问题
I have two queries regarding Polygon in Open Layers.
1)How can we place some array of points on the OS map?
2)Suppose we want to draw a polygon. How could we know whether the points are inside of the polygon or not. In short if we draw a polygon, we fetch the boundaries: How can we identify whether the points are inside the polygon or not?
Any help would be appreciated as I am a beginner.
回答1:
Welcome to the OpenLayers community!
1) See this example to learn how to add point(s) to a map: http://openlayers.org/en/v3.8.2/examples/icon.html. I strongly suggest you also read the "concepts" tutorial: http://openlayers.org/en/v3.8.2/doc/tutorials/concepts.html
2) A polygon object has the intersectsExtent
method, which can be used to see if an extent intersects with an extent. After you have drawn the polygon, you could loop in the array of points and collect each one which extent intersects with the polygon. See the documentation: http://openlayers.org/en/v3.8.2/doc/tutorials/concepts.html
I would separate the points and polygons into 2 layers to keep them separate and more easily loop in the point features.
来源:https://stackoverflow.com/questions/32375716/geofencing-feature-place-map-points-polygon-identify-point-within-polygon