-
Notifications
You must be signed in to change notification settings - Fork 23
/
dcopendata_ward_leaflet.html
198 lines (179 loc) · 6.82 KB
/
dcopendata_ward_leaflet.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
<!DOCTYPE html>
<html>
<head>
<!-- Description: This sample demonstrates how to use clickable polygons to view information about the selected polygon -->
<!-- Attribution:
Leaflet Tutorials, Url: https://leafletjs.com/examples.html
Styling inspired by Esri Story Map: https://storymaps.esri.com/stories/2016/top-stories/
-->
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Wards @ Washington, DC</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="https://dc.gov/sites/default/files/favicon_0.ico">
<style>
body {
margin: 0;
padding: 0;
font-family: "open_sanssemi", sans-serif;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
a {
color: #fff;
font-family: 'open_sansregular', sans-serif;
}
/*styling for title bar and about pop over */
#title {
color: #FFF;
font-family: "open_sanssemibold", sans-serif;
padding: 3 0 0 4;
font-size: 24px;
line-height: 30px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header {
position: relative;
padding: 15px 30px 25px 30px;
margin: auto;
z-index: 500;
background-color: rgb(12, 12, 12);
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, .75);
opacity: 0.8;
}
#about {
padding: 10px 20px 20px 20px;
z-index: 4000;
position: absolute;
background-color: #505050;
color: white;
width: 700px;
left: 50%;
margin-left: -300px;
height: calc(100% - 200px);
top: 100px;
display: none;
overflow: hidden;
opacity: 0.95;
}
#dismiss-about {
cursor: pointer;
font-size: 30px;
float: right;
margin-bottom: 10px;
}
#inner {
width: 100%;
height: calc(100% - 60px);
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
</style>
</head>
<body>
<div id="map"></div>
<div class='header'>
<div id="title">Wards @ Washington, DC</div>
<div style="float:right;">
<a style="color:rgb(206,206,206);font-size:14px; margin-right:10px;"
href="https://github.com/DCgov/opendatadc-starterkit" target="_blank">This on Github</a>
<a style="color:rgb(206,206,206);font-size:14px;" href="javascript:void(0)"
onclick="openAbout()">About This Map</a>
</div>
</div>
<div id="about">
<a id="dismiss-about" onclick="closeAbout()">×</a>
<div id="inner">
<p style="font-size: 1.4em; text-transform: uppercase; text-align: center">About this map
</p>
<p style="font-size:1.2em;">
This sample demonstrates how to load polygons from DC Open Data to overlay a map</p>
<p><strong>Instructions</strong>
<br/> Click a ward on the map to display info</p>
<p><strong>Built with...</strong>
<br/> <a href="https://leafletjs.com/">Leaflet</a>, <a href="https://jquery.com/">jQuery</a></p>
<p><strong>Download Ward 2012 Data in GeoJSON</strong>
<br/><a href="https://opendata.arcgis.com/datasets/0ef47379cbae44e88267c01eaec2ff6e_31.geojson">https://opendata.arcgis.com/datasets/0ef47379cbae44e88267c01eaec2ff6e_31.geojson</a>
</p>
<p><strong>View Ward 2012 Data on DC Open Data</strong>
<br/><a href="http://opendata.dc.gov/datasets/ward-2012" target="_blank">https://opendata.arcgis.com/datasets/0ef47379cbae44e88267c01eaec2ff6e_31</a>
</p>
<p><strong>DC Open Data</strong>
<br/><a href="http://opendata.dc.gov" target="_blank">http://opendata.dc.gov</a></p>
<p><strong>Github Repository</strong>
<br/><a href="https://github.com/DCgov/opendatadc-starterkit" target="_blank">https://github.com/DCgov/opendatadc-starterkit</a>
</p>
<div id="logos" style="text-align: center">
<img src="https://moca.dc.gov/sites/default/files/styles/callout_interior_graphic/public/dc/sites/ocaf/agency_content/images/We%20Are%20Washington.png"
title="We are DC logo">
</div>
</div>
</div>
<script>
//Data source from DC Open Data
var wardGeoJsonUrl = "https://opendata.arcgis.com/datasets/0ef47379cbae44e88267c01eaec2ff6e_31.geojson";
//Replace with your own token
var accessToken = "<<use your own mapbox token>>";
//sets map functions including turning off the standard zoom buttons
//and setting intial map focus point
var map = L.map('map', {
center: [38.8929, -77.0252],
zoom: 12,
zoomControl: false
});
//Create map and load basemap tile layer
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
id: 'mapbox/light-v10',
maxZoom: 17,
minZoom: 9,
accessToken: accessToken,
tileSize: 512,
zoomOffset: -1
}).addTo(map);
// Add our zoom control manually where we want to
var zoomControl = L.control.zoom({
position: 'bottomleft'
});
map.addControl(zoomControl);
//set style of ward layer
function style(feature) {
return {
weight: 2,
opacity: 0.8,
color: 'blue',
fillOpacity: 0.0
};
}
//Add DC Ward geojson to map
$.getJSON(wardGeoJsonUrl, function (data) {
var geojson = L.geoJson(data, {
style: style,
onEachFeature: function (feature, layer) {
//create popup for each ward polygon
layer.bindPopup(feature.properties.NAME + "<br>" + "Rep. " + feature.properties.REP_NAME + "," + "<br>" + feature.properties.REP_PHONE)
}
});
geojson.addTo(map);
});
//open About This panel
function openAbout() {
$("#about").show();
return false;
}
//close About This panel
function closeAbout() {
$("#about").hide();
return false;
}
</script>
</body>
</html>