0
當我在map.on("singleclick", function(event)
後面添加var view
時,我注意到方法getView()
(http://openlayers.org/en/master/apidoc/ol.Map.html#getView)停止工作。任何人都可以給我一個暗示爲什麼會發生這種情況?在我的瀏覽器控制檯我得到以下錯誤:openLayers地圖未定義錯誤
類型錯誤:地圖是不明確的
這裏是我的代碼:
map.on("singleclick", function(event) {
var map = evt.map;
var feature = map.forEachFeatureAtPixel(
event.pixel, function(feature, layer) {
return feature
}
)
var icon_feature = new ol.Feature({
geometry: new ol.geom.Point(event.coordinate),
type: 'icon',
coords: event.coordinate
})
icon_feature.setStyle(icon_style)
icon_layer.getSource().addFeature(icon_feature)
})
var view = map.getView(); //error in this line
//more code here ...