[OpenLayers-Users] Selecting polygon error.

Pierre GIRAUD bluecarto at gmail.com
Fri Jan 18 03:50:04 EST 2008


Sorry, I have no clue.

I tested the following code (adapted from yours) in the
select-feature.html example [1] and it worked great :

var polygonAreaPoints = [
    new OpenLayers.Geometry.Point(0, 0),
    new OpenLayers.Geometry.Point(10, 0),
    new OpenLayers.Geometry.Point(10, 10),
    new OpenLayers.Geometry.Point(0, 10)
];
var pointArray = [];
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 );

var f = new OpenLayers.Feature.Vector(feature);
map.layers[1].addFeatures( f );

var polySelected = function() {
    console.log("selected");
}
var polyUnselected = function() {
    console.log("unselected");
}

selectControl = new OpenLayers.Control.SelectFeature(map.layers[1],
    {hover: true,
    onSelect: polySelected,
    onUnselect: polyUnselected});
map.addControl( selectControl );
selectControl.activate();


[1] http://openlayers.org/dev/examples/select-feature.html

On Jan 18, 2008 4:56 AM, samd <sdoyle_2 at yahoo.com> wrote:
>
> Hi I was discussing this in a previous message but created a new one since it
> is a different topic.
>
> When I am using a select control on a polygonLayer such as the following:
>
> selectControl = new OpenLayers.Control.SelectFeature(polygonLayer,
>                                                             {hover: true,
>                                                             onSelect:
> polySelected,
>                                                             onUnselect:
> polyUnselected})
> map.addControl( selectControl );
> selectControl.activate();
>
> And I regenerate a polygon from points retrieved from the server such as the
> following:
>
>  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 );
>
>          var f = new OpenLayers.Feature.Vector(feature);
>          polygonLayer.addFeatures( f );
>
> The SelectFeature generates the following error on hover:
>
> node.parentNode has no properties
>
> Tracing in Firebug the error occurs here in the OpenLayers.Renderer.Elements
> class
>
> nodeFactory: function(id, type) {
>         var node = OpenLayers.Util.getElement(id);
>         if (node) {
>             if (!this.nodeTypeCompare(node, type)) {
>                 node.parentNode.removeChild(node); // ERROR OCCURS HERE
>                 node = this.nodeFactory(id, type);
>             }
>         } else {
>             node = this.createNode(type, id);
>         }
>         return node;
>     },
>
> Now examining the debugger the node attribute is a number such as 103,105
> etc and the type is "path"
>
> The only thing that I can conclude is there is something missing from the
> construction of the polygon or the addition to the layer in some aspect
> since obviously the node just being a numeric value does not have a parent
> attribute.
>
> Once again the values are rendered on the map but the SelectFeature results
> in this odd error.
>
> Anyone have any ideas?
>
> Thanks,
>
> S.D.
>
>
>
> --
> View this message in context: http://www.nabble.com/Selecting-polygon-error.-tp14946220p14946220.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list