[OpenLayers-Users] All marker offsets are wrong when using features

Christopher Schmidt crschmidt at metacarta.com
Sun Jan 11 19:50:56 EST 2009


On Sun, Jan 11, 2009 at 04:10:59PM -0800, Deluded wrote:
> 
> Hi everyone.
> 
> I've just been improving a site of mine that used to use the text layer to
> overlay tracking points on a OSM map.
> I've updated it to use the following function:
> 
> <code>
>         function addTripMarker(ll, popupContentHTML, img) 
> 	{
>             var feature = new OpenLayers.Feature(markers, ll); 
>             feature.closeBox = true;
>             feature.popupClass =
> OpenLayers.Class(OpenLayers.Popup.FramedCloud, {'autoSize': true});
>             feature.data.popupContentHTML = popupContentHTML;
>             feature.data.overflow = "auto";
>                     
>             var marker = feature.createMarker();
> 
>             var markerClick = function (evt) {
>                 if (this.popup == null) {
>                     this.popup = this.createPopup(true);
>                     map.addPopup(this.popup);
>                     this.popup.show();
>                 } else {
>                     this.popup.toggle();
>                 }
>                 currentPopup = this.popup;
>                 OpenLayers.Event.stop(evt);
>             };
>             marker.events.register("mousedown", feature, markerClick);
> 	    marker.icon.url = img;
> 	    marker.icon.size = new OpenLayers.Size(32,32);
>             marker.icon.offset = new OpenLayers.Pixel(-160, -160);
>             markers.addMarker(marker);
>         }
> </code>
> 
> All the icons are drawn correctly, but without any offset. You can see I've
> put a silly 160,160 offset in to test this and it made no difference.

You an't change the offset like this. (Or if you can, I don't know how.)

Instead of using feature.createMarker, just create your icon and marker
manually. 

-- Chris

> Anyone got any ideas what I'm doing wrong?? I could go back to using the
> text layer, but I never figured out how to change the popup styles on that.
> 
> Thanks in advance :)
> -- 
> View this message in context: http://n2.nabble.com/All-marker-offsets-are-wrong-when-using-features-tp2143419p2143419.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list