In this lab you will use code to style a popup.
Click create_starter_map/index.html and copy the contents to a new jsbin.com.
In JSBin
> HTML
, update the require
statement and function definition:
require(["esri/map",
"esri/layers/FeatureLayer",
"esri/dijit/PopupTemplate",
"dojo/domReady!"],
function(Map, FeatureLayer, PopupTemplate) {
...
function(Map, FeatureLayer, PopupTemplate) {
map = new Map("mapDiv", {
center: [-122.68, 45.52],
zoom: 10,
basemap: "dark-gray"
});
var popupTemplate = new PopupTemplate({
title: "Neighborhoods",
// Fields
fieldInfos: [
{ fieldName: "TOTPOP_CY", label: "Total Population", visible: true, format: { places: 0 } },
{ fieldName: "AVGHINC_CY", label: "Average Income", visible: true, format: { places: 0 } },
{ fieldName: "MEDAGE_CY", label: "Median Age", visible: true, format: { places: 0 } },
{ fieldName: "AREA", visible: true, format: { places: 2 } }
],
// Charts
mediaInfos: [
{
title: "Demographics",
type: "piechart",
value: {
fields: [
"TOTPOP_CY",
"AVGHINC_CY",
]
}
}
]
});
var featureLayer = new FeatureLayer("http://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/PDX_Neighborhoods_Enriched/FeatureServer/0",
{
outFields: ["*"],
infoTemplate: popupTemplate
}
);
map.addLayer(featureLayer);
Output
panel shows styled popups when you click on the neighborhoods.Your app should look something like this:
Bonus