最近,我正在开发一个映射工具,并选择openlayers3作为前端映射APi。在我的地图层,它有几何图形和图像,我想添加一个函数,当我点击不同类型的功能时,它会做不同的动作。
在代码中,我需要识别它来自图像或几何学。我很感谢你们的帮助。
发布于 2015-11-11 15:04:34
你做了个很好的选择。有几种方法可以做到这一点。您可以在该特性中存储一个属性并检查它,例如:
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(ft, layer) { return ft; }
);
// here I'm using feature.get('type') but can be any name
if (feature && feature.get('type') == 'some_value') {
// now you have the clicked feature
}
});请注意,所有功能(ol.Feature)都有一个几何学。
https://stackoverflow.com/questions/33653077
复制相似问题