AnsweredAssumed Answered

Changing definition expression in 4.x with MapImageLayer

Question asked by lorieme on Feb 20, 2018
Latest reply on Feb 23, 2018 by rscheitlin

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

Outcomes