react项目arcgis地图初始化以及点聚合按实体状态分类实现

tech2025-09-04  49

arcgis地图初始化以及点聚合按实体状态分类实现

准备工作nginx代理配置api文件开始初始化实现点聚合展示点聚合文件实现不同状态下的点聚合

准备工作

首先,要初始化arcgis地图就需要地图api和地图服务,地图api大家可以去我的gitee下载:arcgisapi_3.2(开源的) 下载后是这样的,如图所示: 可以发现,里面既有api文档,也有其他文件,ConfigTool.exe我们后面会用到,另外两个markdown不用管。 地图服务推荐网址:点击前往 点进去自己选一个就行

nginx代理

为什么要用nginx代理呢,那是因为api文件过大,不适合放进项目里。 圆规正传,上图: 没错,arcgis-api就是我用git拉取的api文件夹,我放在了D盘,你们随意放,nginx的用法我这里就不说了,因为这篇文章不是介绍nginx的。 server { listen 7877; server_name localhost;

charset utf-8; location / { root "D:\\acgisdemo"; } error_page 500 502 503 504 /50x.html; }

配置api文件

还记得上面我提到的ConfigTool.exe工具吗,现在正是用它的时候了,首先打开工具,一路点确定不用管,然后你会看到以下界面: 按照我的方法去配置,如图所示: 为什么要配置这个呢?因为api里默认的是127.0.0.1,不配置的话在其他的同一个局域网的电脑访问就会报错,总之这么配就对了。

开始初始化

现在开始初始化: 下面展示一些 内联代码片。

// 首先把css引入,我是在public文件夹下的index.html下引入的 <script> var link; var css1 = 'http://'+window.location.hostname+':7877/arcgis_js_api/3_2/dijit/themes/tundra/tundra.css'; //7877是nginx开的端口 var css2 = 'http://'+window.location.hostname+':7877/arcgis_js_api/3_2/esri/css/esri.css'; var cssArr = [css1,css2]; var head = document.getElementsByTagName('head')[0]; for (var i=0;i<cssArr.length;i++){ link = document.createElement('link'); link.type='text/css'; link.rel = 'stylesheet'; link.href = cssArr[i]; head.appendChild(link); } </script> //其次要在用到地图的js/jsx文件引进模块 import esriLoader from 'esri-loader' //最后初始化地图 const mapURL = { url : "http://"+window.location.hostname+":7877/arcgis_js_api/3_2/init.js" }; var myMap,clusterLayer; esriLoader.loadModules([ "esri/map", "esri/toolbars/draw", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/PictureMarkerSymbol","esri/geometry/Point","esri/layers/GraphicsLayer", "esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol", "esri/SpatialReference","esri/InfoTemplate", "esri/graphic","esri/geometry/Extent", "dojo/_base/Color", "dojo/dom", "dojo/on", "esri/request", "dojo/_base/array","esri/renderers/ClassBreaksRenderer","esri/geometry/webMercatorUtils","ClusterLayer", "esri/dijit/PopupTemplate","dojo/domReady!" ], mapURL).then(([Map,Draw,SimpleMarkerSymbol,SimpleLineSymbol,PictureMarkerSymbol,Point,GraphicsLayer,PictureFillSymbol,CartographicLineSymbol,SpatialReference,InfoTemplate,Graphic,Extent,Color,dom,on,esriRequest,arrayUtils,ClassBreaksRenderer,webMercatorUtils,ClusterLayer,PopupTemplate])=>{ myMap = new Map("acgisMap",{ zoom: 10//地图层级 }); //地图服务是我上面给出的网址里选的,大家随意选 var myTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer"); myMap.addLayer(myTiledMapServiceLayer); });

效果如图 :

实现点聚合

我这里连着初始化,一起把代码贴上来吧

