-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.php
86 lines (79 loc) · 2.79 KB
/
map.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
<?php
header("Access-Control-Allow-Origin: *");
if (isset($_GET['pageid'])) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://warper.wmflabs.org/api/v1/maps?field=page_id&query=' . $_GET['pageid']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($curl));
curl_close($curl);
if ($result->data[0]->attributes->status == 'warped') {
// Leaflet does not really deal with WMS...
$wms = str_replace('?request=GetCapabilities&service=WMS&version=1.1.1', '', $result->data[0]->links->wms);
$commons = 'https://commons.wikimedia.org/?curid=' . $_GET['pageid'];
$bbox = explode(',', $result->data[0]->attributes->bbox);
?>
<!doctype html>
<html>
<head>
<title>Embedded Map</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/leaflet/1.0.0-rc.3/leaflet.css">
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/leaflet/1.0.0-rc.3/leaflet.js"></script>
<link rel="stylesheet" href="Leaflet.Slider.css">
<script src="Leaflet.Slider.js"></script>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
}
</style>
<script>
window.onload = function() {
var map = L.map('map').fitBounds([
[<?php echo $bbox[3] ?>, <?php echo $bbox[2] ?>],
[<?php echo $bbox[1] ?>, <?php echo $bbox[0] ?>]
]);
<?php
// make sure the given lang value only contains letters or numbers as we inject the content without validation
if (isset($_GET['lang']) && !preg_match('/[^A-Za-z0-9]/', $_GET['lang'])) {
?>
L.tileLayer('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png?lang=<?php echo $_GET['lang'] ?>', {
attribution: 'Wikimedia maps | Map data © <a href="http://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
<?php
} else {
?>
L.tileLayer('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png', {
attribution: 'Wikimedia maps | Map data © <a href="http://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
<?php
}
?>
var wmsLayer = L.tileLayer.wms('<?php echo $wms; ?>', {
layers: 'MapWarper',
format: 'image/png',
attribution: '<a href="<?php echo $commons; ?>">Wikimedia Commons</a>'
}).addTo(map);
<?php
if (isset($_GET['opacity'])) {
?>
var slider = L.control.slider({ position: 'bottomleft' }).addTo(map);
slider._container.addEventListener('sliderChange', function (e) {
var opacity = (100- e.detail.value) / 100;
wmsLayer.setOpacity(opacity);
}, false);
<?php
}
?>
}
</script>
</head>
<body id="map"></body>
</html>
<?php
} else {
echo 'This map is not yet warped!';
}
}