[OpenLayers-Users] Node has no parent exception when trying to
draw Polygon
Christopher Schmidt
crschmidt at metacarta.com
Thu Jan 17 13:30:33 EST 2008
On Thu, Jan 17, 2008 at 10:25:09AM -0800, samd wrote:
>
> Hi, I originally had thought this but looking at the drawFeature function of
> OpenLayers.Control.DrawFeature on wiki it creates it.
Um. I don't know what you're trying to do, but using the drawFeature
control to add features to your layer is not the right solution.
> var polygonAreaPoints = incidents[i].areaPoints;
> var pointArray = new Array();
>
> for ( var j = 0; j < polygonAreaPoints.length; j++ )
> {
> var x = polygonAreaPoints[j].x;
> var y = polygonAreaPoints[j].y;
>
> pointArray.push( new OpenLayers.Geometry.Point( x, y ) );
> }
>
> // Create the linear ring
> var ring = new OpenLayers.Geometry.LinearRing( pointArray );
>
> // Create the polygon
> var feature = new OpenLayers.Geometry.Polygon( ring );
-> now do this:
var f = new OpenLayers.Feature.Vector(feature);
layer.addFeatures(f);
where layer is a Layer.Vector which has been added to your map.
Regards,
--
Christopher Schmidt
MetaCarta
More information about the Users
mailing list