Last active
April 26, 2019 20:24
-
-
Save nommuna2/e74ee1fd95212e3aa19805e8895ff271 to your computer and use it in GitHub Desktop.
(ArcGIS API for JavaScript) Sample of adding popupTemplate to a mapservice layer in 3.x.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(["esri/map", | |
"esri/layers/ArcGISDynamicMapServiceLayer", | |
"esri/tasks/query", | |
"esri/tasks/QueryTask", | |
"esri/dijit/Popup", | |
"dojo/dom-construct", | |
"esri/dijit/PopupTemplate", | |
"dojo/domReady!" | |
], function (Map, ArcGISDynamicMapServiceLayer,Query, QueryTask, Popup, domCon, PopupTemplate) { | |
var map = new Map("map", { | |
center: [-118, 34.5], | |
zoom: 5, | |
basemap: "topo" | |
}); | |
var layer = new ArcGISDynamicMapServiceLayer('http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer'); | |
map.addLayer(layer); | |
var myQuery = new Query(); | |
myQuery.where = "1=1"; | |
myQuery.outFields = ['*']; | |
map.on("click", function(e){ | |
console.log(e); | |
myQuery.geometry = e.mapPoint; | |
var queryTask = new QueryTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"); | |
queryTask.execute(myQuery, function(result){ | |
console.log(result); | |
var popupTemplate = new PopupTemplate({ | |
title: "My popup", | |
fieldInfos: [ | |
{ fieldName: "state_name", visible: true, label: "State Name: " }, | |
{ fieldName: "pop2000", visible: true, label: "Population: " } | |
] | |
}); | |
result.features.forEach(function(f) { | |
f.setInfoTemplate(popupTemplate); | |
}); | |
map.infoWindow.setFeatures(result.features); | |
map.infoWindow.show(e.screenPoint, map.getInfoWindowAnchor(e.screenPoint)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment