Openlayers 3层样式问题

Openlayers 3 layer style issue

我需要创建一个带有气象图标的图层 - 大约有 100 个。所以。我这样定义它的来源:

    mappingAPI.meteoIconLayerSource = new ol.source.Vector({});

我将图标添加为这样的功能:

    for(stan in meteo.meteoData)
    {
        var iconFeature = new ol.Feature({
            geometry: new ol.geom.Point(ol.proj.transform([parseFloat(meteo.meteoData[stan].lon), parseFloat(meteo.meteoData[stan].lat)], 'EPSG:4326',   'EPSG:3857')),
            obj_id: meteo.meteoData[stan].obj_id,
        });

        mappingAPI.meteoIconLayerSource.addFeature(iconFeature);  
    }

获得源后,我会像这样创建图层:

    mappingAPI.meteoIconLayer = new ol.layer.Vector({
        source: mappingAPI.meteoIconLayerSource,
        style: mappingAPI.getMeteoIconStyle            
    });

样式定义如下所示:

return [new ol.style.Style({
  image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
    anchor: [0.5, 0.5],
    anchorXUnits: 'fraction',
    anchorYUnits: 'fraction',
    opacity: 0.7,
    src: "data/meteo/icon" + feature.get('obj_id') + ".png"
})];

当 src 如上所述定义时(使用特征的 属性 指向唯一编号),我的地图上的图标开始闪烁,因为样式过程再次为图层上的所有特征不停地调用然后再次。以防万一,我参考这样一张图片来替换定义:

src: "data/meteo/icon3898.png",

甚至像这样:

src: "data/meteo/icon" + feature.get('dummy') + ".png",

所有特征的虚拟对象都相同,一切都很好 - 样式过程为每个特征调用一次,直到地图需要重绘。

拜托,有人可以帮助解决这个问题吗?或者有没有其他方法,如何在不将src定义放在样式中的情况下将图标放置在地图上?

马立克

所以,看起来 Openlayers 在加载如此多的图像时遇到了问题,并且它会在没有及时完成时定期启动重新加载(我只是猜测)。如果我将图像预加载到网页上的图像对象中,并且我使用 img 样式 属性(而不是 src),它会按预期工作。 imgSize 属性 也必须设置,否则图标根本不显示。最好的方法是:

img: img,    
imgSize: [img.clientWidth,img.clientHeight]