-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
344 lines (297 loc) · 15.1 KB
/
index.php
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Leaflet Map Generator / by mikeott</title>
<link rel="stylesheet" href="css/style.css?v=1.0" type="text/css" media="all" />
</head>
<body>
<?php if(isset($_POST['submit'])) {
$map_theme = array(
'google' => 'https://mt0.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
'openstreetmap' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'openstreetmap_bw' => 'http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
'opentopmap' => 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
'hydda_base' => 'https://{s}.tile.openstreetmap.se/hydda/base/{z}/{x}/{y}.png',
'watercolor' => 'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png',
'esri' => 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
'positron' => 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}{r}.png',
'voyager' => 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager/{z}/{x}/{y}{r}.png',
'voyager_no_labels' => 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager_nolabels/{z}/{x}/{y}{r}.png',
'voyager_labels_under' => 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager_labels_under/{z}/{x}/{y}{r}.png'
);
$attribution = array(
'google' => 'Map data © ' . date('Y') . ' Google <a href="https://www.google.com/intl/en-GB_US/help/terms_maps.html" target="_blank" rel="noopener">Terms of use</a>',
'openstreetmap' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
'openstreetmap_bw' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
'opentopmap' => 'Map data: © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>',
'hydda_base' => 'Tiles courtesy of <a href="http://openstreetmap.se/" target="_blank">OpenStreetMap Sweden</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
'watercolor' => 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
'esri' => 'Tiles © Esri — Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, ' . date('Y'),
'positron' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
'voyager' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
'voyager_no_labels' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
'voyager_labels_under' => '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>'
);
$width = $_POST['width'];
$height = $_POST['height'];
$theme = isset($_POST['theme']);
if($theme) {
$theme = $map_theme[$_POST['theme']];
$attribution = $attribution[$_POST['theme']];
} else {
$theme = 'https://mt0.google.com/vt/lyrs=m&x={x}&y={y}&z={z}';
$attribution = 'Map data © ' . date('Y') . ' Google <a href="https://www.google.com/intl/en-GB_US/help/terms_maps.html" target="_blank" rel="noopener">Terms of use</a>';
}
$lat = $_POST['latitude'];
$lng = $_POST['longitude'];
$zoom_level = isset($_POST['zoom_level']);
if($zoom_level) {
$zoom_level = $_POST['zoom_level'];
} else {
$zoom_level = 14;
}
$full_screen = isset($_POST['full_screen']);
if($full_screen) {
$full_screen_css = "\r<!--/ Start Fullscreen Addon: https://github.com/brunob/leaflet.fullscreen /-->\r<style>.leaflet-control-fullscreen-button { background: #fff url('https://leaflet.github.io/Leaflet.fullscreen/dist/fullscreen.png'); background-position: 50% 2px !important; } .leaflet-fullscreen-on .leaflet-control-fullscreen-button { background-position: 50% -24px !important; }</style>";
$full_screen_js = '<script src="https://leaflet.github.io/Leaflet.fullscreen/dist/Leaflet.fullscreen.min.js"></script>';
$full_screen_init = "/* Full Screen: https://github.com/brunob/leaflet.fullscreen */\r";
$full_screen_init .= " fullscreenControl: true,\r";
$full_screen_init .= " fullscreenControlOptions: {\r";
$full_screen_init .= " position: 'bottomright'\r";
$full_screen_init .= "},";
} else {
$full_screen_css = '';
$full_screen_js = '';
$full_screen_init = '';
}
$scrollwheel = isset($_POST['scrollwheel']);
if ($scrollwheel) {
$scrollwheel = 'true';
} else {
$scrollwheel = 'false';
}
$satellite_view = isset($_POST['satellite_view']);
if($satellite_view) {
$satellite_view = "\r\r/* Satellite view */\r";
$satellite_view .= "var default_view = L.tileLayer('" . $theme . "')\r";
$satellite_view .= "satellite_view = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}')\r";
$satellite_view .= "var baseMaps = {\r";
$satellite_view .= " 'Default': default_view,\r";
$satellite_view .= " 'Satellite': satellite_view\r";
$satellite_view .= "};\r";
$satellite_view .= "var overlays = {\r";
$satellite_view .= "};\r";
$satellite_view .= "L.control.layers(baseMaps,overlays, {position: 'bottomleft'}).addTo(map);\r";
}
$popup = isset($_POST['popup']);
$popup_text = $_POST['popup_text'];
if($popup_text) {
$popup_text = $popup_text;
} else {
$popup_text = '';
}
if($popup) {
$popup = "\r\r/* Popup */\r";
$popup .= "L.marker([" . $lat . ", " . $lng . "])\r";
$popup .= ".addTo(map)\r";
$popup .= ".bindPopup('" . $popup_text . "')\r";
$popup .= ".openPopup();\r";
} else {
$popup = '';
}
$marker = isset($_POST['marker']);
$marker_image_url = $_POST['marker_image'];
if($marker) {
$marker_image = "\r\r/* Custom map marker */\r";
$marker_image .= "var mapIcon = L.Icon.extend({\r";
$marker_image .= " options: {\r";
$marker_image .= " iconSize: [50, 67],\r";
$marker_image .= " iconAnchor: [22, 64]\r";
$marker_image .= " }\r";
$marker_image .= "});\r";
$marker_image .= "var orangeIcon = new mapIcon({iconUrl: '" . $marker_image_url . "'});\r";
$marker_image .= "L.marker([" . $lat . ", " . $lng . "], {icon: orangeIcon}).addTo(map);\r";
$marker_default = "/* Remove default marker */\r";
} else {
$marker_image = '';
$marker_default = '';
}
?>
<textarea id="the_code" spellcheck="false">
<?php echo htmlspecialchars('<!--/ Start Leaflet Map /-->'); ?>
<?php echo htmlspecialchars('<div id="leaflet" style="width:' . $width . 'px; height:' . $height . 'px"></div><!--/ Remove inline width and height, declare in your stylesheet instead. /-->'); ?>
<?php echo htmlspecialchars('<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" />'); ?>
<?php echo htmlspecialchars('<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"></script>'); ?>
<?php if($marker) {
echo '<style>.leaflet-shadow-pane img { display: none !important; } .leaflet-marker-pane img:first-child { display: none !important; } </style>';
} ?>
<?php echo htmlspecialchars($full_screen_css); ?>
<?php echo htmlspecialchars($full_screen_js); ?>
<?php echo htmlspecialchars('<script>'); ?>
<?php echo htmlspecialchars('window.onload = function() {'); ?>
<?php echo htmlspecialchars("var map = new L.Map('leaflet', {
center: [" . $lat . ", " . $lng . "],
zoom: " . $zoom_level . ",
scrollWheelZoom: " . $scrollwheel . ",
zoomControl: false,
keyboard: true,
dragging: true,
zoomControl: false,
tap: false,
touchZoom: true,
" . $full_screen_init . "
layers: [
new L.TileLayer('" . $theme . "', {
'attribution': '" . $attribution . "'
})
],
});
" . $marker_default . "
/* Map marker position */
L.marker([" . $lat . ", " . $lng . "]).addTo(map);
/* Show scale ruler */
L.control.scale().addTo(map);
/* Zoom control position */
L.control.zoom({
position:'bottomright'
}).addTo(map);"); ?>
<?php echo htmlspecialchars($popup); ?>
<?php echo htmlspecialchars($marker_image); ?>
<?php echo htmlspecialchars($satellite_view); ?>
<?php if($satellite_view) {
echo htmlspecialchars("\r// Auto check first radio button\rdocument.querySelector('.leaflet-control-layers-base label:first-child input').checked = true;");
}
?>
<?php echo htmlspecialchars('}'); ?>
<?php echo htmlspecialchars('</script>'); ?>
<?php echo htmlspecialchars('<!--/ End Leaflet Map /-->'); ?>
</textarea>
<span class="copy">Copy</span>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>" class="mask"></a>
<?php } ?>
<form action="" method="POST">
<h1>
Leaflet Map Generator
</h1>
<div class="form-content">
<p>
<label>Latitude</label>
<input type="text" name="latitude" value="-32.12482252456546" required />
</p>
<p>
<label>Longitude</label>
<input type="text" name="longitude" value="115.91658963680956" required />
</p>
<p>
<label>Width</label>
<input type="number" name="width" value="800" required />
</p>
<p>
<label>Height</label>
<input type="number" name="height" value="600" required />
</p>
<p>
<label>Zoom level</label>
<input type="number" name="zoom_level" min="1" max="18" step="1" value="14" />
</p>
<p>
<label>Theme</label>
<select name="theme" id="theme">
<option value="google">Google</option>
<option value="openstreetmap">Open Street Map</option>
<option value="opentopmap">Open to Map</option>
<option value="hydda_base">Hydra Base</option>
<option value="watercolor">Water Colour</option>
<option value="esri">Esri</option>
<option value="positron">Positron</option>
<option value="voyager">Voyager</option>
<option value="voyager_no_labels">Voyager (no labels)</option>
</select>
</p>
<p>
<span class="valign">
<input type="checkbox" name="full_screen" id="full_screen" checked />
<label for="full_screen">Full screen control</label>
</span>
</p>
<p>
<span class="valign">
<input type="checkbox" name="satellite_view" id="satellite_view" checked />
<label for="satellite_view">Satellite view control</label>
</span>
</p>
<p>
<span class="valign">
<input type="checkbox" name="scrollwheel" id="scrollwheel" />
<label for="scrollwheel">Enable scrollwheel</label>
</span>
</p>
<p>
<span class="valign">
<input type="checkbox" name="popup" id="popup" />
<label for="popup">Include marker popup</label>
</span>
</p>
<p>
<span class="valign">
<input type="checkbox" name="marker" id="marker" />
<label for="marker">Custom marker image</label>
</span>
</p>
<p class="full-width hidden image-path">
<label>Custom marker image path (absolute or relative)</label>
<input type="text" name="marker_image" id="marker_image" />
</p>
<p class="full-width hidden popup-text">
<label>Popup text (HTML allowed)</label>
<textarea name="popup_text" id="popup_text"></textarea>
</p>
</div>
<input type="submit" name="submit" class="submit" value="Generate Code" />
<div class="theme-image">
<img src="images/google.png" id="theme_image" />
</div>
</form>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js'></script>
<script>
$('#marker').change(function(){
if ($(this).is(':checked')) {
$('.image-path').fadeIn();
$('#marker_image').attr('required', 'required');
} else {
$('.image-path').fadeOut();
$('#marker_image').removeAttr('required');
}
});
$('#popup').change(function(){
if ($(this).is(':checked')) {
$('.popup-text').fadeIn();
$('#popup_text').attr('required', 'required');
} else {
$('.popup-text').fadeOut();
$('#popup_text').removeAttr('required');
}
});
$('#theme').change(function(){
$('#theme_image').attr('src', 'images/'+$('#theme').val() + '.png');
});
$('.copy').click(function() {
$('#the_code').select();
$(this).html('Copied!' + ' ✔');
$(this).addClass('copied');
document.execCommand('copy');
});
var textBox = document.getElementById('the_code');
textBox.onfocus = function() {
textBox.select();
/* Work around the Chrome problem */
textBox.onmouseup = function() {
/* Prevent further mouseup intervention */
textBox.onmouseup = null;
return false;
};
};
</script>
</body>
</html>