I am working on a web app using ArcGISDynamicMapServiceLayers, which use UniqueValueRenderers to draw points based on attributes. In many cases, the attribute value is 0, in which cases I would not want to display anything. If I do not assign some symbol to these values, the service draws the default symbol in those locations. I tried assigning a symbol with 0 opacity (transparent), but when I use an InfoWindow in the web app, a click will still [pick up these invisible symbols.
Is there a way that I can not draw these symbols at all if the attribute value is 0?
The user will choose which attribute to use for rendering the symbols. So that value may be 0 in some cases and nonzero in others.
Solved! Go to Solution.
Jason,
Your sample really helped. I did not know you where using the IdentifyTask and not just a simple InfoTemplate or PopupTemplate.
You need to apply the SQL definition to the IdentifyParamaters (lines 5 and 6).
// identify task
function executeIdentifyTask(event) {
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = map.extent;
identifyParams.layerDefinitions = [];
identifyParams.layerDefinitions[0] = attributeField + '>0';
Jason,
Why not set the layer definition expression to exclude those feature with the attribute value of 0?
Can I do that after loading the map services? In other words, can I set the layer definition expression dynamically in runtime?
Sure.
ok I will try that, thanks!
Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.
I will if and when I can get this to work..so far it is not; the definition is applied to the layer, but I can still click on the 'removed' points, and an infoWindow appears with 0 value. I will keep investigating.
update - I confirmed that the layer definitions are being applied; I added a filter to the 'all points' set, and only the points that met the condition are visibly shown. But, I can still click on points that are not visible but are part of the 'all' set, and an InfoWindow appears.
Jason,
If you are still getting the popup when clicking on a point that is filtered out using the defention query then are you adding the layer using a ArcGISDynamicMapServiceLayer or a FeatureLayer?
ArcGISDynamicMapServiceLayer, i mention 'dynamic map services' in my original question and tags...Ill edit for clarity.
Jason,
Strange. Here is a sample where all states but Kansas are remove using the definition query and when I click on any other state a popup is NOT displayed.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Create Map with Custom ArcGISDynamicMapServiceLayer Layer Definitions
</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.24/esri/css/esri.css" />
<style>
html,
body,
#mapDiv {
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script src="https://js.arcgis.com/3.24/"></script>
<script>
var map;
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ImageParameters",
"esri/dijit/PopupTemplate",
"dojo/domReady!"
],
function(Map, ArcGISDynamicMapServiceLayer, ImageParameters, PopupTemplate) {
map = new Map("mapDiv", {
basemap: "streets",
center: [-98.258, 38.236],
zoom: 7
});
//Use the ImageParameters to set map service layer definitions and map service visible layers before adding to the client map.
var imageParameters = new ImageParameters();
//ImageParameters.layerDefinitions takes an array. The index of the array corresponds to the layer id.
//In the sample below an element is added in the array at 3, 4, and 5 indexes.
//Those array elements correspond to the layer id within the remote ArcGISDynamicMapServiceLayer
var layerDefs = [];
layerDefs[5] = "STATE_NAME='Kansas'";
layerDefs[4] = "STATE_NAME='Kansas' and POP2007>25000";
layerDefs[3] = "STATE_NAME='Kansas' and POP2007>25000";
imageParameters.layerDefinitions = layerDefs;
//I want layers 5,4, and 3 to be visible
imageParameters.layerIds = [5, 4, 3];
imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;
imageParameters.transparent = true;
var template = new PopupTemplate({
title: "{STATE_NAME}",
fieldInfos: [
{
fieldName: "STATE_NAME",
label: "State",
visible: true
}, {
fieldName: "STATE_FIPS",
label: "Fips",
visible: true
}, {
fieldName: "SUB_REGION",
label: "Sub Region",
visible: true
}
]
});
var infoTemplates = {
5: {
infoTemplate: template,
layerURL: "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
}
}
//construct ArcGISDynamicMapServiceLayer with imageParameters from above
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer", {
imageParameters: imageParameters,
infoTemplates: infoTemplates
});
map.addLayer(dynamicMapServiceLayer);
});
</script>
</head>
<body>
<div id="mapDiv"></div>
</body>
</html>