我正在尝试点击地图上的功能信息点击openlayers3。我在控制台中收到类似TypeError的错误消息:layer.getSource(...)为null 我的点击功能是
map.on('click', function (evt) {
var fl = map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
return { 'feature': feature, 'layer': layer };
});
var feature = fl.feature;
layer = fl.layer;
if (layer == vectorlayer) {
var admin = "<table>";
admin += "<tr><td style='color:green; border: 0px solid red;text-align:left;vertical-align:middle;font-size:15px;'><b> Information<b></td></tr>";
admin += "<tr><td><b>Type</b></td><td>:</td><td >" + feature.get('field1') + "</td></tr>";
admin += "<tr><td><b>District</b></td><td>:</td><td>" + feature.get('district') + "</td></tr>";
admin += "<tr><td><b>Taluk</b></td><td>:</td><td >" + feature.get('taluk') + "</td></tr>";
admin += "<tr><td><b>Village</b></td><td>:</td><td>" + feature.get('village') + "</td></tr>";
admin += "<tr><td><b>code</b></td><td>:</td><td>" + feature.get('field2') + "</td></tr>";
$("#Identifier").html(schooladmin);
$("#Identifier").dialog('open');
schooladmin += "</table>";
}
});
答案 0 :(得分:0)
这不是点击功能,它是指针移动功能,如果你想使用点击互动,你必须将catched事件更改为singleClick,如下所示:
map.on('singleclick', function(evt){
//...
});