为什么我不能运行这种方法(openlayers)(ol.layer.Vector)




var vectorSource = new ol.source.Vector({
features: features
});

var vectorLayer = new ol.layer.Vector({
source: vectorSource,

style: function (feature) {
feature.setStyle(typeitems(feature));
console.log("apple");
}
});

这是我的代码。 为什么不能运行此行控制台.log("苹果"(;in ol.layer.Vector ?

style属性将ol.Style | ol.Style[] | ol.StyleFunction应用于所有没有自己样式的功能。

如果您发布完整的示例,我们可能会更好地帮助您。但是,我将假设样式函数签名类似于function typeitems(feature: ol.Feature): ol.Style.在这种情况下,您可以像这样重写代码:

var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: function (feature) {
return typeitems(feature);
}
});
[...]
function typeitems(feature: ol.Feature): ol.Style {
return new ol.Style({
stroke: new ol.Style.Stroke({ color: 'red', width: 5})
});
}

在这里,typeitems()有点毫无意义,因为它总是会创建相同的红色笔划样式,但你明白我的观点,你可以解决你的问题。如果您需要更具体的帮助,请发布比这种最小变量声明更多相关的代码。

祝你好运!

最新更新