arcgis js api3.x featurelayer加标注

mac2024-06-03  31

说明几种拿不到featurelayer所有几何的情况: 1. 监听featurrelayer的load事件,在这个事件中featurelayer.graphics得到的是一个空数组,此时是拿不到所有的几何的。 2. 通过featurelayer的queryFeature方法或者使用querytask请求,都只返回前1000条数据,这个是featurelayer的默认返 回数目,修改方法,请参照:https://blog.csdn.net/D_bel/article/details/102843289 通过上面的方法处理后:利用update-end事件,可以拿到所有在发布服务的时候设置的最大值的数据。 监听featurelayer的update-end事件,在这个事件中通过featurelayer.graphics可以拿到featurelayer中的几何数据 var _this = this; var originalOption = { id:_this.polygonOriginalLayerId, mode: FeatureLayer.MODE_SNAPSHOT, outFields: ["*"] }; //serviceURL服务的url _this.polygonOriginalLayer = new FeatureLayer(serviceURL,originalOption); _this.polygonOriginalLayer.attr("cursor","pointer"); _this._map.addLayer(_this.polygonOriginalLayer); //标注图层 _this.originalLableLayer = new GraphicsLayer({id:"originalLayer"}); _this._map.addLayer(_this.originalLableLayer); _this.originalLableLayer.clear(); // _this.polygonOriginalLayer.on("update-end",function (evt) { array.forEach(_this.polygonOriginalLayer.graphics,function (graphic) { if(graphic.geometry && graphic.geometry.rings && graphic.attributes){   /** * 这个循环,对于多部件,会给每个部件的rings的单独图形添加标注 * 如果对于多部件的情况,只想显示一个标注,那不就不要这个循环 * **/ array.forEach(graphic.geometry.rings,function (ring) { var polygon = new Polygon(ring); polygon.spatialReference = _this.mapUtil._map.spatialReference; var textSym = new TextSymbol(graphic.attributes[_this.originalLableField]); //添加为每个文字graphic添加位置、文字内容 var graphicText = new Graphic(polygon,textSym); //将graphic加入图层 _this.originalLableLayer.add(graphicText); }); } }); });
最新回复(0)