[OpenLayers-Users] External Graphic of features positioning

ilias kanellos ilias.kanellos at gmail.com
Thu Aug 19 05:02:39 EDT 2010


Dear List,

I am trying to create markers as point features of a vector layer. I do this
by using the following code:

                            var markerStyle = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default','select']);
                            markerStyle.graphicWidth = 21;
                            markerStyle.graphicHeight = 25;
                            markerStyle.graphicOpacity = 1;
                            markerStyle.externalGraphic = ""; // I put the
url of the image here
                            markerStyle.graphicTitle = displayName; //
displayName is a string previously defined
                            var markerCoordPoint = new
OpenLayers.Geometry.Point(markerCoords.lon,markerCoords.lat); //
markerCoords is a LonLat object
                            var newMarker =  new
OpenLayers.Feature.Vector(markerCoordPoint,null,markerStyle);

When I add the above feature to a vector layer and put in on my map it
displays the image I want in the correct coordinates,
however the center of the image is put to the Lon/Lat coordinates I specify
for the newMarker variable.
What I would like to do is to set a specific point (such as the center of
the bottom, or the bottom left corner) of the image to be put on the
determined coordinates.
I tried to add the following to the markerStyle object:

                            markerStyle.graphicXOffset =
-(markerStyle.graphicWidth/2);
                            markerStyle.graphicYOffset =
-markerStyle.graphicHeight;

However if I understood this correctly, the above offset concerns pixels,
and the result is that the marker image gets placed in a completely wrong
position,
especially in low zoom levels. Is there some way to 'anchor' the
externalGraphic the way I want to?
Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100819/24adb1e8/attachment.html


More information about the Users mailing list