openlayers - 为什么我不能运行这个方法(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");
}
});
这是我的代码。为什么不能运行这一行 console.log("apple"); 在 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()
有点毫无意义,因为它总是会创建相同的红色笔触样式,但你明白我的意思是如何解决你的问题。如果您需要更具体的帮助,请发布比这种最小变量声明更多的相关代码。
祝你好运!
推荐阅读
- reactjs - 为什么我的 iframe 有时会在签署 DocuSign 表单之前首先加载返回 URL 页面?
- c# - 从我的方法中替换 IF 和 Else If 语句
- git - 使用 husky hook 强制推送到另一个远程分支
- c++ - 现代 CMake - 带有 set_property 或 target_compile_features 的 C++ 版本
- file - 电子自定义拖动图标
- haskell - 为什么 ghc (Haskell) 编译器找不到我导入的模块 Data.Vector?我收到错误:找不到模块“Data.Vector”
- excel - VBA | 导出到多页 PDF
- java - 根据元素的第一次出现对列表进行排序
- ffmpeg - 无法播放从 IPC360 相机下载的 .h264 视频
- python - 将保存 numpy 数组的 Python 字典保存到文件中