/** * * @param {地图服务} mapServer * @param {坐标系编号,访问地图服务地址,一般里面会写清楚,我这里用的是102100,WGS 1984 Web-Mercator坐标系} coordinates * @param {初始化中心点经度} centerLon * @param {初始化中心点纬度} centerLat * @param {初始化地图层级} dZoom * @param {这个是判断是否有不在线摄像机的标志,没有此需求的不必关心这个} flag */ initAcgisMap:function(mapServer,coordinates,centerLon,centerLat,dZoom,flag){ //api const mapURL = { url : "http://"+window.location.hostname+":7877/arcgis_js_api/3_2/init.js" }; var myMap,webMercator,clusterLayer; var photoInfo = []; esriLoader.loadModules([ "esri/map", "esri/toolbars/draw", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol","esri/symbols/PictureMarkerSymbol","esri/geometry/Point","esri/layers/GraphicsLayer", "esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol", "esri/SpatialReference","esri/InfoTemplate", "esri/graphic","esri/geometry/Extent", "dojo/_base/Color", "dojo/dom", "dojo/on", "esri/request", "dojo/_base/array","esri/renderers/ClassBreaksRenderer","esri/geometry/webMercatorUtils","ClusterLayer", "esri/dijit/PopupTemplate","dojo/domReady!" ], mapURL).then(([Map,Draw,SimpleMarkerSymbol,SimpleLineSymbol,PictureMarkerSymbol,Point,GraphicsLayer,PictureFillSymbol,CartographicLineSymbol,SpatialReference,InfoTemplate,Graphic,Extent,Color,dom,on,esriRequest,arrayUtils,ClassBreaksRenderer,webMercatorUtils,ClusterLayer,PopupTemplate])=>{ myMap = new Map("acgisMap",{ zoom: dZoom }); var myTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer(mapServer); myMap.addLayer(myTiledMapServiceLayer); //点击地图上摄像机时触发 dojo.connect(myMap, "onClick", showCoordinatesAndAddPoint); //改变地图层级开始时触发 dojo.connect(myMap, "onZoomStart", function(anchor,extent,zoomFactor,level){ startZoom = level; }); //改变地图层级结束时触发 dojo.connect(myMap, "onZoomEnd", function(anchor,extent,zoomFactor,level){ if(startZoom > level){ isCluster = true; } if(!isCluster){ return; } clusterLayer.changeExtentEvent(); }); //地图初始化完成后触发 dojo.connect(myMap, "onLoad",function() { if(graphicLoad()){ addClusterLayer(allCamaraData); } var height = parseInt($('#acgisMap_zoom_slider').css('height')); $('#acgisMap_zoom_slider').css({ left:'77%', top:window.innerHeight-60-height+'px' }); if(flag){ layer.msg('摄像机总数有'+cammreNum+'个,其中不在范围内的有'+errorcNum+'个'); } }); //点击摄像机方法 function showCoordinatesAndAddPoint(evt) { //get mapPoint from event if(evt.graphic){ var graphic=evt.graphic; var initialExtent = new Extent({ "xmin": graphic._extent.xmin, "ymin": graphic._extent.ymin, "xmax": graphic._extent.xmax, "ymax": graphic._extent.ymax, "spatialReference": { "wkid": coordinates } }); myMap.setExtent(initialExtent); if(graphic.symbol && graphic.symbol.url){ if(graphic.symbol.url.indexOf('map_camera_cluster') == -1){ if(videoObj){ if(videoObj.object){ videoObj.StartPlayCamera(loginHandle,graphic.attributes["deviceId"],0,0); } }else{ layer.msg('请移至IE11方可播放视频'); } }else{ clusterLayer._onClick(graphic); isCluster = false; } } }else{ return; } } //往地图添加摄像机 function graphicLoad() { var initialExtent = new Extent({ "xmin":centerLon, "ymin":centerLat, "xmax":centerLon, "ymax":centerLat, "spatialReference": { "wkid": coordinates } }); //allCamaraData地图摄像机点位数据,需要你们自己调接口获得的 myMap.setExtent(initialExtent); if(allCamaraData.length > 0){ return true; }else{ return false; } } //地图点聚合功能 function addClusterLayer(items) { var countyInfo = {}; countyInfo.data = arrayUtils.map(items, function (item) { var latlng = new Point(parseFloat(item.deviceLongitude),parseFloat(item.deviceLatitude),myMap.spatialReference); //var webMercator = webMercatorUtils.geographicToWebMercator(latlng); var attributes = item; return { "x": latlng.x, "y": latlng.y, "attributes": attributes }; }); //以下这些时不同状态的摄像机图标和摄像机聚合图标 var one = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/QiangJi.png", 20, 20); var error = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/QiangJiError.png", 20, 20); var goodCluster = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster_good.png", 34, 41).setOffset(0, 20); var errorCluster = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster_error.png", 34, 41).setOffset(0, 20); var all = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster.png", 34, 41).setOffset(0, 20); //点聚合实现方法 clusterLayer = new ClusterLayer({ "view":myMap, "map":myMap, "data": countyInfo.data, //"spatialReference": new SpatialReference({"wkid": coordinates}), //重要,否则 _clusterTest() 出现计算错误 "graphicSym":one, "graphicSymError":error, "symbolArray":[goodCluster,errorCluster,all] } ); clusterLayer.excuseClusterEvent(); myMap.addLayer(clusterLayer); } }); }

展示点聚合文件

从上面的代码可以看出,点聚合是通过一个叫ClusterLayer的模块实现的,这个模块要放进api后才能使用,我已经把ClusterLayer.js文件放进api文件夹中了,从上面的开源地址中拉取就可以得到了。 如图所示:

实现不同状态下的点聚合

首先是实现点聚合代码,可以看到已经有不同状态下的图标了。如果不需要不同的状态那把所有状态都用同一个图标即可。

//以下这些时不同状态的摄像机图标和摄像机聚合图标 var one = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/QiangJi.png", 20, 20); var error = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/QiangJiError.png", 20, 20); var goodCluster = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster_good.png", 34, 41).setOffset(0, 20); var errorCluster = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster_error.png", 34, 41).setOffset(0, 20); var all = new PictureMarkerSymbol("http://"+window.location.hostname+":7877/map_camera_cluster.png", 34, 41).setOffset(0, 20); //点聚合实现方法 clusterLayer = new ClusterLayer({ "view":myMap, "map":myMap, "data": countyInfo.data, //"spatialReference": new SpatialReference({"wkid": coordinates}), //重要,否则 _clusterTest() 出现计算错误 "graphicSym":one, "graphicSymError":error, "symbolArray":[goodCluster,errorCluster,all] } ); clusterLayer.excuseClusterEvent(); myMap.addLayer(clusterLayer);

其次是点聚合文件代码,可以自己照着上面的new ClusterLayer方法去选择性地查看:

define([ "dojo/_base/declare", "dojo/_base/array", "esri/Color", "esri/symbols/Font", "dojo/_base/connect", "esri/SpatialReference", "esri/geometry/Point", "esri/graphic", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/MultiLineTextSymbol", "esri/symbols/TextSymbol", "esri/geometry/webMercatorUtils", "esri/dijit/PopupTemplate", "esri/layers/GraphicsLayer", "esri/InfoTemplate" ], function ( declare, arrayUtils, Color, Font, connect, SpatialReference, Point, Graphic, SimpleMarkerSymbol, MultiLineTextSymbol, TextSymbol,webMercatorUtils, PopupTemplate, GraphicsLayer,InfoTemplate ) { return declare([GraphicsLayer],{ constructor: function(options) { this.view = options.view,//当前视图,必须 this.map = options.map,//当前地图,必须 this.id = "clusters",//图层id,必须 this.data = options.data || [],//聚类数据,必须 this.field = "clusterCount",//聚类的字段 this.distance = 100,//距离 this.labelColor = "#fff",//标注颜色,默认为白色 this.labelOffset = -10,//标注偏移,默认为-6 this.resolution = null, this.clusters = null, this.singles = null, //单个对象,点击时出现 this.showSingles = true, this.symbolArray = options.symbolArray,//graphic样式数组 this.singleSym = null,//单个graphic样式 this.graphicSym = options.graphicSym,//在线摄像机要素高亮样式 this.graphicSymError = options.graphicSymError,//离线摄像机要素高亮样式 this.singleTemplate = null, this.spatialReference = options.spatialReference,//空间参考 this.maxSingles = 1000,//单个集群最大数 this.timer = null }, /** * @description 初始化 * @creator 陈铭 * @createtime 2018-02-06 */ init:function(){ this.clusters = []; this.singles = []; this.spatialReference = this.view.spatialReference; if(this.symbolArray == null){ var red = new SimpleMarkerSymbol("circle", 20, null, new Color("green")); var blue = new SimpleMarkerSymbol("circle", 20, null, new Color("blue")); var green = new SimpleMarkerSymbol("circle", 20, null, new Color("red")); this.symbolArray = [red, blue,green]; } }, /** * @description 执行点聚合事件 * @creator 陈铭 * @createtime 2018-02-06 */ excuseClusterEvent: function() { //判断当前是否存在该id的图层,若有,删除 var layer = this.map.getLayer(this.id); if(layer != undefined || layer != null) this.map.remove(layer); //removeLayer(层 //初始化 this.init(); //清除当前图层上的图形 this._clear(); //设置Resolution this.setResolution(); //创建聚合图形 this.clusterGraphics(); var div = this.inherited(arguments); return div; }, /** * @description 设置Resolution * @creator 陈铭 * @createtime 2018-02-06 */ setResolution: function() { var e = this.view.extent; var rightTop = new Point(e.xmax, e.ymax, this.spatialReference); //右上角 var leftBottom = new Point(e.xmin, e.ymin, this.spatialReference); //左下角 if (!this.spatialReference.isWebMercator()) { var rightTopPoint = webMercatorUtils.geographicToWebMercator(rightTop); var leftBottomPoint = webMercatorUtils.geographicToWebMercator(leftBottom); this.resolution = (rightTopPoint.x - leftBottomPoint.x) / this.view.width; return; } this.resolution = (rightTop.x - leftBottom.x) / this.view.width; }, /** * @description 地图缩放处理事件 * @creator 陈铭 * @createtime 2018-02-06 */ changeExtentEvent:function(){ //清除当前图层上的图形 this._clear(); //设置Resolution this.setResolution(); //创建聚合图形 this.clusterGraphics(); }, /** * @description 移除缩放事件 * @creator 陈铭 * @createtime 2018-02-06 */ removeZoomEnd: function() { this.inherited(arguments); }, /** * @description 添加聚合集群 * @creator 陈铭 * @createtime 2018-02-06 */ add : function(p) { //判断点是否落在现有集群中,若没有,则新建一个新集群 if (p.declaredClass) { this.inherited(arguments); return; } //把新数据添加到data中 this.data.push(p); //是否添加到集群中 var clustered = false; for (var i = 0; i < this.clusters.length; i++) { var c = this.clusters[i]; //判断两点之间是否属于同一集群 if (this.clusterTest(p, c)) { //添加新点到现有集群 this.clusterAddPoint(p, c); //更新集群图形信息 this.updateClusterGeometry(c); //更新集群label信息 this.updateLabel(c); clustered = true; break; } } //如果没有添加到集群中,则创建新集群 if (!clustered) { this.clusterCreate(p); p.attributes.clusterCount = 1; this.showCluster(p); } }, /** * @description 清楚当前所有集群 * @creator 陈铭 * @createtime 2018-02-06 */ _clear : function() { var layer = this.map.getLayer(this.id); if (layer != undefined || layer != null) layer.clear(); // //clear()() // Summary: Remove all clusters and data // points. this.inherited(arguments); this.clusters.length = 0; }, /** * @description 清除单个集群 * @creator 陈铭 * @createtime 2018-02-06 */ clearSingles : function(singles) { var s = singles || this.singles; arrayUtils.forEach(s, function(g) { this.remove(g); }, this); this.singles.length = 0; }, /** * @description 点击集群事件 * @creator 陈铭 * @createtime 2018-02-06 */ _onClick : function(e,flag) { if(!flag){ this._clear(); //清除单个要素 this.clearSingles(this.singles); } //获取当前集群的数据 var singles = []; for (var i = 0, il = this.data.length; i < il; i++) { if (e.attributes.clusterId == this.data[i].attributes.clusterId) { singles.push(this.data[i]); } } //判断单个集群长度是否有大于单个集群最大长度 if (singles.length > this.maxSingles) { alert("对不起,当前集群长度大于" + this.maxSingles + "个,请放大到更大级别再进行查询当个集群!"); return null; } else { //停止地图点击 //e.stopPropagation(); //this.view.popup.content = "<div style='background-color:DarkGray;color:white'> miles.</div>"; //this.map.infoWindow.show(e.graphic.geometry); this.addSingles(singles); return singles; } }, /** * @description 创建聚合图形 * @creator 陈铭 * @createtime 2018-02-06 */ clusterGraphics : function() { for (var j = 0, jl = this.data.length; j < jl; j++) { var point = this.data[j]; var clustered = false; var numClusters = this.clusters.length; for (var i = 0; i < this.clusters.length; i++) { var c = this.clusters[i]; //判断两点之间是否属于同一集群 if (this.clusterTest(point, c)) { //添加新点到现有集群 this.clusterAddPoint(point, c); clustered = true; break; } } //如果没有添加到集群中,则创建新集群 if (!clustered) { this.clusterCreate(point); } } //显示所有集群 this.showAllClusters(); }, /** * @description 判断两点之间是否属于同一个集群 * @creator 陈铭 * @createtime 2018-02-06 */ clusterTest : function(p, cluster) { var c_latlng; var p_latlng; if (this.spatialReference.isWebMercator()) { //地图 为WebMercator坐标系 c_point = new Point(cluster.x, cluster.y, this.spatialReference); p_point = new Point(p.x, p.y, this.spatialReference); } else { //地图为非WebMercator坐标系,则需转换为墨卡托坐标系 c_latlng = new Point( parseFloat(cluster.x), parseFloat(cluster.y), this.spatialReference); p_latlng = new Point(parseFloat(p.x), parseFloat(p.y), this.spatialReference); c_point = webMercatorUtils .geographicToWebMercator(c_latlng); p_point = webMercatorUtils .geographicToWebMercator(p_latlng); } var distance = (Math.sqrt(Math.pow( (c_point.x - p_point.x), 2) + Math.pow((c_point.y - p_point.y), 2)) / this.resolution); return (distance <= this.distance); }, /** * @description 添加新点到现有集群 * @creator 陈铭 * @createtime 2018-02-06 */ clusterAddPoint : function(p, cluster) { //添加新点到现有集群 var count, x, y; count = cluster.attributes.clusterCount; x = (p.x + (cluster.x * count)) / (count + 1); y = (p.y + (cluster.y * count)) / (count + 1); cluster.x = x; cluster.y = y; //创建这个集群的新范围 if (p.x < cluster.attributes.extent[0]) { cluster.attributes.extent[0] = p.x; } else if (p.x > cluster.attributes.extent[2]) { cluster.attributes.extent[2] = p.x; } if (p.y < cluster.attributes.extent[1]) { cluster.attributes.extent[1] = p.y; } else if (p.y > cluster.attributes.extent[3]) { cluster.attributes.extent[3] = p.y; } //统计这个集群有多少个点 if(p.attributes.deviceStatus == '0'){ cluster.attributes.errorCount++ }else{ cluster.attributes.goodCount++ } cluster.attributes.clusterCount++; //判断是否包含attributes字段,若无,赋值 if (!p.hasOwnProperty("attributes")) { p.attributes = {}; } //给这个属性一个clusterId值 p.attributes.clusterId = cluster.attributes.clusterId; }, /** * @description 创建一个新集群 * @creator 陈铭 * @createtime 2018-02-06 */ clusterCreate : function(p) { var clusterId = this.clusters.length + 1; if (!p.attributes) { p.attributes = {}; } p.attributes.clusterId = clusterId; //创建一个新集群 var cluster = { "x" : p.x, "y" : p.y, "attributes" : { "clusterCount" : 1, "errorCount" : 1, "goodCount" : 1, "clusterId" : clusterId, "extent" : [ p.x, p.y, p.x, p.y ], "content" : p.attributes } }; this.clusters.push(cluster); }, /** * @description 显示所有集群 * @creator 陈铭 * @createtime 2018-02-06 */ showAllClusters : function() { var me = this; var array = this.groupData(); var flag; for (var i = 0; i <this.clusters.length; i++) { flag = false; var c = this.clusters[i]; if(c.attributes.clusterCount <= 5){ flag = true; } else if(c.attributes.clusterCount == c.attributes.goodCount){ this.singleSym = this.symbolArray[0]; }else if(c.attributes.errorCount == 1){ this.singleSym = this.symbolArray[1]; }else{ this.singleSym = this.symbolArray[2]; } this.showCluster(c,flag); } //数量多的话可能就要延迟超过100毫秒了 /*this.timer = setTimeout(function() { var tspans = document.querySelectorAll('tspan'); for(var i=0;i<tspans.length;i++){ tspans[i].style.fontSize = '8px'; } clearTimeout(me.timer); me.timer = null; },100)*/ }, /** * @description 获取分组组值数组 * @creator 陈铭 * @createtime 2018-02-06 */ groupData:function(){ //获取最大最小值 var max = this.clusters[0].attributes.clusterCount; var min = this.clusters[0].attributes.clusterCount; for (var i = 0; i <this.clusters.length; i++) { var count = this.clusters[i].attributes.clusterCount; if(max < count) max = count; else if(min > count) min = count; } //组距 var dValue = (max - min)/3; return [(max - dValue),(min + dValue)]; }, /** * @description 显示集群 * @creator 陈铭 * @createtime 2018-02-06 */ showCluster : function(c,flag) { if(flag){ this._onClick(c,flag); return; } var labelText; if(c.attributes.goodCount == 1){ labelText = 0 + '/' + c.attributes.clusterCount;//这里如需转行可直接+'\n'即可 }else{ labelText = c.attributes.goodCount + '/' + c.attributes.clusterCount; } var point = new Point(c.x, c.y, this.spatialReference); if(this.singleSym == null) this.singleSym = new SimpleMarkerSymbol("circle", 20, null, new Color("red")); //添加点图形 this.add(new Graphic(point, this.singleSym,c.attributes)); //添加文字到指定位置 var label = new TextSymbol(labelText).setFont(new Font("8px",Font.STYLE_NORMAL,Font.VARIANT_NORMAL,Font.WEIGHT_NORMAL)); label.color = new Color(this.labelColor); label.xoffset = 0; label.yoffset = this.labelOffset; this.add(new Graphic(point, label,c.attributes)); }, /** * @description 添加单个点 * @creator 陈铭 * @createtime 2018-02-06 */ addSingles : function(singles) { //添加单个点到地图上 arrayUtils.forEach(singles, function(p) { var g = null; if(p.attributes.deviceStatus == '1'){ g = new Graphic(new Point(p.x, p.y,this.spatialReference),this.graphicSym, p.attributes) }else{ g = new Graphic(new Point(p.x, p.y,this.spatialReference),this.graphicSymError, p.attributes) } //这里需要自己按需定义infoTemplate var infoTemplate = new InfoTemplate(); infoTemplate.setTitle("摄像机信息"); infoTemplate.setContent('<div><span>摄像机ip:</span><span>'+p.attributes.deviceIp+'</span></div><div><span>摄像机名称:</span><span>'+p.attributes.deviceName+'</span></div>'); g.setInfoTemplate(infoTemplate); this.singles.push(g); if (this.showSingles) { this.add(g); } }, this); }, /** * @description 更新集群图形 * @creator 陈铭 * @createtime 2018-02-06 */ updateClusterGeometry : function(c) { var cg = arrayUtils.filter(this.graphics,function(g) { return !g.symbol && g.attributes.clusterId == c.attributes.clusterId; }); if (cg.length == 1) { cg[0].geometry.update(c.x, c.y); } else { console.log("didn't find exactly one cluster geometry to update: ",cg); } }, /** * @description 更新集群Label * @creator 陈铭 * @createtime 2018-02-06 */ updateLabel : function(c) { //找到已存在的集群label var label = arrayUtils.filter(this.graphics,function(g) { return g.symbol && g.symbol.declaredClass == "esri.symbol.TextSymbol" && g.attributes.clusterId == c.attributes.clusterId; }); if (label.length == 1) { //更新集群Label this.remove(label[0]); var newLabel = new TextSymbol(c.attributes.clusterCount); newLabel.color = new Color(this.labelColor); newLabel.xoffset = 0; newLabel.yoffset = this.labelOffset; this.add(new Graphic(new Point(c.x,c.y, this.spatialReference), newLabel, c.attributes)); alert(newLabel.font.size); } else { console.log("didn't find exactly one label: ",label); } } }); })
最新回复(0)