0

I am using Openlayers 2, this is just a mock-up code for testing a layer(POINTS) is inside the other layer(POLYGON).

var p = new OpenLayers.Geometry.Point(13977549.20, 1019860.15);
for (var i = 0; i < layer_floodhazard.features.length; i++) {
    var feature = layer_floodhazard.features[i];
    if (feature.containsPoint(p)) {
        alert('Contains')
    };
}

When I looked at the console is says :Uncaught TypeError: undefined is not a function and it points on the line where containsPoint function is.

1
  • What do you mean by that? layer_floodhazard is a vector layer. Feb 27, 2015 at 5:40

1 Answer 1

0

What happens here is that you feature does not have the containsPoint Method directly.

Assuming your layer_floodhazard.features are polygons, you should see a geometry property under the feature and if the geometry is a polygon, then you should be able to see .containsPoint under the .geometry property.

Maybe you should try

if (feature.geometry.containsPoint(p)) {
  alert('Contains')
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.