因為項目需要使用,所以最近找了下Graphic圖層的顯隱控制。但是之前的很多博客所說的hide和show方法在api中並沒有(可能是版本更新給干掉了吧)。然后就查了查arcGis For js 找了一個折中方法,供大家參考。如果大家有其他更好的方案可以提出來,共同進步。
首先是創建Graphic對象
1 var point = { 2 type : "point", // autocasts as new Polyline() 3 longitude : 114, 4 latitude:96 5 }; 6 var markerSymbol = { 7 type : "simple-marker", // autocasts as SimpleLineSymbol() 9 color : "rgba(255,0,0,1)" 10 }; 11 var pointGraphicName="point"+areaArr[a].objectid; 12 var graphic= new self.param.Graphic({ 13 geometry : point, // Add the geometry created in step 4 14 symbol : markerSymbol,16 visible:true 17 })
然后存入到graphics,然后控制顯隱其實就是graphics添加和刪除要素圖層
view.graphics.add(graphic);
view.graphics.remove(graphic);