Render Map on a Zip code

559
7
01-09-2014 01:48 AM
VikasNeekhra
New Contributor
I am using 3.8 Arc GIS JS api, and also new to this map world.

1. I have to render the map based on the zip code. If I enter any US zip code in a text box and hit submit button, then the map should render that location. So is there any method in Map which can help us on this?

2. When setting data in InfoTemplate then I have to show some text based on the condition, but looks like it is not able to store the fields value in javascript variable. Please suggest something on this. Below is the code I am trying.

var valCrewOnSite = ${CrewOnSite};
if( valCrewOnSite == "Yes") {
  crewOnSiteStatus = "<tr><td align=left width=95>Status:</td><td align=right>Restoration in progress</td><tr>";
}

Appreciating any help!

Regards,
Vikas
0 Kudos
7 Replies
JakeSkinner
Esri Esteemed Contributor
1.  You can use Query and the FeatureLayer selectFeatures method.  Ex:

var query = new Query();
query.where = "ZipCode = '" + dom.byId("btnSubmit");    
query.outFields = ['ZipCode'];
query.returnGeometry = true;
query.outSpatialReference = map.spatialReference;
zipCodeLayer.on('selection-complete', zoomCountry);
zipCodeLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, zoomToZip);


You will also want to render the selected feature.  Ex:

var selectSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new  SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,200,0]), 2), new Color([255,255,0,0.40]));

var zipCodeLayer = new FeatureLayer("http://server/arcgis/rest/services/ZipCodes/MapServer/0", {
  mode: FeatureLayer.MODE_SELECTION,
  outFields: ["*"]
});

zipCodeLayer.setSelectionSymbol(selectSymbol);
0 Kudos
JosephSaltenberger
New Contributor III
What would be the best way to re-render a subset or selection of features that are already displayed on the map? Right now, I have something similar to this example, where the whole layer is rendered:

https://developers.arcgis.com/en/javascript/jssamples/renderer_function.html

However, he data fields used to set the renderer are dynamic, so I have a function that runs every few seconds to re-render the entire layer. It would be ideal to only render the features that actually changed values. Any suggestions?

Thanks
0 Kudos
VikasNeekhra
New Contributor
Thanks Jake for looking into it.

I just have to move the map based on the zip code and dont have to highlight or show symbol on that. If we can set some extent on Map, but how find the extend for a particular zip code?

dojo.connect(dojo.byId("btnSubmit"),"onclick", function() {
  var queryTask = new esri.tasks.QueryTask(<SERVICE_URL>);
  var query = new Query();
  query.where = "ZipCode = '" + dojo.byId("txtZipCode").value;
  query.outFields = ['ZipCode'];
  query.returnGeometry = true;
  query.outSpatialReference = map.spatialReference;
  querytask.execute(query)

});
0 Kudos
KenBuja
MVP Esteemed Contributor
Executing a QueryTask will return a FeatureSet. You can use "graphicsUtils.graphicsExtent" to get the extent of the FeatureSet
0 Kudos
JakeSkinner
Esri Esteemed Contributor
The Query Task has a complete event, which returns a featureSet.  You can set the extent to the featureSet using the graphicsUtils.graphicsExtent method:

queryTask.on("complete", function(featureSet){
    var featureExtent = graphicsUtils.graphicsExtent(featureSet.features);                    
    map.setExtent(featureExtent);
}
0 Kudos
JakeSkinner
Esri Esteemed Contributor
What Ken said 😉
0 Kudos
JohnGravois
Frequent Contributor
maybe i'm missing something, but wouldn't it be a lot easier to use our World Geocoding Service for this?
0 Kudos