2014-10-16 101 views
2

我們正在嘗試查找有關如何在地圖上的新點被點擊後如何隱藏標記的建議或實施選項。隱藏ArcGis標記

在我們的應用程序中,一旦用戶點擊地圖上的特定銷,我們將顯示與點擊事件關聯的新銷(位於不同緯度/長位置)。即一個點應該在俄克拉何馬州,但地圖顯示得克薩斯州,所以一旦點擊標記德克薩斯州,一個新的標記在俄克拉荷馬州顯示。我們的問題是,無論何時用戶選擇一個新點,我們都無法爲之前的選擇「隱藏」標記,這會使我們的屏幕混亂。

有關我們如何處理此問題的任何建議?

代碼如下:

require(["esri/map", "esri/geometry/Point", "esri/symbols/SimpleMarkerSymbol", "esri/graphic", "dojo/_base/array", "dojo/dom-style", "dojox/widget/ColorPicker", "esri/InfoTemplate", "esri/Color", "dojo/dom", "dojo/domReady!", "esri/geometry/Polyline", "esri/geometry/geodesicUtils", "esri/units","esri/symbols/SimpleLineSymbol"], 
function(Map, Point,SimpleMarkerSymbol, Graphic, arrayUtils, domStyle, ColorPicker, InfoTemplate, Color, dom, Polyline, geodesicUtils, Units,SimpleLineSymbol) { 
map = new Map("mapDiv", { 
center : [-98.35, 35.50], 
zoom : 5, 
basemap : "topo" 
//basemap types: "streets", "satellite", "hybrid", "topo", "gray", "oceans", "osm", "national-geographic" 
}); 
map.on("load", pinMap); 
var arr = []; 
var initColor, iconPath; 
function pinMap() { 
map.graphics.clear(); 
iconPath = "M16,3.5c-4.142,0-7.5,3.358-7.5,7.5c0,4.143,7.5,18.121,7.5,18.121S23.5,15.143,23.5,11C23.5,6.858,20.143,3.5,16,3.5z M16,14.584c-1.979,0-3.584-1.604-3.584-3.584S14.021,7.416,16,7.416S19.584,9.021,19.584,11S17.979,14.584,16,14.584z"; 
var infoContent = "<b>Id</b>: ${Id} "; 
var infoTemplate = new InfoTemplate(" Details",infoContent); 
$.post('{{ path('points') }}', {}, function(r) { 
arrayUtils.forEach(r.points, function(point) { 
if (point.test==1) { 
initColor = "#CF3A3A"; 
} 
else { 
initColor = "#FF9900"; 
} 
arr.push(point.id,point.pinLon1,point.pinLat1,point.pinLon2,point.pinLat2); 
var attributes = {"Site URL":point.url,"Activity Id":point.id,"Updated By":point.updated,"Customer":point.customer}; 
var graphic = new Graphic(new Point(point.pinLon1,point.pinLat1),createSymbol(iconPath,initColor),attributes,infoTemplate); 
map.graphics.add(graphic); 
map.graphics.on("click",function(evt){ 
var Content = evt.graphic.getContent(); 
var storeId = getStoreId(Content); 
sitePins(storeId); 
}); 
}); 
}, 'json'); 
} 
function getStoreId(content){ 
var init = content.split(":"); 
var fin= init[2].split("<"); 
return fin[0].trim(); 
} 
function sitePins(siteId) { 
iconPathSite = "M15.834,29.084 15.834,16.166 2.917,16.166 29.083,2.917z"; 
initColorSite = "#005CE6"; 
var infoContent = "<b>Distance</b>: ${Distance} Miles"; 
var infoTemplate = new InfoTemplate(" Distance to Location",infoContent); 
var indexValue=0; 
for (var index = 0; index < arr.length; index++){ 
if (arr[index]==storeId){ 
indexValue =index; 
} 
} 
pinLon1 = arr[indexValue+1]; 
pinLat1 = arr[indexValue+2]; 
pinLon2 = arr[indexValue+3]; 
pinLat2 = arr[indexValue+4]; 
var line = {"paths":[[[pinLon1, pinLat1], [pinLon2, pinLat2]]]}; 
line = new esri.geometry.Polyline(line); 
var lengths = Number(esri.geometry.geodesicLengths([line], esri.Units.MILES)).toFixed(2); 
var attributes = {"Distance":lengths}; 
var graphicSite = new Graphic(new Point (pinLon1,pinLat1), createSymbol(iconPathSite, initColorSite),attributes,infoTemplate); 
var pathLine = new esri.Graphic(line, new esri.symbol.SimpleLineSymbol()); 
map.graphics.add(pathLine); 
map.graphics.add(graphicSite); 
} 

function createSymbol(path, color) { 
var markerSymbol = new esri.symbol.SimpleMarkerSymbol(); 
markerSymbol.setPath(path); 
markerSymbol.setSize(18); 
markerSymbol.setColor(new dojo.Color(color)); 
markerSymbol.setOutline(null); 
return markerSymbol; 
} 
}); 
</script> 

回答

0

據我得到的代碼,它顯示了標記和點之間的距離,然後clicked.You正在創建在地圖上的每一次點擊事件點和折線。以下內容可以提供幫助:

1)請提供id說'abc'給折線圖形網站。

2)然後在每個點擊事件中刪除ID爲'abc'的圖形和折線。

dojo.forEach(this.map.graphics.graphics, function(g) { 
     if(g && g.id === "abc") { 
     //remove graphic with specific id 
      this.map.graphics.remove(g); 
     } 

}, this); 

3)然後,您可以創建新的折線和點,因爲你已經在做它。