• ArcGIS API for JavaScript 3.x与Supercluser


        以前的老项目还用着ArcGIS API for JavaScript 3.x,最近有数据更新要有几十万的数据要展示。
        仔细研究一番,发现ArcGIS API for JavaScript 3.41文档中写着仅限数据中的五万条,多了也不会聚合。
    image.png
        看着官方不提供解决方案,我决定找找开源的方案,找到一个ArcGIS API for JavaScript 4.x与Supercluser结合的clusterlayer,不过不是想要的结果,于是我自己开发一个。
    先基于supercluster创建数据聚合,一百万数据处理完0-9级聚合大概四秒钟。接着监听地图范围变化,这样就可以
    使用FeatureLayer显示

    var featureCollection = {
        "layerDefinition": null,
        "featureSet": {
            "features": [],
            "geometryType": "esriGeometryPoint"
        }
    };
    featureCollection.layerDefinition = {
        "geometryType": "esriGeometryPoint",
        "objectIdField": "CID",
        "drawingInfo": {
            "renderer": {
                "type": "simple",
                "symbol": {
                    "color": [79,218,79,255],
                    "type": "esriSMS",
                    "size":30,
                    "style": "esriSMSCircle",
                    "outline": {
                        "color": [79,218,79,255],
                        "width": 1,
                        "type": "esriSLS",
                        "style": "esriSLSSolid"
                    }
                }
            }
        },
        "fields": [{
            "name": "CID",
            "alias": "CID",
            "type": "esriFieldTypeOID"
        },
            {
                "name": "point_count",
                "alias": "point_count",
                "type": "esriFieldTypeInteger"
            },
            {
            "name": "point_count",
            "alias": "point_count",
            "type": "esriFieldTypeInteger"
        },
            {
                "name": "cluster_id",
                "alias": "cluster_id",
                "type": "esriFieldTypeInteger"
            },
            {
            "name": "point_count_abbreviated",
            "alias": "point_count_abbreviated",
            "type": "esriFieldTypeString"
        }
        ]
    };
    
    var popupTemplate = new PopupTemplate({
        title: "{point_count}",
        description: "{point_count_abbreviated}"
    });
    
    //create a feature layer based on the feature collection
    let monumentLayer = new FeatureLayer(featureCollection, {
        id: 'flickrLayer',
        infoTemplate: popupTemplate
    });
    
    

    worker中请求数据并创建聚合,根据页面信息传递数据

    
    index = new Supercluster({
        log: true,
        radius: 60,
        extent: 256,
        maxZoom: 9,
        minZoom: 0,
        //reduce: (accumulated, props) => { accumulated.sum += props.sum; },
        // properties to use for individual points when running the reducer
        map(props) {
            props.point_count = 1;
            props.point_count_abbreviated = '1';
            return props;
        },
    }).load(data.features);
    
    
    self.onmessage = function (e) {
        if (e.data.getClusterExpansionZoom) {
            postMessage({
                expansionZoom: index.getClusterExpansionZoom(e.data.getClusterExpansionZoom),
                center: e.data.center
            });
        } else if (e.data.bbox) {
            postMessage(index.getClusters(e.data.bbox, e.data.zoom));
        } else if (e.data.tile) {
            postMessage(index.getTile(e.data.tile[0], e.data.tile[1], e.data.tile[2]));
        }
    };
    
    

    image.png

    完成效果

    cluster (1).gif

    参考资料:

    https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#setfeaturereduction

    https://github.com/mapbox/supercluster

  • 相关阅读:
    Java操作redis
    ExtJs6编译之后上线报错无法查看到的解决方法
    使用idea开发工具,nginx服务部署Extjs6,SpringBoot项目到服务器
    跨域拦截Access-Control-Allow-Origin设置多个origin
    ExtJs6内嵌iframe,nginx部署本地前台文件
    基于resteasy,Base64码上传文件
    resteasy上传单个文件/多个文件到阿里云服务器
    win7 系统保留分区 BCDedit
    Ubuntu Linux系统下apt-get命令详解
    Linux 查看 硬件配置
  • 原文地址:https://www.cnblogs.com/polong/p/16437077.html
Copyright © 2020-2023  润新知