openlayers3.X 与4.X画圈和画多边形api区别
2021-02-11 20:17
在 3.X版本中,对于画圈,画多边形不能更好的筛选包含的点,而4.X版本中则只需调用 geom.intersectsCoordinate([lng,lat] 已经完美实现。完整代码如下:
drawselect:function(){
draw.clear();
draw.griddrawLayer = new ol.layer.Vector({
source : draw.griddrawSource,
style : draw.griddrawstyle,
zIndex : 900
});
map.addLayer(draw.griddrawLayer);
draw = new ol.interaction.Draw({
source: draw.griddrawSource,
type: ‘Circle‘
});
map.addInteraction(draw);
draw.on("drawstart", function(evt){
sketch= evt.feature;
}, this);
draw.on("drawend", function(evt) {
map.removeInteraction(draw);
var geom= evt.feature.getGeometry();
vectorSource.forEachFeature(function(_feature){
var layername = _feature.get("layername");
if (layername == "videolayer") {
var lng = _feature.get("lng");
var lat = _feature.get("lat");
if(geom.intersectsCoordinate([lng,lat]) == true){
var name = _feature.get("name");
var code = _feature.get("code");
list.push({"code":code,"name":name});
}
}
});
}, this);
},
文章标题:openlayers3.X 与4.X画圈和画多边形api区别
文章链接:http://soscw.com/index.php/essay/54159.html