openlayer3矢量图层文本显示重复

时间:2016-11-29 03:47:02

标签: openlayers-3

This is a picture which shows the number of my shops at this place, but why on my map the number 90 is repeated?. I am using a styleFunc to determine the color, the cold is something like:

 function styleFunction(feature) {
            var destCount = feature.get("destCount");
            var originCount = feature.get("originCount");
            if (typeof originCount === "undefined") {
                originCount = 0;
            }
            if (typeof destCount === "undefined") {
                destCount = 0;
            }
            totalPointsCount = destCount + originCount;
            totalPointsCount = totalPointsCount.toString();
            return getStyle(feature.getProperties().type);
        }

function styleFunction(feature) {
            var destCount = feature.get("destCount");
            var originCount = feature.get("originCount");
            if (typeof originCount === "undefined") {
                originCount = 0;
            }
            if (typeof destCount === "undefined") {
                destCount = 0;
            }
            totalPointsCount = destCount + originCount;
            totalPointsCount = totalPointsCount.toString();
            return getStyle(feature.getProperties().type);
        }

创建baseLayer的代码是:

fetch('data/xml/service-meta-data.xml').then(function (response) {
        return response.text();
    }).then(function (text) {
        var result = parser.read(text);
        var options = ol.source.WMTS.optionsFromCapabilities(result, {
            layer: 'China',
            matrixSet: 'EPSG:3857'
        });
        var baseLayer = new ol.layer.Tile({
            opacity: 1,
            source: new ol.source.WMTS(options)
        });
        var map = new ol.Map({
            layers: [
                baseLayer,
                vectorLayer
            ],
            overlays: [infoOverlay],
            target: 'map',
            view: view
        });
     })

您可以忽略所有数据处理,并专注于stylefunc,任何人都可以告诉我为什么数字会重复?很多人

1 个答案:

答案 0 :(得分:0)

查看此链接Openlayers3 Vector labels

当你开始放大时,平铺图层会创建重复的标签。所以创建它有ImageWMS图层。

    var baseLayer = new ol.layer.Image({
        opacity: 1,
        source: new ol.source.ImageWMS(options)
    });