+ Reply to Thread
Results 1 to 3 of 3

Thread: layerDefinitions problem

  1. #1
    Betsy Schenck-Gardner
    Join Date
    Jan 2010
    Posts
    65
    Points
    4
    Answers Provided
    0


    0

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

  2. #2
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default 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:
    Code:
    {
      "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/res...Fields=&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:
    Code:
    <!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>
    Last edited by swingley; 04-25-2012 at 04:09 PM. Reason: Provided example page using layer definitions
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  3. #3
    Betsy Schenck-Gardner
    Join Date
    Jan 2010
    Posts
    65
    Points
    4
    Answers Provided
    0


    0

    Default 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.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts