Hi, you have to calculate your offset for every zoomlevel. I do it by use of a styleMap with context. The code below should give you an idea, how to get it work. function layerContext() { theXOffset = 10; theYOffset = 10; theResolution = map.getResolution(); var context = { getXO : function(){ return theXOffset * theResolution / map.getResolution(); }, getYO : function(){ return theYOffset * theResolution / map.getResolution(); } }; var template = { ... graphicXOffset : "${getXO}", graphicYOffset : "${getYO}", ... pointRadius : 0 }; yourLayer.styleMap = new OpenLayers.StyleMap(new OpenLayers.Style(template, {context:context}) ); }
I use this approach to display georeferenced images as externalGraphic. http://gis.ibbeck.de/ginfo/apps/OLExamples/OL27/examples/ExternalGraphicOver lay/ExternalGraphicOverlay.asp Arnd _____ Von: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org] Im Auftrag von ilias kanellos Gesendet: Donnerstag, 19. August 2010 11:03 An: Users@openlayers.org Betreff: [OpenLayers-Users] External Graphic of features positioning 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
_______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users