layerDefinitions problem

1101
2
04-25-2012 01:39 PM
BetsySchenck-Gardner
Occasional Contributor
Does anyone know why this doesn't work:

var imageParameters = new esri.layers.ImageParameters();
var layerDefs = [];
layerDefs[1] = "vdate='2012/04/26-00Z'";
imageParameters.layerDefinitions = layerDefs;
imageParameters.layerIds = [1];
imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
imageParameters.transparent = true;
lyr = new esri.layers.ArcGISDynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/Models/NWS_AirTempForecasts/MapServer", {"imageParameters":imageParameters,"opacity":0.90});
map.addLayer(lyr);

If I go to the REST service for this map and to the query page of this particular layer, I can enter the vdate string of 2012/04/26-00Z and get a result.  But if I try to use the layerDefinitions option, I get no results.
0 Kudos
2 Replies
derekswingley1
Frequent Contributor
I think your code is correct but the underlying data in that service is a little wonky. If you do where 1=1, you see the vdate come back with lots of spaces:
{
  "displayFieldName": "vdate",
  "fieldAliases": {
    "vdate": "vdate"
  },
  "fields": [{
    "name": "vdate",
    "type": "esriFieldTypeString",
    "alias": "vdate",
    "length": 25
  }],
  "features": [{
    "attributes": {
      "vdate": "           2012\/04\/26-00Z"
    }
  }, {
    "attributes": {
      "vdate": "           2012\/04\/26-00Z"
    }
  }, {
    "attributes": {
      "vdate": "           2012\/04\/26-00Z"
    }
  }
  <snip>


I got it work at the REST endpoint with vdate like '%2012/04/26%' Here's a request that uses that:  http://www.ncddc.noaa.gov/arcgis/rest/services/Models/NWS_AirTempForecasts/MapServer/1/query?text=&g...

You might post this question over the in REST forum to see if someone over there has any additional input.

Edit:  Here's a working page:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/tundra/tundra.css" />
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/esri/dijit/css/Popup.css" />
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
      #map{ margin: 0; padding: 0; }
    </style>
    <script>var dojoConfig = { parseOnLoad: true };</script>
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>
    <script>
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
      
      var map;
      function init() {
        var ext = new esri.geometry.Extent({"xmin":-11077893,"ymin":4210843,"xmax":-7969046,"ymax":5570810,"spatialReference":{"wkid":102100}});
        map = new esri.Map("map",{ extent: ext, wrapAround180: true });
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
        map.addLayer(basemap);

        var imgParams = new esri.layers.ImageParameters();
        var layerDefs = [];
        layerDefs[1] = "vdate like '%2012/04/26%'";
        imgParams.layerDefinitions = layerDefs;
        imgParams.layerIds = [1];
        imgParams.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
        imgParams.transparent = true;

        var dyn = new esri.layers.ArcGISDynamicMapServiceLayer("http://www.ncddc.noaa.gov/arcgis/rest/services/Models/NWS_AirTempForecasts/MapServer", {
          "imageParameters": imgParams
        });
        map.addLayer(dyn);
        
        dojo.connect(map, "onLoad", function() { 
          dojo.connect(dijit.byId("map"), "resize", map, map.resize);
        });
      }
      dojo.ready(init);
    </script>
  </head>
  
  <body class="tundra">
    <div data-dojo-type="dijit.layout.BorderContainer" 
         data-dojo-props="design:'headline',gutters:false" 
         style="width: 100%; height: 100%; margin: 0;">
      <div id="map" 
           data-dojo-type="dijit.layout.ContentPane" 
           data-dojo-props="region:'center'"> 
      </div>
    </div>
  </body>
</html>
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
Thanks Derek.  That fixed it.  Didn't realize there were all those empty spaces since you don't see them when you bring the layer up in ArcMap.
0 Kudos