【问题标题】:UI is getting blocked when zooming in/out with markers in openlayers integration在 openlayers 集成中使用标记放大/缩小时 UI 被阻止
【发布时间】:2019-04-17 00:59:26
【问题描述】:

我已在我的 angularJs/Typescript 项目中将 openlayers 与 bing map 集成以开发 ms 动态 crm 客户端应用程序。我在现场服务移动 crm 中将此应用程序用作离线 html。

我在地图上有大约 5k 条记录作为标记,但是当我放大/缩小地图时,地图会挂起,这意味着当时所有活动都会阻塞大约 10-20 秒,我认为这太可怕了。

下面是浅浅的代码:

this.ClusterSource = new ol.source.Cluster({
     distance: distance,
     source: vectorSource
});

var vectorLayer = new ol.layer.Vector({
    renderMode: 'image',
    source: this.ClusterSource,
    style: this.styleFunction,
    zIndex: 9999
});


self.MapControl.addLayer(vectorLayer);  

styleFunction = (feature, resolution) => {
    let self = this;

    if (!feature || !resolution) return;

        let finalStyle: ol.style.Style;
        let features = <ol.Feature[]>feature.get("features");
        if (features.length === 1) {
            finalStyle = new ol.style.Style({
                image: new ol.style.Icon({ src: 
                self.getIconForSinglePlace(feature.get("features")[0]) })
            });
        } else if (features.length > 1) {
            if (resolution > 1) finalStyle = 
                self.getStyleForCluster(features.length);
            else self.displayOverlapping(features);
        }

        return finalStyle;
    }



    getStyleForCluster = (size: number): ol.style.Style => {
        let clusterStyle = (<any>window).styleCache[size];
        if (!clusterStyle) {
            clusterStyle = new ol.style.Style({
                image: new ol.style.Circle({
                    radius: (Math.log(size) / Math.log(10)) * 3 + 10,
                    fill: new ol.style.Fill({
                        color: this.getFillColorForPlace(size)
                    })
                }),
                text: new ol.style.Text({
                    text: size.toString(),
                    fill: new ol.style.Fill({
                        color: "#fff"
                    })
                })
            });
            (<any>window).styleCache[size] = clusterStyle;
        }
        return clusterStyle;
    }

    getIconForSinglePlace(feature: any) {
        return feature.get("metadata").icon
            ? feature.get("metadata").icon
            : 
  `../images/pushpins/${feature.get("metadata").Color.substring(1)}.png`;
    }

    // this function call for duplicate position of markers
    displayOverlapping = (features: ol.Feature[]) => {
        if (features) {
            let coordinates = (<any>features[0].getGeometry()).getCoordinates();
            let points = this.generatePointsCircle(features.length, coordinates);

            let multiLineString = new ol.geom.MultiLineString([]);
            multiLineString.setCoordinates([]);

            features.forEach((feature, index) => {
                multiLineString.appendLineString(new ol.geom.LineString([coordinates, points[index]]));
                feature.setGeometry(new ol.geom.Point(points[index]));
            });
        }
    };

我正在寻找专家的建议。

【问题讨论】:

    标签: dynamics-crm openlayers openlayers-5


    【解决方案1】:

    您应该以与缓存集群样式相同的方式缓存单个要素样式。

        if (features.length === 1) {
            let src = self.getIconForSinglePlace(feature.get("features")[0]);
            finalStyle = (<any>window).styleCache[src];
            if (!finalStyle) {
                finalStyle = new ol.style.Style({
                    image: new ol.style.Icon({ src: src })
                });
                (<any>window).styleCache[src] = finalStyle;
            }
    

    【讨论】:

    • 嗨@Mike,谢谢你的建议。实施您的解决方案后,当我放大/缩小地图时,仍然会遇到相同的问题阻塞 UI 约 20 秒。场景是在搜索后,我在地图上有大约 2k 到 3/5k 的记录,然后我放大/我们的,当我点击标记或 UI 上的任何按钮时,UI 被阻止大约 20 秒,它只发生一次。在刷新页面之前,问题永远不会发生。那么可能是什么原因呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多