AnsweredAssumed Answered

Hide Marker

Question asked by Lucasbrito3 on Oct 15, 2014
Latest reply on Oct 17, 2014 by Lucasbrito3

We are trying to find suggestions, or implementation options on how to hide a marker once a new point on the map has been clicked.

In our application, once the user clicks on a particular pin on the map, we display a new pin (in a different lat/long location) that is associated with the click event. I.e. a point should be in oklahoma, but the map is displaying texas, so once the marker texas is clicked, a new marker in oklahoma is shown. Our issue is that whenever a user selects a new point, we are not able to "hide" the marker for the previous selection, which then clutters our screen.

Any suggestions on how we could handle this issue?

Code is below:


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( ) {;  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.pinLon1,point.pinLat1,point.pinLon2,point.pinLat2);  var attributes = {"Site URL":point.url,"Activity Id","Updated By":point.updated,"Customer":point.customer};  var graphic   = new Graphic(new Point(point.pinLon1,point.pinLat1),createSymbol(iconPath,initColor),attributes,infoTemplate); graphic );"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()); pathLine ); 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>