AnsweredAssumed Answered

Getting "cannot read property id of 'null' error when creating a Query()

Question asked by pierckbp on Oct 28, 2015
Latest reply on Oct 28, 2015 by pierckbp

I'm trying to work through a simple tutorial and whenever I get to the "var query = new Query();" line I get an error in chrome in init.js and cannot read id of null. Supposedly the error is on line 143 of init.js in b.get. I get the same error running locally with simpleHTTPServer or from cloud9.

 

**Code below in its entirety

<!DOCTYPE html>

<html>

<head>

  <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">

</head>

 

 

<body>

<select id="population" name="population">

      <option value="" selected="selected">Select a population</option>

      <option value="2500">2,500</option>

      <option value="5000">5,000</option>

      <option value="7500">7,500</option>

    </select>

  <div id="map">

 

 

  </div>

</body>

 

 

<script src="http://js.arcgis.com/3.14/"></script>

<script>

  require([

  'dojo/dom',

  'dojo/on',

  'dojo/_base/array',

  'dojo/_base/Color',

  'esri/map',

  'esri/tasks/query',

  'esri/tasks/QueryTask',

  'esri/symbols/SimpleMarkerSymbol',

  'esri/symbols/SimpleLineSymbol',

  'esri/graphic'], function(dom, on, array, Query, QueryTask, Map, Color, SimpleMarkerSymbol, SimpleLineSymbol, Graphic){

 

  var map = new Map('map', {

  basemap: 'streets',

  center: [-118.2095, 34.0866],

  zoom: 10

  });

  var url = 'http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/la_county_labor_centroid/FeatureServer/0';

     var markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, null, new Color([50,50,255]));

 

  function onQuerySuccess(featureSet) {

     map.graphics.clear();

     array.forEach(featureSet.features, function(feature){

        feature.setSymbol(markerSymbol);

        map.graphics.add(feature);

     });

  }

  function onError(error){

     console.error('An eerror occurred in the query: ', error);

  }

 

 

  on(dom.byId('population'), 'change', function(e) {

    var population = e.target.value;

    if (population.length > 0) {

      var queryTask = new QueryTask(url);

      var query = new Query();

      query.where = 'TOTAL_POP > ' + population;

      query.returnGeometry = true;

      queryTask.execute(query).then(onQuerySuccess, onError);

    }

  });

 

  });

</script>

</html>

Outcomes