-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathsample-multiple.html
114 lines (95 loc) · 3.1 KB
/
sample-multiple.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Esri Leaflet Geocoder</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1" />
<!-- Load Leaflet from their CDN -->
<link rel="stylesheet" href="../node_modules/leaflet/dist/leaflet.css" />
<script src="../node_modules/leaflet/dist/leaflet-src.js"></script>
<script src="../node_modules/esri-leaflet/dist/esri-leaflet-debug.js"></script>
<link rel="stylesheet" href="../dist/esri-leaflet-geocoder.css" />
<script src="../dist/esri-leaflet-geocoder-debug.js"></script>
<!-- Make the map fill the entire page -->
<style>
#map {
position: fixed;
top: 100px;
bottom: 0;
left: 0;
right: 0;
height: 375px;
width: 80%;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map("map").setView([37.74, -121.62], 9);
// var tiles = L.esri.basemapLayer('Topographic').addTo(map);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var getProviders = function () {
return [
L.esri.Geocoding.arcgisOnlineProvider({
// countries: ['USA', 'GUM', 'VIR', 'PRI'],
// categories: ['Address', 'Postal', 'Populated Place', ],
// maxResults: 3
apikey: 'YOUR_API_KEY'
}),
L.esri.Geocoding.mapServiceProvider({
label: "States and Counties",
url:
"http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
layers: [2, 3],
searchFields: ["NAME", "STATE_NAME"]
})
];
}
// this is the geocoder control and behavior based on the original testing page "sample.html"
var searchControl = L.esri.Geocoding.geosearch({
providers: getProviders()
}).addTo(map);
var results = L.layerGroup().addTo(map);
searchControl.on("results", function (data) {
results.clearLayers();
for (var i = data.results.length - 1; i >= 0; i--) {
results.addLayer(L.marker(data.results[i].latlng));
}
});
// add additional geocoder controls throughout the map control corners for testing
L.esri.Geocoding.geosearch({
position: "topleft",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "topright",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "topright",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "bottomleft",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "bottomleft",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "bottomright",
providers: getProviders()
}).addTo(map);
L.esri.Geocoding.geosearch({
position: "bottomright",
providers: getProviders()
}).addTo(map);
</script>
</body>
</html>