[OpenLayers-Users] Buffering and resizing a point

Mehmet Sirin m.sirin07 at googlemail.com
Thu Dec 17 04:34:03 EST 2009


hi,

since there isn't a buffer function integrated in openlayers i have to find
other ways to simulate buffering a point and displaying it:


 function pointBuffer(lat, lon, radius,color){
           polygonLayer.removeFeatures(polygonLayer.features);
                var style = {
                    fillColor: '#ff0000',
                    strokeWidth: 1,
                    pointRadius: radius,  // in pixels

                };



                var point = new OpenLayers.Geometry.Point(lat, lon);
                var feature = new OpenLayers.Feature.Vector(point,null,
style);

                polygonLayer.addFeatures([feature]);
                polygonLayer.setOpacity(0.5);


            }


---------------------------------------------------------------------------------------------------------------

...
                                 var lonlat1=new
OpenLayers.LonLat(parseInt(radius),0);
                                 var lonlat2=new
OpenLayers.LonLat(parseInt(radius*2),0);
                                 var
pixel1=map.getLayerPxFromLonLat(lonlat1);
                                 var
pixel2=map.getLayerPxFromLonLat(lonlat2);


                                 var dist=
Math.abs(parseInt(pixel2.x)-parseInt(pixel1.x));


                                 createCircle(x,y,dist);


--------------------------------------------------------------------------------------------------------------

It works fine, but now the problem:
When zooming in or out the point feature won't resize -that means it does
not changes. the pixel size/radius is the same in every zoom level.

for solving this, i thought of creating a linearring and then a polygon, of
which i know that will automatically resize with zooming.

i tried:
var linearRing = new OpenLayers.Geometry.LinearRing(point); //just one point
var polygonFeature = new OpenLayers.Feature.Vector(
 new OpenLayers.Geometry.Polygon([linearRing]),null, style);

but seems not to work..



anybody can help?


regards
m.sirin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091217/05ed8f5d/attachment.html


More information about the Users mailing list