[OpenLayers-Users] Selecting polygon error.

Eric Lemoine eric.c2c at gmail.com
Fri Jan 18 12:12:49 EST 2008


On Jan 18, 2008 9:50 AM, Pierre GIRAUD <bluecarto at gmail.com> wrote:
> Sorry, I have no clue.
>
> I tested the following code (adapted from yours) in the
> select-feature.html example [1] and it worked great :

That it exactly why I suggested to try with the onSelect and
onUnselect callbacks removed. I'm suspecting that there's something
that causes the issue in the callbacks.


> 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



More information about the Users mailing list