You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martijn Vos <m....@hippo.nl> on 2008/03/27 22:39:09 UTC

How to link ImageMap to an image?

I'm trying to use ImageMap. I've got a dynamically generated
image, using RenderedDynamicImageResource to generate the image
from a list of objects, each of which has its own coordinates
(which works fine).

Now I want an imagemap so that I can actually click on those
objects. I thought this wouldn't be too hard, considering I've
got that list of objects with their coordinates, and Wicket
contains a convenient ImageLink class which has convenient
addCircleLink() and addPolygonLink() methods.

When I use it, however, I get this error message:

WicketMessage: Component imageMap must be applied to a tag of type 
'img', not '<map wicket:id="imageMap" name="foo" id="foo">' (line 0, 
column 0)
[markup = 
file:/C:/eclipse-workspace/Spacegame3/web/WEB-INF/classes/mcv/wicket/spacegame/UniverseMapPanel.html, 
index = 4, current = '<map wicket:id="imageMap" name="foo" id="foo">' 
(line 6, column 5)]

But when I create the ImageMap with the image's wicket:id instead
of its own, I get this error:

java.lang.IllegalArgumentException: A child with id 'universeMap' 
already exists:

So should I remove the wicket Image? That makes no sense, because
then how would the <img> know what image to show?

So basically, I'm stumped as to how to use ImageMap. Any ideas?


mcv.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Matthew Young wrote:
>> ...ImageMap is supposed to work on a static <img>
>> tag with a hard-coded src atrribute.
> 
> But you can modify the src tag like below.  Would that help?
> 
>         WebMarkupContainer img = new ImageMap("image") {
>             private static final long serialVersionUID = 1L;
>             @Override protected void onComponentTag(final ComponentTag tag){
>                 super.onComponentTag(tag);
>                 tag.put("src", YOUR_VERY_OWN_URL);
>             }
>         };

Not a lot. I want to treat my image in the same way as any other
Wicket Image, and in my particular case, that means linking it to
an RenderedDynamicImageResource.

The problem is that the ImageMap needs to be applied to an img tag,
which means I can't apply an Image to that tag anymore, but ImageMap
doesn't provide anywhere near the functionality that Image does. It
should. I see this as a serious bug in ImageMap, and not just
some unavoidable limitation that needs to be worked around. The big
question is how to fix this.

I've got a couple of options:

1: Since ImageMap is applied to an img tag, ImageMap needs to implement
the same functionality as Image. The best way to do that by simply
making it inherit, but that's a problem since ImageMap already extends
WebMarkupContainer. No idea what WebMarkupContainer does, but there's
probably a very good reason for it. Also, there seems to be a big
difference in the way Image and ImageMap are rendered. ImageMap uses
onRender(), whereas Image uses onComponentTag(). I don't know enough
about the inner workings of Wicket to know what that means.

2: Since an ImageMap is something completely different from an Image,
it should not apply to an img tag, but to a map tag, and Image needs to
have a method to link it to an ImageMap. Accept that the current
ImageMap was based on a bad idea, and fix it properly.

I think the second is better and cleaner, and I have a better idea of
how to do it. The problem is that it requires some big changes: Image
needs an extra method, compatibility with the old ImageMap will break,
and you need to add a <map> tag to your markup.

I'm not completely happy with the need to add a <map> tag, and would
like to be able to simply add an ImageMap to an Image and have that
work, but considering the difference between onRender() and
onComponentTag(), I'm not sure that's possible. On the other hand,
web designers will probably like having an actual imagemap in their
markup.

Should I be posting this to the dev list perhaps?


mcv.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Matthew Young wrote:
>> ...ImageMap is supposed to work on a static <img>
>> tag with a hard-coded src atrribute.
> 
> But you can modify the src tag like below.  Would that help?
> 
>         WebMarkupContainer img = new ImageMap("image") {
>             private static final long serialVersionUID = 1L;
>             @Override protected void onComponentTag(final ComponentTag tag){
>                 super.onComponentTag(tag);
>                 tag.put("src", YOUR_VERY_OWN_URL);
>             }
>         };

Not a lot. I want to treat my image in the same way as any other
Wicket Image, and in my particular case, that means linking it to
an RenderedDynamicImageResource.

The problem is that the ImageMap needs to be applied to an img tag,
which means I can't apply an Image to that tag anymore, but ImageMap
doesn't provide anywhere near the functionality that Image does. It
should. I see this as a serious bug in ImageMap, and not just
some unavoidable limitation that needs to be worked around. The big
question is how to fix this.

