简体   繁体   English

openlayers3功能不显示图层样式

[英]openlayers3 feature disapear layer style

I'm working on an embedded "GPS". 我正在开发嵌入式“ GPS”。 Our embedded browser is qt5.3 webpluging which is rather old but we can't upgrade our qt yet. 我们的嵌入式浏览器是qt5.3 webpluging,它已经很老了,但是我们还不能升级qt。

The problem is that when we update the marker of current position it sometimes disappear for 10s or more. 问题是,当我们更新当前位置的标记时,它有时会消失10秒或更长时间。 Here is a link to a working example or the problem: https://jsfiddle.net/6c8negae/3/ . 这是工作示例或问题的链接: https : //jsfiddle.net/6c8negae/3/ In firefox there is no problem however the image disapear sometimes in our browser. 在firefox中,没有问题,但是有时我们的浏览器中的图像消失了。

The style we compute: 我们计算的样式:

var STYLE_ON = new ol.style.Style({
    image: new ol.style.Icon({
        // not the actual arrow we use: ours is 30*30, 1.9kio
        src: "http://images.easyfreeclipart.com/1067/double-up-arrow-1067454.jpg"
    })
});
var STYLE_OFF = new ol.style.Style({
    image: new ol.style.Icon({
        // actually a grayed image of the STYLE_ON arrow
        src: "http://images.easyfreeclipart.com/1067/double-up-arrow-1067454.jpg"
    })
});

How we select the style: 我们如何选择样式:

map.addLayer(new ol.layer.Vector({
    type: 'markers',
    source: markers,
    style: function (feature) {
        var style = null;
        if (feature.get('vtype') === 'cur') {
            style = feature.get('fade') ? STYLE_OFF : STYLE_ON;
            style.getImage().setRotation(feature.get('rotation'));
        }
        else {
            style = new ol.style.Style({
                image: new ol.style.Circle({
                    radius: 6,
                    opacity: 0.5,
                    fill: new ol.style.Fill({
                        color: COLORS[feature.get('vtype')]
                    })
                })
            });
        }
        return [style];
    }
}));

Are there any workaround? 有什么解决方法吗? It don't look more efficient to have one style per feature (as of our original code was that way). 每个功能只有一种样式看起来并没有更高的效率(就像我们原来的代码那样)。

Try a base64 encoded image: 尝试使用base64编码的图像:

  var iconStyle = new ol.style.Style({
      image: new ol.style.Icon({
      src: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANRJREFUeNrsksERgyAQRfdTQS7pI3YQS0kJHlJFiggdpARboITcc7GELDObDCrIqnBKdoaB0c97sApaUS+63Xk68WiPdB00e6AEH3h68DjLI6eVQAnv5eRhqSTYCFdLsAOukmAnPCtBAfiiBIXgSQkKwqMSFIbPJKgAH0lMJTgJszdiSpXvY7fwvpNM8haG+3ThhU3A28wBnGRiEuvZ/gYUkQzykVyuD5KZSqwwyQTBj0QNT0i+8JEgkDRr4BNJE8JnAgk+t/42sb2GKtdf8AOCtwADADYvWhxy2YPJAAAAAElFTkSuQmCC'
    })
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM