SuperMap / iClient-JavaScript

Modern GIS Web Client for JavaScript, based on Leaflet\OpenLayers\MapboxGL-JS\Classic(iClient8C), enhanced with ECharts\D3\MapV etc. Contributed by SuperMap & community.
https://iclient.supermap.io
Apache License 2.0
823 stars 280 forks source link

自定义vector图层,不能正确触发styleFunction #31

Closed ghost closed 5 years ago

ghost commented 5 years ago

缺陷

描述

不能触发style Function方法

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.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); /// 其他方法……

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', });

songyumeng commented 5 years ago

谢谢您提的缺陷。 我把您的代码复制在线调试,是可以正常运行的。效果见下图 image

请再检查下代码呢。如果还是有问题,可以提供一个完成的重现demo吗?

ghost commented 5 years ago

我这边也尝试了一下,没问题,可能是我要素集合有问题。