Closed ghost closed 5 years ago
不能触发style Function方法
ol.layer.Test = function (opt_options) { var options = opt_options ? opt_options : {}; options.source = new ol.source.Vector({features: opt_options.features});
ol.layer.Vector.call(this, options); this.setStyle(function (fea, resolution) { var style; return style; }.bind(this)); // this.getSource().addFeatures(options.features); delete opt_options.features;
}
ol.inherits(ol.layer.Test, ol.layer.Vector); /// 其他方法……
调用后触发this.setStyle中的匿名函数。但是在这个版本中没有触发,原生ol-v4.6.5版本可以触发。
var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.Tianditu({}) }), new ol.layer.Test({ features: [new ol.Feature({ geometry: new ol.geom.Point([102.79071213226318, 25.00734961509705]) id: '234' })] }) ], view: new ol.View({ projection: 'EPSG:4326', center: [102.79071213226318, 25.00734961509705],//[102.7043, 24.9796], zoom: 17, }), projection: 'EPSG:4326', });
谢谢您提的缺陷。 我把您的代码复制在线调试,是可以正常运行的。效果见下图
请再检查下代码呢。如果还是有问题,可以提供一个完成的重现demo吗?
我这边也尝试了一下,没问题,可能是我要素集合有问题。
缺陷
描述
Version 911
Actual Behavior [当前现象]
ol.layer.Test = function (opt_options) { var options = opt_options ? opt_options : {}; options.source = new ol.source.Vector({features: opt_options.features});
}
ol.inherits(ol.layer.Test, ol.layer.Vector); /// 其他方法……
Expected Behavior [期望现象]
调用后触发this.setStyle中的匿名函数。但是在这个版本中没有触发,原生ol-v4.6.5版本可以触发。
Example of reproducing the issue [重现现象的例子]
var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.Tianditu({}) }), new ol.layer.Test({ features: [new ol.Feature({ geometry: new ol.geom.Point([102.79071213226318, 25.00734961509705]) id: '234' })] }) ], view: new ol.View({ projection: 'EPSG:4326', center: [102.79071213226318, 25.00734961509705],//[102.7043, 24.9796], zoom: 17, }), projection: 'EPSG:4326', });