我是 Open Layers 库和 JavaScript 的新手。所以我想知道为什么我不能通过 opt_geometryOrProperties
constructor 指定 Feature 对象的 id
或 style
属性的值争论。毕竟它适用于 geometry
属性:
var g = new ol.geom.Point([0, 0]);
var feature = new ol.Feature({geometry: g});
feature.getGeometry() === g; // true
但是如果我尝试使用 id
或 style
,它确实不工作:
var g = new ol.geom.Point([0, 0]);
var id = 1;
var style = new ol.style.Style;
var feature = new ol.Feature({
geometry: new ol.geom.Point([0, 0]),
id: id,
style: style
});
feature.getId() === id; // false
feature.getStyle() === style; // false
如何判断哪些属性可通过构造函数设置,哪些属性不可设置?
最佳答案
要回答你的第一个问题,你不能在构造函数中设置样式,而且他们似乎不太可能去 to add it to the constructor .关于在哪里可以找到可以在构造函数中设置哪些属性,请参阅 API documentation .
可能有用的是在矢量图层的图层中设置样式。
关于javascript - 如何从构造函数初始化 ol.Feature 对象的 id 或 style 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28309194/