[OpenLayers-Users] Buffering and resizing a point

Andreas Hocevar ahocevar at opengeo.org
Thu Dec 17 05:44:22 EST 2009


Hi,

why so complicated?

Ivan pointed you to the right way to do it. If you look at it, you see a
context with a getType function. In this function, you can return the
desired point radius. If you have your radius in map units, just do the
following:

return radiusInMapUnits / map.getResolution();

Regards,
Andreas.


On 2009-12-17 11:15, Mehmet Sirin wrote:
> hi, there you have the same problem: point-vectors stays as they are
> -without stretching/resizing.
>
> i just find the solution:
>
>           function createCircle(lat, lon, radius){
>            polygonLayer.removeFeatures(polygonLayer.features);
>                 var style = {
>                     fillColor: '#ff0000',
>                     strokeWidth: 1,
>                     pointRadius: radius,  // in map coordinates
>                   
>                 };
>
>
>                var point = new OpenLayers.Geometry.Point(lat, lon);
>                var polygonFeature =
> OpenLayers.Geometry.Polygon.createRegularPolygon(point,radius,30,0);
>                var feature = new
> OpenLayers.Feature.Vector(polygonFeature,null, style);  
>
>   
>                 polygonLayer.addFeatures([feature]);
>                 polygonLayer.setOpacity(0.5);
>
>
>             }
>
> 2009/12/17 Ivan Grcic <igrcic at gmail.com <mailto:igrcic at gmail.com>>
>
>     Hi, cant you make something like this:
>     http://openlayers.org/dev/examples/styles-context.html
>
>     On Thu, Dec 17, 2009 at 10:34 AM, Mehmet Sirin
>     <m.sirin07 at googlemail.com <mailto:m.sirin07 at googlemail.com>> wrote:
>     > 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
>     > _______________________________________________
>     > Users mailing list
>     > Users at openlayers.org <mailto:Users at openlayers.org>
>     > http://openlayers.org/mailman/listinfo/users
>     >
>     >
>
>
>
>     --
>     Ivan Grcic
>
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list