[OpenLayers-Trac] [OpenLayers] #3585: Click to add feature (circle) -> center is not quite where clicked

OpenLayers trac-20090302 at openlayers.org
Mon Nov 28 04:58:04 EST 2011


#3585: Click to add feature (circle) -> center is not quite where clicked
---------------------------+------------------------------------------------
 Reporter:  DottedAlex     |       Owner:  tschaub     
     Type:  bug            |      Status:  new         
 Priority:  trivial        |   Milestone:  2.12 Release
Component:  Handler.Point  |     Version:  2.11        
 Keywords:                 |       State:              
---------------------------+------------------------------------------------
 FYI: I've filed this under Handler.Point but it applies to all the other
 feature handlers too.

 Using OpenLayers.Control.DrawFeature with OpenLayers.Handler.Point and
 circle as symbolizer the circle is never quite drawn where clicked (It's
 out by one pixel).

 I've followed this through the code and it seems the renderers use the top
 left of the clicked pixel as center so circles always appear 'off center'.

 Solution is farily simple: Alter createFeature in OpenLayers.Handler.Point
 so that 0.5 is added to the clicked location which causes the middle of
 the pixel to be used instead:

 createFeature: function(pixel) {
         pixel = pixel.add(0.5,0.5);
         var lonlat = this.map.getLonLatFromPixel(pixel);
         this.point = new OpenLayers.Feature.Vector(
             new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
         );

-- 
Ticket URL: <http://trac.openlayers.org/ticket/3585>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list