Select to view content in your preferred language

DefinitionExpression with MapImageLayer subLayer

2273
2
Jump to solution
01-10-2017 12:36 PM
RandyBonds_Jr_
Regular Contributor

I'm having trouble with a complex definitionExpression in a sublayer of my MapImageLayer (JSAPI 4.2). When I do the same query from the REST service directory, it works perfectly. 

More or less, I want a date range and either of two other field values to be 1. What happens is that the points are all shown, but only the ones that match the query have a popup... it's really neat.

Here's my code

        var layer = new MapImageLayer({
          url: "https://gis.yakimawa.gov/arcgis101/rest/services/CouncilDistricts/ElementarySchoolSidewalksAnalysis/...",
          sublayers: [
          {
            id: 4,
            visible: true,
            definitionExpression: "Type = 1",
            popupTemplate: template
          }, {
            id: 3,
            visible: true
          }, {
            id: 2,
            visible: true,
            popupTemplate: streetTemplate
          },{
            id: 1,
            visible: true,
            popupTemplate: streetTemplate
          }, {
            id: 0,
            visible: false,
            definitionExpression: "(Collision_Date <= date '2016-12-31 23:59:59' AND Collision_Date >= date '2014-01-01 00:00:00') AND (Number_of_Pedestrians_Involved > 0 OR Number_of_Pedalcyclists_Involve > 0)",
            popupTemplate: collisionTemplate
          }]
        });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
KristianEkenes
Esri Regular Contributor

Hi Randy,

This is a bug we weren't aware of. So thanks for asking about it.  This is actually already fixed for our next release. In the meantime you can use the following code to patch your app.

// TODO remove when upgrading to 4.3
function patchMapImageLayer(layer) {
  var original = layer.createExportImageParameters;
  layer.createExportImageParameters = function(options) {
    var params = original.call(layer, options);
    var layerDefs = params.layerDefs.split(";").reduce(function(result, layerDef) {
      var firstColon = layerDef.indexOf(":");
      var layerId = parseInt(layerDef.slice(0, firstColon));
      result[layerId] = layerDef.slice(firstColon + 1);
      return result
    }, {});
    params.layerDefs = JSON.stringify(layerDefs);
    return params;
  };
}
        
patchMapImageLayer(layer);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here's a small sample app using your layer, which shows it working as expected: JS Bin - Collaborative JavaScript Debugging 

Be sure to remove this code once you upgrade to 4.3 since this will break the app. Hopefully that helps!

View solution in original post

2 Replies
KristianEkenes
Esri Regular Contributor

Hi Randy,

This is a bug we weren't aware of. So thanks for asking about it.  This is actually already fixed for our next release. In the meantime you can use the following code to patch your app.

// TODO remove when upgrading to 4.3
function patchMapImageLayer(layer) {
  var original = layer.createExportImageParameters;
  layer.createExportImageParameters = function(options) {
    var params = original.call(layer, options);
    var layerDefs = params.layerDefs.split(";").reduce(function(result, layerDef) {
      var firstColon = layerDef.indexOf(":");
      var layerId = parseInt(layerDef.slice(0, firstColon));
      result[layerId] = layerDef.slice(firstColon + 1);
      return result
    }, {});
    params.layerDefs = JSON.stringify(layerDefs);
    return params;
  };
}
        
patchMapImageLayer(layer);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here's a small sample app using your layer, which shows it working as expected: JS Bin - Collaborative JavaScript Debugging 

Be sure to remove this code once you upgrade to 4.3 since this will break the app. Hopefully that helps!

RandyBonds_Jr_
Regular Contributor

Awesome! Thank a ton!

0 Kudos