Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I wonder what is the relation between the Geometry.Point one sets for a Feature.Vector and the image provided as externalGraphic for the style, in OpenLayers.

Is the Geometry.Point of a feature for the image:

  1. The centre point of the image,
  2. or the left top most corner of the image.

In case it is 2 then please advice how would I set the values of offsets if, for example, the image is 32x32 (WxH). Is it simply 16 (W/2) for the value of graphicXOffset, and accordingly for the graphicYOffset?

I need to know this information to set the image centre to be the point of a feature. Sadly the documentation doesn't say a word about it, or I am unable to find it.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I figured out, using the code below, that the geometry point of a feature is the centre point of an image set using the externalGraphics. After adding a feature with an image I added another one with a style painting the point as a circle with radius of 5 and the point was painted in the middle of the image.

// World Geodetic System 1984 projection (lon/lat) -- set as the map's display projection
var projWGS84 = new OpenLayers.Projection("EPSG:4326"); 
// Spherical Mercator projection (meters) -- set as the map's projection
var proj900913 = new OpenLayers.Projection("EPSG:900913");
var origin = new OpenLayers.Geometry.Point(lon, lat).transform(projWGS84, map.getProjectionObject());
var style = {
   pointRadius: 5
};
var center = new OpenLayers.Feature.Vector(origin, null, style);
layer.addFeatures([center]);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.