2 Replies Latest reply on Apr 26, 2012 6:17 AM by betsyjsg

    layerDefinitions problem

      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});

      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.
        • Re: layerDefinitions problem
          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"

          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=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=vdate+like+%27%252012%2F04%2F26%25%27&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=&f=html

          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">
              <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"/>
              <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" />
                html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
                #map{ margin: 0; padding: 0; }
              <script>var dojoConfig = { parseOnLoad: true };</script>
              <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>
                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");
                  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
                  dojo.connect(map, "onLoad", function() { 
                    dojo.connect(dijit.byId("map"), "resize", map, map.resize);
            <body class="tundra">
              <div data-dojo-type="dijit.layout.BorderContainer" 
                   style="width: 100%; height: 100%; margin: 0;">
                <div id="map" 
          • Re: layerDefinitions problem
            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.