[OpenLayers-Users] draw Polygon from script
Frédéric Junod
frederic.junod at camptocamp.com
Tue Sep 11 08:59:49 EDT 2007
Le Tue, 11 Sep 2007 14:55:37 +0200,
Kevin Kempfer <mail at kevinkempfer.de> a écrit :
> What I am doing so far is this:
>
> var p1 = new OpenLayers.Geometry.Point(8.4,41.3)
> var p2 = new OpenLayers.Geometry.Point(8.4,42.3)
> var p3 = new OpenLayers.Geometry.Point(9.4,42.3)
> var p4 = new OpenLayers.Geometry.Point(9.4,41.3)
>
> var poly = new OpenLayers.Geometry.LinearRing(new Array(p1,p2,p3,p4));
> var control = drawControls['polygon'];
> control.drawFeature(poly);
>
> Is this the correct way of adding a polygon to the map?
To add points to the map you need to:
1. create a OpenLayers.Layer.Vector and add it to the map
2. create OpenLayers.Geometry.Point and OpenLayers.Feature.Vector
3. bind Geometry and Vector Feature
4. add Vector Feature to the Vector Layer
very basic js code:
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Vector('my points');
map.addLayer(layer);
var features = [];
for (var i=0, i < myPointsFromAjax.length; i++) {
var geom = new OpenLayers.Geometry.Point(myPointsFromAjax[i].x,
myPointsFromAjax[i].y);
features.push(new OpenLayers.Feature.Vector(geom));
}
layer.addFeatures(features);
or something like that ...
Now you need to digg into http://www.openlayers.org/dev/examples/ and look at
the source code, especially resize-features.html
Hope that helps,
fredj
>
> Thanks,
>
> Kevin.
>
>
> Kevin Kempfer schrieb:
> > Hi,
> >
> > I receive some points from a database via AJAX and would like to add
> > them to the map as new polygon. Where should my script jump in? Call the
> > DrawFeature-Handler? Can someone please give me a direction on where to
> > start?
> >
> > Thanks,
> >
> > Kevin.
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
>
--
Frédéric Junod
Camptocamp SA
More information about the Users
mailing list