I've got a couple of options:

1: Since ImageMap is applied to an img tag, ImageMap needs to implement
the same functionality as Image. The best way to do that by simply
making it inherit, but that's a problem since ImageMap already extends
WebMarkupContainer. No idea what WebMarkupContainer does, but there's
probably a very good reason for it. Also, there seems to be a big
difference in the way Image and ImageMap are rendered. ImageMap uses
onRender(), whereas Image uses onComponentTag(). I don't know enough
about the inner workings of Wicket to know what that means.

2: Since an ImageMap is something completely different from an Image,
it should not apply to an img tag, but to a map tag, and Image needs to
have a method to link it to an ImageMap. Accept that the current
ImageMap was based on a bad idea, and fix it properly.

I think the second is better and cleaner, and I have a better idea of
how to do it. The problem is that it requires some big changes: Image
needs an extra method, compatibility with the old ImageMap will break,
and you need to add a <map> tag to your markup.

I'm not completely happy with the need to add a <map> tag, and would
like to be able to simply add an ImageMap to an Image and have that
work, but considering the difference between onRender() and
onComponentTag(), I'm not sure that's possible. On the other hand,
web designers will probably like having an actual imagemap in their
markup.

Should I be posting this to the dev list perhaps?


mcv.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Martijn Vos wrote:
[snip]
> Should I be posting this to the dev list perhaps? I have already created
> a Jira issue for this.

My apologies for posting the same message four time last friday.
Problems with my employer's mailserver.

Anyway, I fixed the problem by writing a new ImageMap, and I
started a new thread about this on the dev list called
"WICKET-1456: rewrite existing ImageMap or create a new one?"


mcv.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Matthew Young wrote:
>> ...ImageMap is supposed to work on a static <img>
>> tag with a hard-coded src atrribute.
> 
> But you can modify the src tag like below.  Would that help?
> 
>         WebMarkupContainer img = new ImageMap("image") {
>             private static final long serialVersionUID = 1L;
>             @Override protected void onComponentTag(final ComponentTag tag){
>                 super.onComponentTag(tag);
>                 tag.put("src", YOUR_VERY_OWN_URL);
>             }
>         };

Not a lot. I want to treat my image in the same way as any other
Wicket Image, and in my particular case, that means linking it to
an RenderedDynamicImageResource.

The problem is that the ImageMap needs to be applied to an img tag,
which means I can't apply an Image to that tag anymore, but ImageMap
doesn't provide anywhere near the functionality that Image does. It
should. I see this as a serious bug in ImageMap, and not just
some unavoidable limitation that needs to be worked around. The big
question is how to fix this.

I've got a couple of options:

1: Since ImageMap is applied to an img tag, ImageMap needs to implement
the same functionality as Image. The best way to do that by simply
making it inherit, but that's a problem since ImageMap already extends
WebMarkupContainer. No idea what WebMarkupContainer does, but there's
probably a very good reason for it. Also, there seems to be a big
difference in the way Image and ImageMap are rendered. ImageMap uses
onRender(), whereas Image uses onComponentTag(). I don't know enough
about the inner workings of Wicket to know what that means.

2: Since an ImageMap is something completely different from an Image,
it should not apply to an img tag, but to a map tag, and Image needs to
have a method to link it to an ImageMap. Accept that the current
ImageMap was based on a bad idea, and fix it properly.

I think the second is better and cleaner, and I have a better idea of
how to do it. The problem is that it requires some big changes: Image
needs an extra method, compatibility with the old ImageMap will break,
and you need to add a <map> tag to your markup.

I'm not completely happy with the need to add a <map> tag, and would
like to be able to simply add an ImageMap to an Image and have that
work, but considering the difference between onRender() and
onComponentTag(), I'm not sure that's possible. On the other hand,
web designers will probably like having an actual imagemap in their
markup.

I'm currently working on option 2, and it's looking like a pretty
extensive rewrite.

Should I be posting this to the dev list perhaps? I have already created
a Jira issue for this.


mcv.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Matthew Young wrote:
>> ...ImageMap is supposed to work on a static <img>
>> tag with a hard-coded src atrribute.
> 
> But you can modify the src tag like below.  Would that help?
> 
>         WebMarkupContainer img = new ImageMap("image") {
>             private static final long serialVersionUID = 1L;
>             @Override protected void onComponentTag(final ComponentTag tag){
>                 super.onComponentTag(tag);
>                 tag.put("src", YOUR_VERY_OWN_URL);
>             }
>         };

