Changing definition expression in 4.x with MapImageLayer

1124
5
02-20-2018 01:37 PM
LoriEmerson_McCormack
Occasional Contributor

Changing definition expressions in 4.x takes a long time to see results in the map, and the results are inconsistent.

The map service is set up to do inspections, and when an inspection is completed, the symbol color changes color.  If there is no inspection (AKA No Maintenance Record), the symbol is red (value of NULL).  I have a checkbox on the map that lets the user see only those symbols that still need to be inspected.

The GIS layers in the map service are joined to a view of the inspection table.

Question:  After I change the definition expression, do I need to refresh my map somehow?  Does my click event code look reasonable?  

// definition expressions use table names and attribute names because joined to a view

var defExprCatchBasinNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'catch+basin' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprCatchBasinAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'catch+basin' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprCatchBasinPipeNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'catch+pipe' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprCatchBasinPipeAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'catch+pipe' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprDrywellNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'drywell' AND ( PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT <> '.TRUE.' AND PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT <> 'T') AND ( PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprDrywellAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'drywell' AND ( PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT <> '.TRUE.' AND PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT <> 'T') AND ( PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprDrywellPipeNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'dry+pipe' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprDrywellPipeAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'dry+pipe' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprPretreatDrywellNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'drywell' AND ( PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT = '.TRUE.' OR PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT = 'T') AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprPretreatDrywellAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'drywell' AND ( PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT = '.TRUE.' OR PUBLISHED.STORMWATER.Storm_Struc_points.PRETREAT = 'T') AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprSandFilterNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'Sand Filter' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprSandFilterAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'Sand Filter' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";
var defExprSwaleNoMaint = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'swale' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL) AND ENGINEERSdev.dbo.vwSWUFacilityMaintRecordExists.SymbolColor IS NULL";
var defExprSwaleAll = "PUBLISHED.STORMWATER.Storm_Struc_points.STRUCTURE = 'swale' AND (PUBLISHED.STORMWATER.Storm_Struc_points.Non_County <> 'yes' OR PUBLISHED.STORMWATER.Storm_Struc_points.Non_County IS NULL)";

// index values of the layers in the map service

var indexCatchBasin = 7;
var indexCatchBasinPipe = 8;
var indexCulvertPipe = 9;
var indexDetentionPond = 10;
var indexDrywellsGroup = 11;
var indexDrywell = 12;
var indexDrywellPipe = 13;
var indexPretreatDrywell = 14;
var indexMaintJunction = 15;
var indexSandFilter = 17;
var indexSwale = 18;
var indexMunicipalBdry = 19;
var indexParcels = 20;
var indexMaintDist = 21;
var indexMunicipalShaded = 22;
var indexSWUDrainageNetwork = 24;
var indexSWUServiceArea = 25;

var initialExtent = new Extent(
   -117.83, 47.23,
   -117.03, 48.055,
   SpatialReference({ wkid: 4326 })
);

var map = new Map({
   basemap: "topo"
});

var view = new MapView({
   container: "viewDiv",
   map: map,
   extent: initialExtent
});

view.constraints = {
   minScale: 2000000, // User cannot zoom out beyond a scale of 1:2,000,000
   maxScale: 0, // User can overzoom tiles
   rotationEnabled: false // Disables map rotation
};

/********************
* Add home button
********************/
var homeButton = new Home({
view: view
});

// Add the home widget to the top left corner of the view
view.ui.add(homeButton, "top-left");

/********************
* Add layer
********************/

var lyrMaintPoints = new MapImageLayer({
url: urlMaintPts,
sublayers: [
{
id: 25, // indexSWUServiceArea
visible: true
}, {
id: 24, // indexSWUDrainageNetwork
visible: true
}, {
id: 23,
visible: false
}, {
id: 22, // indexMunicipalShaded
visible: false
}, {
id: 21, // indexMaintDist
visible: false
}, {
id: 20, // indexParcels
visible: true
}, {
id: 19, // indexMunicipalBdry
visible: true
}, {
id: 18, // indexSwale
visible: true
}, {
id: 17, // indexSandFilter
visible: true
}, {
id: 16,
visible: false
}, {
id: 15, // indexMaintJunction
visible: false
}, {
id: 14, // indexPretreatDrywell
visible: true
}, {
id: 13, // indexDrywellPipe
visible: true
}, {
id: 12, // indexDrywell
visible: true
}, {
id: 11, // indexDrywellsGroup
visible: false
}, {
id: 10, // indexDetentionPond
visible: false
}, {
id: 9, // indexCulvertPipe
visible: true
}, {
id: 8, // indexCatchBasinPipe
visible: true
}, {
id: 7, // indexCatchBasin
visible: true
}, {
id: 6,
visible: false
}, {
id: 5,
visible: false
}, {
id: 4,
visible: false
}, {
id: 3,
visible: false
}, {
id: 2,
visible: false
}, {
id: 1,
visible: false
}, {
id: 0,
visible: false
}]
});

map.add(lyrMaintPoints);

   

// click event on the map checkbox to show features where No Maintenance Record exists
$('#checkbox-NoMaintRecord').on('click', function (event) {
   if ($(this).is(":checked")) {
      $(this).parent().addClass('filter-layer');
      var sublayerCB = lyrMaintPoints.findSublayerById(indexCatchBasin);
      sublayerCB.definitionExpression = defExprCatchBasinNoMaint;
      var sublayerCBP = lyrMaintPoints.findSublayerById(indexCatchBasinPipe);
      sublayerCBP.definitionExpression = defExprCatchBasinPipeNoMaint;
      var sublayerDW = lyrMaintPoints.findSublayerById(indexDrywell);
      sublayerDW.definitionExpression = defExprDrywellNoMaint;
      var sublayerDWP = lyrMaintPoints.findSublayerById(indexDrywellPipe);
      sublayerDWP.definitionExpression = defExprDrywellPipeNoMaint;
      var sublayerPrDW = lyrMaintPoints.findSublayerById(indexPretreatDrywell);
      sublayerPrDW.definitionExpression = defExprPretreatDrywellNoMaint;
      var sublayerSF = lyrMaintPoints.findSublayerById(indexSandFilter);
      sublayerSF.definitionExpression = defExprSandFilterNoMaint;
      var sublayerSW = lyrMaintPoints.findSublayerById(indexSwale);
      sublayerSW.definitionExpression = defExprSwaleNoMaint;

      identifyLayerDefinitions[indexCatchBasin] = defExprCatchBasinNoMaint;
      identifyLayerDefinitions[indexCatchBasinPipe] = defExprCatchBasinPipeNoMaint;
      identifyLayerDefinitions[indexDrywell] = defExprDrywellNoMaint;
      identifyLayerDefinitions[indexDrywellPipe] = defExprDrywellPipeNoMaint;
      identifyLayerDefinitions[indexPretreatDrywell] = defExprPretreatDrywellNoMaint;
      identifyLayerDefinitions[indexSandFilter] = defExprSandFilterNoMaint;
      identifyLayerDefinitions[indexSwale] = defExprSwaleNoMaint;
      identifyParams.layerDefinitions = identifyLayerDefinitions;
}
else {
      $(this).parent().removeClass('filter-layer');
      var sublayerCB = lyrMaintPoints.findSublayerById(indexCatchBasin);
      sublayerCB.definitionExpression = defExprCatchBasinAll;
      var sublayerCBP = lyrMaintPoints.findSublayerById(indexCatchBasinPipe);
      sublayerCBP.definitionExpression = defExprCatchBasinPipeAll;
      var sublayerDW = lyrMaintPoints.findSublayerById(indexDrywell);
      sublayerDW.definitionExpression = defExprDrywellAll;
      var sublayerDWP = lyrMaintPoints.findSublayerById(indexDrywellPipe);
      sublayerDWP.definitionExpression = defExprDrywellPipeAll;
      var sublayerPrDW = lyrMaintPoints.findSublayerById(indexPretreatDrywell);
      sublayerPrDW.definitionExpression = defExprPretreatDrywellAll;
      var sublayerSF = lyrMaintPoints.findSublayerById(indexSandFilter);
      sublayerSF.definitionExpression = defExprSandFilterAll;
      var sublayerSW = lyrMaintPoints.findSublayerById(indexSwale);
      sublayerSW.definitionExpression = defExprSwaleAll;

      identifyLayerDefinitions[indexCatchBasin] = defExprCatchBasinAll;
      identifyLayerDefinitions[indexCatchBasinPipe] = defExprCatchBasinPipeAll;
      identifyLayerDefinitions[indexDrywell] = defExprDrywellAll;
      identifyLayerDefinitions[indexDrywellPipe] = defExprDrywellPipeAll;
      identifyLayerDefinitions[indexPretreatDrywell] = defExprPretreatDrywellAll;
      identifyLayerDefinitions[indexSandFilter] = defExprSandFilterAll;
      identifyLayerDefinitions[indexSwale] = defExprSwaleAll;
      identifyParams.layerDefinitions = identifyLayerDefinitions;
   } // end else stmt
});

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Lori,

  Try adding lyrMaintPoints.refresh();

0 Kudos
LoriEmerson_McCormack
Occasional Contributor

Thanks for the suggestion.  I tried it and even tried setting a timeout.

setTimeout(refreshFunction, 5000);

function refreshFunction() {
lyrMaintPoints.refresh();
}

The code works fine if I only reset one definition query at a time.  If I try resetting the definitionExpression on multiple layers, then the screen won't refresh.  Even if I zoom in, the symbols won't resolve to smaller icons.  The identifyParams.layerDefinitions changes work fine.  It's the layer definitionExpression that seems to be the problem.

The response is extremely slow even when I try toggling the visibility of layers.  I used a refresh there as well, and it takes another ten seconds after the refresh before I see results on the screen.

If I try setting the definitionExpression and then toggle layer visibility, the layer visibility doesn't work (because the symbols are frozen from the definitionExpression). 

To verify that my definitionExpressions were valid, I tried them all in ArcMap.  I also tried them one by on in my code.

The one thing to note about my GIS layers is that some of them are the same feature class but with different definition expressions (e.g., Drywells).  Could that be the issue?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lori,

   I would suggest commenting out all but one of the def expressions and test and then adding one more each time to try and narrow down the issue.

0 Kudos
LoriEmerson_McCormack
Occasional Contributor

I commented out all of the def expressions except one, and it worked.  I tried it for each def expression and they all worked by themselves.  I tried with two def expressions, and it worked.  I tried it for three def expressions (it worked for some combinations of def expression but not others).

I also tried setting the def expressions using a loop so only one sublayer definition expression was changed at a time.

I think there is something wrong with setting sublayer definition expressions using 4.6.  Perhaps the length of the definition expression strings is exceeded?

Setting the identifyParams.layerDefinitions works fine.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lori,

   So based on what you did, you could not narrow it down to a particular expression then. Sounds like a call to tech support is in order then.

0 Kudos