Select to view content in your preferred language

Clear last point

438
1
05-14-2013 11:49 AM
GaryWine
Deactivated User
Hey All

I have looked through quite a few of the posts on this process. I am using the find a feature on a map sample, modified slightly. When I click on a row in the datagrid I need the previous point, or polyline to go away. Right now I have a secondary symbol set up to show the selected street in black, when I click on the next street I need that previous selection to disappear.

In the datagrid under the STREET tab, if there is a streetname with no address to its left - then that is an actual polyline from a street centerlines feature class. Click on one of those and you will see the zoom and the symbol change for the selected road.

// JavaScript Document// JavaScript Document
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("esri.map");
dojo.require("esri.tasks.find");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.Button");
     
var findTask, findParams;      
var map, center, zoom;      
var grid, store;
function init() {
  dojo.connect(grid, "onRowClick", onRowClickHandler);
        center = [-77.985, 39.450];
        zoom = 11;
        map = new esri.Map("map", {
          basemap: "hybrid",
          center: center,
          zoom: zoom,
     minZoom: 11,
     maxZoom: 19,
     logo: false,
     sliderStyle: 'small'
        });
        //Create Find Task using the URL of the map service to search
        findTask = new esri.tasks.FindTask("http://maps.berkeleywv.org/arcgis/rest/services/research_911/Operational/MapServer/");
        dojo.connect(map, "onLoad", function() {
          //Create the find parameters
          findParams = new esri.tasks.FindParameters();
          findParams.returnGeometry = true;
          findParams.layerIds = [0,1,9];
          findParams.searchFields = ["FULLADDR","FULLNAME","INTERSECTION"];
          findParams.outSpatialReference = map.spatialReference;
          console.log("find sr: ", findParams.outSpatialReference);
        });
      }
      function doFind() {
        //Set the search text to the value in the box
        findParams.searchText = dojo.byId("ownerName").value;
        findTask.execute(findParams,showResults);
      }
      function showResults(results) {
        //This function works with an array of FindResult that the task returns
        map.graphics.clear();
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));
    var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([255, 119, 25, 9]));
    var intersectionmarkerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 255, 255]), 2), new dojo.Color([0, 0, 0, 8]));
        //create array of attributes
        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          //graphic.setSymbol(symbol);
     switch (graphic.geometry.type) {
      case "polygon":
      graphic.setSymbol(symbol);
      break;
      case "point":            
      graphic.setSymbol(markerSymbol);            
      break;          
      case "polyline":            
      graphic.setSymbol(lineSymbol);           
      break;
      case "multipoint":
      graphic.setSymbol(intersectionmarkerSymbol);
      break;
     }
          map.graphics.add(graphic);
          return result.feature.attributes;
        });
       
        //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items
        };
         //Create data store and bind to grid.
        store = new dojo.data.ItemFileReadStore({ data:data });
        var grid = dijit.byId('grid');
        grid.setStore(store);
        //Zoom back to the initial map extent
        map.centerAndZoom(center, zoom);
      }
//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt){
var extent;
var clickedItemId = grid.getItem(evt.rowIndex).OBJECTID;
  var selectedItemId;
var selectedlineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 10);
  dojo.forEach(map.graphics.graphics,function(graphic){
   if((graphic.attributes) && graphic.attributes.OBJECTID === clickedItemId){
     selectedItemId = graphic;
      return;
    }
  });
if(selectedItemId.geometry.type == "polyline"){
   var itemExtent = selectedItemId.geometry.getExtent();
  selectedItemId.setSymbol(selectedlineSymbol);
  map.setExtent(itemExtent);
}
if (selectedItemId.geometry.type == "point") {
  var itemExtent = selectedItemId.geometry
   extent = pointToExtent(map, itemExtent.x, itemExtent.y, 150);
  map.setExtent(extent);
}
}
function pointToExtent(map, pointX, pointY, tolerance){
    var xmin = pointX - tolerance;
    var ymin = pointY - tolerance;
    var xmax = pointX + tolerance;
    var ymax = pointY + tolerance;
   
    return new esri.geometry.Extent(xmin, ymin, xmax, ymax, map.spatialReference)
}
     
dojo.ready(init);
0 Kudos
1 Reply
VinayBansal
Frequent Contributor
You can add attribute to the secondary symbol graphic, like graphic.attributes["MySelection"] = "True". And when you need to delete the graphic, find the graphic with having attribute "MySelection" from graphics layer before making another selection and remove the graphic. Its just a way of setting the flag for your graphic that needs to be deleted.
0 Kudos