-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap-geojson.html
More file actions
244 lines (217 loc) · 9.04 KB
/
map-geojson.html
File metadata and controls
244 lines (217 loc) · 9.04 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>Leaflet Examples</title>
<!-- Bootstrap core CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin="" />
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark" aria-label="Third navbar example">
<div class="container-fluid">
<a href="#" class="navbar-brand d-flex align-items-center">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true" class="me-2" viewBox="0 0 24 24"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>
<strong>Leaflet Examples</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample03">
<ul class="navbar-nav me-auto mb-2 mb-sm-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown03" data-bs-toggle="dropdown" aria-expanded="false">Examples</a>
<ul class="dropdown-menu" aria-labelledby="dropdown03">
<li><a class="dropdown-item" href="map-simple.html">Simple Example</a></li>
<li><a class="dropdown-item" href="map-satellite.html">Satellite Layer</a></li>
<li><a class="dropdown-item" href="map-popup.html">Marker Popup</a></li>
<li><a class="dropdown-item" href="map-draggable.html">Draggable Marker</a></li>
<li><a class="dropdown-item" href="map-image.html">Overlay Image</a></li>
<li><a class="dropdown-item" href="map-geojson.html">GeoJSON Area</a></li>
<li><a class="dropdown-item" href="map-cluster.html">Clusters</a></li>
<li><a class="dropdown-item" href="map-heatmap.html">Heatmap</a></li>
<li><a class="dropdown-item" href="map-vector.html">Vector Layer</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<main>
<section class="py-5 container">
<h1 class="fw-light">Add GeoJSON Outline</h1>
<div class="row py-lg-5">
<style>
#map { height: 380px; }
</style>
<div id="map"></div>
</div>
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8">
<h3>Try It Out</h3>
<p>Zoom in to the marker and notice the polygon shape defined</p>
<h3>Code</h3>
<pre>
var geojsonFeature = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-6.337939202785492,
54.17750946223595
],
[
-6.337791681289673,
54.17731401762
],
[
-6.337337046861649,
54.17743489512197
],
[
-6.337392032146454,
54.177507107487024
],
[
-6.337371915578842,
54.17751652648189
],
[
-6.337402760982513,
54.17755734210142
],
[
-6.337433606386185,
54.177550277862466
],
[
-6.337492614984512,
54.1776334788225
],
[
-6.337939202785492,
54.17750946223595
]
]
]
}
}
]
}
L.geoJSON(geojsonFeature).addTo(map);
</pre>
<p class="lead">View the source of this page to see fully how the map is created. In this example notice:</p>
<ul>
<li>We create a geojsonFeature variable</li>
<li>We have coordinates for each of 9 points defined in geojsonFeature</li>
<li>We use the geoJSON function with the geojsonFeature variable to add the shape to the map</li>
</ul>
<p>
<a href="map-cluster.html" class="btn btn-primary my-2">Next Example</a>
<a href="map-image.html" class="btn btn-default">Previous</a>
</p>
</div>
</div>
</section>
</main>
<footer class="text-muted py-5">
<div class="container">
<p class="float-end mb-1">
<a href="#">Back to top</a>
</p>
<p class="mb-1"></p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1/dist/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
<script>
var mapbox_url = 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoiam9ubnltY2N1bGxhZ2giLCJhIjoiY2xsYzdveWh4MGhwcjN0cXV5Z3BwMXA1dCJ9.QoEHzPNq9DtTRrdtXfOdrw';
var mapbox_attribution = '© Mapbox © OpenStreetMap Contributors';
var esri_url ='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
var esri_attribution = '© Esri © OpenStreetMap Contributors';
var lyr_satellite = L.tileLayer(esri_url, {id: 'MapID', maxZoom: 20, tileSize: 512, zoomOffset: -1, attribution: esri_attribution});
var lyr_streets = L.tileLayer(mapbox_url, {id: 'mapbox/streets-v11', maxZoom: 28, tileSize: 512, zoomOffset: -1, attribution: mapbox_attribution});
var marker = L.marker([54.17747885048963, -6.337641477584839], {draggable:'false'}).bindPopup('<b>Newry Town Hall</b>');
var lg_markers = L.layerGroup([marker]);
var map = L.map('map', {
center: [54.17747885048963, -6.337641477584839],
zoom: 18,
layers: [lyr_satellite, lyr_streets, lg_markers]
});
var baseMaps = {
"Streets": lyr_streets,
"Satellite": lyr_satellite
};
var overlayMaps = {
"Markers": lg_markers,
};
L.control.layers(baseMaps, overlayMaps).addTo(map);
var geojsonFeature = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-6.337939202785492,
54.17750946223595
],
[
-6.337791681289673,
54.17731401762
],
[
-6.337337046861649,
54.17743489512197
],
[
-6.337392032146454,
54.177507107487024
],
[
-6.337371915578842,
54.17751652648189
],
[
-6.337402760982513,
54.17755734210142
],
[
-6.337433606386185,
54.177550277862466
],
[
-6.337492614984512,
54.1776334788225
],
[
-6.337939202785492,
54.17750946223595
]
]
]
}
}
]
}
L.geoJSON(geojsonFeature).addTo(map);
</script>
</body>
</html>