Skip to content

This sample shows how to add an instance of MapImageLayer to a Map in a Scene and update thedefinitionExpression of a sublayer.

// Create a MapImageLayer instance pointing to a Map Service
// containing data about US Cities, Counties, States and Highways.
// Define sublayers with visibility for each layer in Map Service.
// Set an initial definition expression on the cities sublayer.
const layer = new MapImageLayer({
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
sublayers: [
{
id: 3,
visible: false,
},
{
id: 2,
visible: true,
},
{
id: 1,
visible: true,
},
{
id: 0,
visible: true,
definitionExpression: "pop2000 > 100000",
},
],
});
// Add event listener for when the slider thumb is released
// and set the definition expression on the cities sublayer.
slider.addEventListener("calciteSliderChange", () => {
selectedPopulation = Number(slider.value);
citiesSublayer.definitionExpression = `pop2000 > ${selectedPopulation}`;
});
// Add event listener for when the slider input changes during sliding
// and update the text showing the current population value.
slider.addEventListener("calciteSliderInput", () => {
sliderCount.textContent = slider.value;
});