Select to view content in your preferred language

ArcGIS - How to add multiple states to existing map?

1515
4
12-01-2014 11:22 AM
kaiserislam
Deactivated User

I am new to ARCGIS. Can someone show me how can I go about adding 2 states New Jersey and Delaware to the existing code? So that it displays along with New York.

Is there also a wild card option to add all the states?

<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <!--The viewport meta tag is used to improve the presentation and behavior of the samples
  on iOS devices-->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Class Breaks Renderer</title>

  <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
  <style>
  html, body, #map{
  height: 100%;
  margin: 0;
  padding: 0;
  }
  </style>
  <script src="http://js.arcgis.com/3.11/"></script>
  <script>

  //https://developers.arcgis.com/javascript/jssamples/renderer_class_breaks.html
  var map;
  require([
  "esri/map", "esri/layers/FeatureLayer",
  "esri/InfoTemplate", "esri/symbols/SimpleFillSymbol",
  "esri/renderers/ClassBreaksRenderer",
  "esri/Color", "dojo/dom-style", "dojo/domReady!"
  ], function(
  Map, FeatureLayer,
  InfoTemplate, SimpleFillSymbol,
  ClassBreaksRenderer,
  Color, domStyle
  ) {
  map = new Map("map", {
  basemap: "streets",
  center: [-74.215, 42.382],
  zoom: 7,
  slider: false
  });

  var symbol = new SimpleFillSymbol();
  symbol.setColor(new Color([150, 150, 150, 0.5]));

  // Add five breaks to the renderer.
  // If you have ESRI's ArcMap available, this can be a good way to determine break values.
  // You can also copy the RGB values from the color schemes ArcMap applies, or use colors
  // from a site like www.colorbrewer.org
  //
  // alternatively, ArcGIS Server's generate renderer task could be used
  var renderer = new ClassBreaksRenderer(symbol, "POP07_SQMI");
  renderer.addBreak(0, 25, new SimpleFillSymbol().setColor(new Color([56, 168, 0, 0.5])));
  renderer.addBreak(25, 75, new SimpleFillSymbol().setColor(new Color([139, 209, 0, 0.5])));
  renderer.addBreak(75, 175, new SimpleFillSymbol().setColor(new Color([255, 255, 0, 0.5])));
  renderer.addBreak(175, 400, new SimpleFillSymbol().setColor(new Color([255, 128, 0, 0.5])));
  renderer.addBreak(400, Infinity, new SimpleFillSymbol().setColor(new Color([255, 0, 0, 0.5])));

  var infoTemplate = new InfoTemplate("${NAME}", "${*}");
  var featureLayer = new FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3", {
  mode: FeatureLayer.MODE_SNAPSHOT,
  outFields: ["*"],
  infoTemplate: infoTemplate
  });

  featureLayer.setDefinitionExpression("STATE_NAME = 'New York'");
  featureLayer.setRenderer(renderer);
  map.addLayer(featureLayer);
  });
  </script>
  </head>

  <body>
  <div id="map"></div>
  </body>

</html>

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Kaiser,

  If you look at the code there is this line that sets the definition expression for the FeatureLayer:

featureLayer.setDefinitionExpression("STATE_NAME = 'New York'");

You need to adjust this line to add the other states you are interested in, or remove this line if you want all states.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kaiser,

   By the way you will notice that I have moved your thread from the GeoNet Help space to the ArcGIS API for JavaScript‌ space. It is important to post questions in the correct spaces.

0 Kudos
kaiserislam
Deactivated User

Robert  Thank you. I was trying something like this but none worked

featureLayer.setDefinitionExpression("STATE_NAME = 'New York', 'New Jersey'");

featureLayer.setDefinitionExpression("STATE_NAME = 'New York'","STATE_NAME = 'New Jersey'");

featureLayer.setDefinitionExpression("STATE_NAME = 'New York'");; featureLayer.setDefinitionExpression("STATE_NAME = 'New Jersey'")

;

The first options render nothing , the second option rendered on new york ,  third option only NJ .

what is right way to add other states?

Also, If  I try to display for the whole of USA removing the featurelayer, defintion(

  1. featureLayer.setDefinitionExpression("STATE_NAME = 'New York'");  )

it only  displays half of the USA. screen grab attached below.argis-screengrab.jpg

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kaiser,

  OK, so you need some basic SQL syntax help then.

featureLayer.setDefinitionExpression("STATE_NAME IN( 'New York', 'New Jersey', 'Delaware')");

The reason that removing the DefinitionExpression does not work is you are likely reaching the Map Services max feature output.