在openlayers中调用两次的style函数

时间:2016-11-17 06:45:26

标签: javascript openlayers openlayers-3

我想知道为什么我的样式函数会为添加到图层的每个集群调用两次。这是我的代码:

function calculateClusterInfo(feature, resolution) {
    //This function called twice
    var style, size, circleRadius, circleFill, zoomMapID;
    size = feature.get('features').length;
    var style = styleCache[size];
    if (!style) {
    if (size > 1) {
        if (size < 10) { // small cluster
            circleRadius = 30;
            circleFill = new ol.style.Fill({
                color: [181, 226, 140, 0.6]
            });
        } 
        style = [new ol.style.Style({
            image: new ol.style.Circle({
                radius: circleRadius,
                fill: circleFill
            }),
            text: new ol.style.Text({
                textAlign: "start",
                textBaseline: "middle",
                font: "bold 12px helvetica",                    
                text: size,
                fill: new ol.style.Fill({color: "#000000"}),
                stroke: new ol.style.Stroke({color: "#ffffff", width: 4}),
                offsetX: 0,
                offsetY: 0,
                rotation: 0
            })
        })];          
        return style;
    } else {
        style = [feature.get('features')[0].getStyle()];
        return style;
    }
    }
};

我无法弄清楚为什么样式函数被调用两次。

0 个答案:

没有答案