-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet15-query.php
34 lines (29 loc) · 971 Bytes
/
leaflet15-query.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
<?php
// Get the data from the database
require_once ('database.php');
$database = new database ('localhost', $username = 'leaflet', $password = 'leaflet123', $database = 'leaflet');
$data = $database->getData ("SELECT * FROM locations;");
// Assemble the features
$features = array ();
foreach ($data as $record) {
$features[] = array (
"type" => "Point",
"properties" => array (
'id' => $record['id'],
'caption' => $record['caption'],
'categoryId' => $record['categoryId'],
'iconUrl' => $record['iconUrl'],
'username' => $record['username'],
),
"coordinates" => array ($record['longitude'], $record['latitude']),
);
}
// Assemble the GeoJSON
$geojson = array (
"type" => "FeatureCollection",
"features" => $features,
);
// Serve as GeoJSON
header('Content-Type: application/json');
echo json_encode ($geojson, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
?>