Not a lot. I want to treat my image in the same way as any other
Wicket Image, and in my particular case, that means linking it to
an RenderedDynamicImageResource.

The problem is that the ImageMap needs to be applied to an img tag,
which means I can't apply an Image to that tag anymore, but ImageMap
doesn't provide anywhere near the functionality that Image does. It
should. I see this as a serious bug in ImageMap, and not just
some unavoidable limitation that needs to be worked around. The big
question is how to fix this.

I've got a couple of options:

1: Since ImageMap is applied to an img tag, ImageMap needs to implement
the same functionality as Image. The best way to do that by simply
making it inherit, but that's a problem since ImageMap already extends
WebMarkupContainer. No idea what WebMarkupContainer does, but there's
probably a very good reason for it. Also, there seems to be a big
difference in the way Image and ImageMap are rendered. ImageMap uses
onRender(), whereas Image uses onComponentTag(). I don't know enough
about the inner workings of Wicket to know what that means.

2: Since an ImageMap is something completely different from an Image,
it should not apply to an img tag, but to a map tag, and Image needs to
have a method to link it to an ImageMap. Accept that the current
ImageMap was based on a bad idea, and fix it properly.

I think the second is better and cleaner, and I have a better idea of
how to do it. The problem is that it requires some big changes: Image
needs an extra method, compatibility with the old ImageMap will break,
and you need to add a <map> tag to your markup.

I'm not completely happy with the need to add a <map> tag, and would
like to be able to simply add an ImageMap to an Image and have that
work, but considering the difference between onRender() and
onComponentTag(), I'm not sure that's possible. On the other hand,
web designers will probably like having an actual imagemap in their
markup.

Should I be posting this to the dev list perhaps?


mcv.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to link ImageMap to an image?

Posted by Matthew Young <gi...@gmail.com>.
>...ImageMap is supposed to work on a static <img>
>tag with a hard-coded src atrribute.

But you can modify the src tag like below.  Would that help?

        WebMarkupContainer img = new ImageMap("image") {
            private static final long serialVersionUID = 1L;
            @Override protected void onComponentTag(final ComponentTag tag){
                super.onComponentTag(tag);
                tag.put("src", YOUR_VERY_OWN_URL);
            }
        };


On Thu, Mar 27, 2008 at 3:05 PM, Martijn Vos <m....@hippo.nl> wrote:

> Martijn Vos wrote:
> > I'm trying to use ImageMap. I've got a dynamically generated
> > image, using RenderedDynamicImageResource to generate the image
> > from a list of objects, each of which has its own coordinates
> > (which works fine).
> >
> > Now I want an imagemap so that I can actually click on those
> > objects. I thought this wouldn't be too hard, considering I've
> > got that list of objects with their coordinates, and Wicket
> > contains a convenient ImageLink class which has convenient
> > addCircleLink() and addPolygonLink() methods.
> ...
> > So basically, I'm stumped as to how to use ImageMap. Any ideas?
>
> After a bit more fiddling and looking at the source, I get the
> impression that ImageMap is supposed to work on a static <img>
> tag with a hard-coded src atrribute. So basically it's an
> extremely basic class in dire need of some extension. I figured
> I'd make my own DynamicImageMap, which would extend ImageMap and
> make for a nice first contribution to Wicket. Unfortunately,
> ImageMap is final, so I can't extend it! Why is an extremely
> basic, feature-poor class final? Doesn't that make ImageMap a
> bit of a dead end?
>
>
> mcv.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to link ImageMap to an image?

Posted by Martijn Vos <m....@hippo.nl>.
Martijn Vos wrote:
> I'm trying to use ImageMap. I've got a dynamically generated
> image, using RenderedDynamicImageResource to generate the image
> from a list of objects, each of which has its own coordinates
> (which works fine).
> 
> Now I want an imagemap so that I can actually click on those
> objects. I thought this wouldn't be too hard, considering I've
> got that list of objects with their coordinates, and Wicket
> contains a convenient ImageLink class which has convenient
> addCircleLink() and addPolygonLink() methods.
...
> So basically, I'm stumped as to how to use ImageMap. Any ideas?

After a bit more fiddling and looking at the source, I get the
impression that ImageMap is supposed to work on a static <img>
tag with a hard-coded src atrribute. So basically it's an
extremely basic class in dire need of some extension. I figured
I'd make my own DynamicImageMap, which would extend ImageMap and
make for a nice first contribution to Wicket. Unfortunately,
ImageMap is final, so I can't extend it! Why is an extremely
basic, feature-poor class final? Doesn't that make ImageMap a
bit of a dead end?


mcv.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org