-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
200 lines (165 loc) · 6.68 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<html>
<head>
<title>LFUCG Snow Removal</title>
<meta charset=utf-8 />
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet-src.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/esri-leaflet@2.0.4"></script>
<style>
body { margin:0; padding:0; }
#map { position: absolute; top:0; bottom:0; right:0; left:0; }
.legend {
background-color: white;
padding: 10px;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
.legend-items {
display: inline; /l* click to close */
}
.legend-item {
padding-top: 10px;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- search -->
<link rel="stylesheet" href="https://unpkg.com/esri-leaflet-geocoder@2.3.2/dist/esri-leaflet-geocoder.css">
<script src="https://unpkg.com/esri-leaflet-geocoder@2.3.2"></script>
<!-- home button -->
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/leaflet-easybutton@2.0.0/src/easy-button.css">
<script src="https://unpkg.com/leaflet-easybutton@2.0.0/src/easy-button.js"></script>
<!-- legend and popup -->
<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
<script>
//create variable for bounding coordinates of fayette county envelope
var southWest = L.latLng(37.844628, -84.659246),
northEast = L.latLng(38.211523, -84.28272),
bounds = L.latLngBounds(southWest, northEast);
//set up map and add data
var map = new L.map("map",{
zoomControl: false,
//scrollWheelZoom: false
});
map.fitBounds(bounds);
L.esri.basemapLayer("Gray").addTo(map);
var localGrayBase = L.esri.tiledMapLayer({
url: 'https://maps.lexingtonky.gov/lfucggis/rest/services/basemap_grayscale/MapServer',
}).addTo(map)
var snowPriorityMs = L.esri.tiledMapLayer({
url: 'https://maps.lexingtonky.gov/lfucggis/rest/services/snowremoval/MapServer',
opacity: 0.7
})
.addTo(map);
var overlayMs = L.esri.dynamicMapLayer({
url: "https://maps.lexingtonky.gov/lfucggis/rest/services/overlay/MapServer",
opacity: 0.5
}).addTo(map);
var labelsMs = L.esri.tiledMapLayer({
url: "https://maps.lexingtonky.gov/lfucggis/rest/services/labels/MapServer",
opacity: 0.9
}).addTo(map);
//create search control with results from county envelope
var searchControl = L.esri.Geocoding.geosearch({
position: 'topright',
expanded: true,
searchBounds: bounds,
providers: [
L.esri.Geocoding.arcgisOnlineProvider({
categories: ['Address', 'Populated Place','POI' ]
})
]
}).addTo(map);
// create snow removal popup
var results = L.layerGroup().addTo(map);
map.on('click', function (e) {
displayStatus(e.latlng);
});
var displaySearchResults = function(data, latlng) {
displayStatus(data.results[0].latlng);
}
var displayStatus = function(latlng) {
results.clearLayers();
snowPriorityMs.identify()
.returnGeometry(false)
//.tolerance(0)
.on(map)
.at(latlng)
.run(function(error, featureCollection) {
var snow, roadname;
$.each(featureCollection.features, function(index, feature) {
if (feature.layerId === 7) { snow = feature.properties['SNOW'], roadname = feature.properties['ANNO']; }
});
showSnowPopup(map, latlng, snow, roadname);
});
}
var showSnowPopup = function(map, addressLatLng, snow, roadname) {
if (!snow || snow === 'Null') {
return false;
} else {
var snowLanguage = '<h3>' + roadname + '<br>' + snow + '</h3>';
snow = snowLanguage
}
var popup = L.popup({
closeButton: true,
})
.setLatLng(addressLatLng)
.setContent(snow)
.openOn(map);
map.setView(addressLatLng);
setTimeout(function() {
map.panBy(new L.Point(0, -100));
}, 500);
};
var legendItem = function(key, bgcolor, brstyle, brcolor) {
return '<div class="legend-item"><i style="background: ' + bgcolor + '; border-style: ' + brstyle + '; border-color: ' + brcolor + ';"></i> ' + key + '</div>';
}
var addLegend = function(map) {
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'legend');
div.innerHTML += '<div class="legend-toggle-container"><a href="#" class="legend-toggle">Legend</a></div>';
var items = L.DomUtil.create('div', 'legend-items');
//items.innerHTML += legendItem(key, background color, border style, border color);
items.innerHTML += legendItem('Rank 1', '#9F5C5B', 'none', 'none');
items.innerHTML += legendItem('Rank 2', '#2F75B5', 'none', 'none');
items.innerHTML += legendItem('Rank 3', '#9EBE83', 'none', 'none');
items.innerHTML += legendItem('Rank 4', '#E2BC3D', 'none', 'none');
items.innerHTML += legendItem('Parks Snow Removal', '#E2BC3D', 'dashed', 'black');
items.innerHTML += legendItem('Rural Snow Removal', 'none', 'dashed', '#E2BC3D');
items.innerHTML += legendItem('State Snow Removal', '#979797', 'none', 'none');
$(div).append(items);
return div;
};
legend.addTo(map);
$('.legend-toggle').click(function(e) {
e.preventDefault();
$('.legend-items').toggle();
});
}
addLegend(map);
// make a bar with navigation buttons
var zoomBar = L.easyBar([
L.easyButton( '<big>+</big>', function(control, map){map.setZoom(map.getZoom()+1);}),
L.easyButton( 'fa-home fa-lg', function(control, map){map.fitBounds(bounds);}),
L.easyButton( '<big>-</big>', function(control, map){map.setZoom(map.getZoom()-1);}),
]);
zoomBar.addTo(map);
</script>
</body>
</html>