[OpenLayers-Users] Bug with custom markers?

Christopher Schmidt crschmidt at metacarta.com
Fri Jan 25 07:40:15 EST 2008


On Fri, Jan 25, 2008 at 03:07:48AM -0800, Cranio wrote:
> 
> Hi all.
> 
> I've created a map with some markers on it. By clicking on the marker, a
> popup is shown with some ajax-retrieved data. And all goes fine.
> 
> Strange thing though: if i don't specify any custom icon and go with the
> default one, all is fine. When I try to insert a custom PNG as icon,
> suddenly the marker doesn't fire any click event.
> 
> Is it a bug or what?
> 
> ------------------------------
> 
> For further info, here's the JS function that creates the icon and the one
> for the marker:
> 
> [...]
> 
> var size = new OpenLayers.Size(26,26);
> var offset = new OpenLayers.Pixel(-(size.w/2),-(size.h/2));
> var icon = new OpenLayers.Icon('/path-to-icons/1.png',size,offset);
> aM(icon,lon,lat,0);
> 
> [...]
> 
> function aM(icon,lon,lat,id)
> {
>     var ll = gmap.forwardMercator(lon,lat);
>     feature = new OpenLayers.Feature(gmap,ll);
>     var marker = feature.createMarker();
>     marker.icon=icon; // <--- I HAD TO DO THIS WAY CUZ I USED
> feature.createMarker ... MAYBE I SHOULDN'T?

Correct, you shouldn't. Instead, the third property of your Feature()
object should be a 'data' hash with an icon variable:
  Feature(gmap, ll, {icon:new OpenLayers.Icon()})

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list