-
Notifications
You must be signed in to change notification settings - Fork 0
/
markers.php
71 lines (63 loc) · 2.23 KB
/
markers.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
<?php
$csv_file = "markers.csv";
if (!file_exists($csv_file)) {
exit("<center><code style='color: red;'>$csv_file not found.</code></center>");
}
?>
<!DOCTYPE html>
<html>
<!-- Author: Dmitri Popov
License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
Source code: https://github.com/dmpop/pinpinpin -->
<head>
<title>PinPinPin</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.png" />
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="leaflet/leaflet.css" />
<script src="leaflet/leaflet.js"></script>
<!-- Numbered markers https://gist.github.com/comp615/2288108 -->
<link rel="stylesheet" href="leaflet/leaflet_numbered_markers.css" />
<script src="leaflet/leaflet_numbered_markers.js"></script>
</head>
<body>
<div id="map"></div>
<script>
// Creating map options
var mapOptions = {
<?php
if (($file = fopen($csv_file, "r")) !== FALSE) {
$line = fgetcsv($file);
echo "center: [" . $line[0] . "," . $line[1] . "],";
}
?>
zoom: 5
}
// Creating a map object
var map = new L.map('map', mapOptions);
// Creating a Layer object
var layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors. This is <a href="https://github.com/dmpop/pinpinpin">PinPinPin</a>'
});
// Adding layer to the map
map.addLayer(layer);
// Creating a marker
<?php
if (($file = fopen($csv_file, "r")) !== FALSE) {
for ($i = 0; $i < count(file($csv_file)); $i++) {
$line = fgetcsv($file);
echo "
var marker" . $i . " = new L.Marker(new L.LatLng(" . $line[0] . ", " . $line[1] . "), {
icon: new L.NumberedDivIcon({
number: '" . $i + 1 . "'
})
}).addTo(map).bindPopup('" . $line[2] . "');
";
}
fclose($file);
}
?>
</script>
</body>
</html>