arcgis api for javascript 点聚合

这篇博客介绍了如何使用 ArcGIS API for JavaScript 实现点聚合功能,提供了相关的 HTML 代码示例以及 ClusterLayer.js 的修改版,并分享了包含1000个照片数据的1000-photos.json文件的链接。
摘要由CSDN通过智能技术生成

目录:


html代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Cluster</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.23/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.23/esri/css/esri.css">
    <style>
        html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
        #map{ margin: 0; padding: 0; }

        /* center the image in the popup */
        .esriViewPopup .gallery { margin: 0 auto !important; }
    </style>

    <script>
        // helpful for understanding dojoConfig.packages vs. dojoConfig.paths:
        // http://www.sitepen.com/blog/2013/06/20/dojo-faq-what-is-the-difference-packages-vs-paths-vs-aliases/
        var dojoConfig = {
            paths: {
                extras: location.pathname.replace(/\/[^/]+$/, "") + "/extras"
            }
        };
    </script>
    <script src="https://js.arcgis.com/3.23/"></script>
    <script>
        var map;
        require([
            "dojo/parser",
            "dojo/ready",
            "dojo/_base/array",
            "esri/Color",
            "dojo/dom-style",
            "dojo/query",

            "esri/map",
            "esri/request",
            "esri/graphic",
            "esri/geometry/Extent",

            "esri/symbols/SimpleMarkerSymbol",
            "esri/symbols/SimpleFillSymbol",
            "esri/symbols/PictureMarkerSymbol",
            "esri/renderers/ClassBreaksRenderer",

            "esri/layers/GraphicsLayer",
            "esri/SpatialReference",
            "esri/dijit/PopupTemplate",
            "esri/geometry/Point",
            "esri/geometry/webMercatorUtils",

            "extras/ClusterLayer",

            "dijit/layout/BorderContainer",
            "dijit/layout/ContentPane",
            "dojo/domReady!"
        ], function(
                parser, ready, arrayUtils, Color, domStyle, query,
                Map, esriRequest, Graphic, Extent,
                SimpleMarkerSymbol, SimpleFillSymbol, PictureMarkerSymbol, ClassBreaksRenderer,
                GraphicsLayer, SpatialReference, PopupTemplate, Point, webMercatorUtils,
                ClusterLayer
        ) {
            ready(function() {
                parser.parse();

                var clusterLayer;
                var popupOptions = {
                    "markerSymbol": new SimpleMarkerSymbol("circle", 20, null, new Color([0, 0, 0, 0.25])),
                    "marginLeft": "20",
                    "marginTop": "20"
                };
                map = new Map("map", {
                    basemap: "oceans",
                    center: [-117.789, 33.543],
                    zoom: 13
                });

                map.on("load", function() {
                    // hide the popup's ZoomTo link as it doesn't make sense for cluster features
                    domStyle.set(query("a.action.zoomTo")[0], "display", "none");

                    // get the latest 1000 photos from instagram/laguna beach
                    var photos = esriRequest({
                        url: "data/1000-photos.json",
                        handleAs: "json"
                    });
                    photos.then(addClusters, error);
                });

                function addClusters(resp) {
                    var photoInfo = {};
                    var wgs = new SpatialReference({
                        "wkid": 4326
                    });
                    photoInfo.data = arrayUtils.map(resp, function(p) {
                        var latlng = new  Point(parseFloat(p.lng), parseFloat(p.lat), wgs);
                        var webMercator = webMercatorUtils.geographicToWebMercator(latlng);
                        var attributes = {
                            "Caption": p.caption,
                            "Name": p.full_name,
                            "Image": p.image,
                            "Link": p.link
                        };
                        return {
                            "x": webMercator.x,
                            "y": webMercator.y,
                            "attributes": attributes
                        };
                    });

                    // popupTemplate to work with attributes specific to this dataset
                    var popupTemplate = new PopupTemplate({
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值