Openlayers 判断图形包含点


//假设获取的图形对象名为f
 var componets = f.geometry.components[0].components;
 var changedComponents = _.map(componets, function(c) {
       return new OpenLayers.Geometry.Point(c.x, c.y);
 });
f.geometry.components[0].components = changedComponents;
var tuxingObj = f.geometry.components[0];
// 1. 获取图层
var layer = map.getLayersByName(layerName);
//2. 遍历比较图形包含点
_.each(layer.features, function(feature) {
    if (tuxingObj.containsPoint(feature.geometry)) {
        console.log(feature);
    }
});

转载自:https://blog.csdn.net/yaksok/article/details/54669871

You may also like...