forked from Esri/geodev-hackerlabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (71 loc) · 2.12 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Search with widget</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
<style>
html, body, #viewDiv {
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script src="https://js.arcgis.com/4.1/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/Search",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(Map, MapView, Search, FeatureLayer) {
var map = new Map({
basemap: "dark-gray"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-122.68, 45.52], // lon, lat
zoom: 10
});
// Create search widget
var searchWidget = new Search({
view: view,
allPlaceholder: "Neighborhood e.g. Downtown",
searchAllEnabled: true
});
var sources = [];
// Add the default world geocoder source
sources.push(searchWidget.defaultSource);
// Add the feature layer source to search
sources.push({
featureLayer: new FeatureLayer("http://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/PDX_Neighborhoods_Styled/FeatureServer/0"),
name: "Neighborhood Search",
searchFields: ["NAME"],
displayField: "NAME",
exactMatch: false,
outFields: ["NAME","AVGHINC_CY","MEDAGE_CY","TOTPOP_CY"],
placeholder: "Neighborhood e.g. Downtown",
// Create a PopupTemplate to format data
popupTemplate: {
title: "{NAME}",
content: "Median Age: {MEDAGE_CY}</br>Average Household Income: {AVGHINC_CY}</br> Population: {TOTPOP_CY}"
}
});
// Set the sources
searchWidget.sources = sources;
// Initialize the widget
searchWidget.startup();
// Add widget to the UI
view.ui.add(searchWidget, {
position: "top-right"
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>