gpt4 book ai didi

javascript - 无法以编程方式向图层添加要素

转载 作者:行者123 更新时间:2023-11-30 12:05:15 25 4
gpt4 key购买 nike

我的 map 附加了一个点击事件。在这个点击事件中,我触发了一个应该向 map 添加功能的功能,但现在什么也没有发生。我这样试过:

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
}

最佳答案

It is a OL3 bug

没那么快。

函数的第一个参数应该是 click 事件。另一个错误:ol.Feature 中没有 style 参数构造函数。

创建后设置要素样式。所以:

featurething.setStyle(some_style_or_a_function);

关于javascript - 无法以编程方式向图层添加要素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35429093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com