我的地图上有一个点击事件。在此点击事件中,我触发了一个应该向地图添加要素的函数,但是现在什么也没有发生。我这样尝试过:
function boo (map, layer){
var source = layer.getSource();
var thing = new ol.geom.Polygon( [[
ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-44,-55], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-88,75], 'EPSG:4326', 'EPSG:3857')
]]);
var featurething = new ol.Feature({
name: "Thing",
geometry: thing,
style: function() {
console.log("Never see this text");
return new ol.style.Style({
fill: new ol.style.Fill({
color: "rgba(192,192,192,1)"
}),
stroke: new ol.style.Stroke({
color: "rgba(192,192,192,1)",
width: 10
})
})
}
});
source.addFeature( featurething );
// see no error messages, but still no feature is added to the map
}
这是一个OL3错误
没那么快。
函数的第一个参数应该是click
事件。另一个错误:构造函数中没有style
参数ol.Feature
。
创建要素样式后,对其进行设置。所以:
featurething.setStyle(some_style_or_a_function);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句