Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nommuna2/f5cfb00419c4560bc2288fb14722903a to your computer and use it in GitHub Desktop.
Save nommuna2/f5cfb00419c4560bc2288fb14722903a to your computer and use it in GitHub Desktop.
(ArcGIS API for JavaScript 4.x) Sample of applying a definition expression on a feature layer using a drop-down.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Feature Layer</title>
<!-- <link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css"> -->
<link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/themes/dark-blue/main.css">
<link rel="stylesheet" href="indexstylesheet.css">
<script src="https://js.arcgis.com/4.10/"></script>
</head>
<body>
<div id="viewDiv"></div>
<div id="stateFilter">
<select id="state">
<option value="Default">Default</option>
<option value="California">California</option>
</select>
</div>
</body>
<script src="index.js"></script>
</html>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"dojo/domReady!"
],
function (Map, MapView, FeatureLayer) {
const filter = document.getElementById('state');
//Create a new map and set the basemap to Dark gray
var map = new Map({
basemap: "dark-gray",
//layers: [featureLayer]
});
//set a new view and set the properties of the view
var view = new MapView({
container: "viewDiv",
map: map,
center: [-86.049, 38.485],
zoom: 3
});
const layer = new FeatureLayer({
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"
});
map.add(layer);
layer.when(function(e){
//Apply a definition expression on event change
filter.addEventListener('change',function(e) {
layer.definitionExpression = "state_name = 'California'";
console.log(layer.definitionExpression);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment