Révision 034df12a
Ajouté par Jocelyn Delande il y a presque 11 ans
ajax/all_points.php | ||
---|---|---|
1 |
<?php |
|
2 |
require_once('../class/sites_dir.class.php'); |
|
3 |
require_once('../class/site_point.class.php'); |
|
4 |
|
|
5 |
function get_ref_points() { |
|
6 |
$ref_points_filename = '../ref_points.local.php'; |
|
7 |
if (file_exists($ref_points_filename)) { |
|
8 |
include $ref_points_filename; |
|
9 |
return $ref_points; |
|
10 |
} else { |
|
11 |
return array(); |
|
12 |
} |
|
13 |
} |
|
14 |
|
|
15 |
|
|
16 |
function ref_point_to_geoJSONFeature($name, $values) { |
|
17 |
return array("type" => "Feature", |
|
18 |
"geometry" => array( |
|
19 |
"type" => "Point", |
|
20 |
"coordinates" => [$values[1],$values[0]] |
|
21 |
), |
|
22 |
"properties" => array("name" => $name, "type" => 'loc_point') |
|
23 |
); |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
function get_site_points() { |
|
28 |
$dir = "../tiles"; |
|
29 |
return (new sites_dir($dir))->get_sites(); |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
function site_point_to_geoJSONFeature($sp) { |
|
34 |
$prm = $sp->get_params(); |
|
35 |
$name = $sp->get_name(); |
|
36 |
$lat = floatval($prm['latitude']); |
|
37 |
$lon = floatval($prm['longitude']); |
|
38 |
//$alt = $prm['altitude']; |
|
39 |
//$title = $prm['titre']; |
|
40 |
|
|
41 |
return array("type" => "Feature", |
|
42 |
"geometry" => array( |
|
43 |
"type" => "Point", |
|
44 |
"coordinates" => [$lon, $lat] |
|
45 |
), |
|
46 |
"properties" => array("name" => $name, "type" => 'pano_point') |
|
47 |
); |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
$json = array( |
|
52 |
"type" => "FeatureCollection", |
|
53 |
"features"=> array() |
|
54 |
); |
|
55 |
|
|
56 |
foreach (get_ref_points() as $name => $vals) { |
|
57 |
$json['features'][] = ref_point_to_geoJSONFeature($name, $vals); |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
foreach(get_site_points() as $site_point) { |
|
62 |
$json['features'][] = site_point_to_geoJSONFeature($site_point); |
|
63 |
} |
|
64 |
|
|
65 |
echo json_encode($json); |
|
66 |
?> |
ajax/ref_points.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any |
|
6 |
* origin. |
|
7 |
* |
|
8 |
* In a production environment, you probably want to be more restrictive, but this gives you |
|
9 |
* the general idea of what is involved. For the nitty-gritty low-down, read: |
|
10 |
* |
|
11 |
* - https://developer.mozilla.org/en/HTTP_access_control |
|
12 |
* - http://www.w3.org/TR/cors/ |
|
13 |
* |
|
14 |
*/ |
|
15 |
function cors() { |
|
16 |
// Allow from any origin |
|
17 |
if (isset($_SERVER['HTTP_ORIGIN'])) { |
|
18 |
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); |
|
19 |
header('Access-Control-Allow-Credentials: true'); |
|
20 |
header('Access-Control-Max-Age: 86400'); // cache for 1 day |
|
21 |
} |
|
22 |
|
|
23 |
// Access-Control headers are received during OPTIONS requests |
|
24 |
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
|
25 |
|
|
26 |
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) |
|
27 |
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); |
|
28 |
|
|
29 |
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) |
|
30 |
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); |
|
31 |
|
|
32 |
exit(0); |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
cors(); |
|
37 |
|
|
38 |
function ref_point_to_geoJSONFeature($name, $values) { |
|
39 |
return array("type" => "Feature", |
|
40 |
"geometry" => array( |
|
41 |
"type" => "Point", |
|
42 |
"coordinates" => [$values[1],$values[0]] |
|
43 |
), |
|
44 |
"properties" => array("name" => $name, "type" => 'loc_point') |
|
45 |
); |
|
46 |
} |
|
47 |
|
|
48 |
function get_ref_points() { |
|
49 |
$ref_points_filename = '../ref_points.local.php'; |
|
50 |
if (file_exists($ref_points_filename)) { |
|
51 |
include $ref_points_filename; |
|
52 |
return $ref_points; |
|
53 |
} else { |
|
54 |
return array(); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
$json = array( |
|
59 |
"type" => "FeatureCollection", |
|
60 |
"features"=> array() |
|
61 |
); |
|
62 |
|
|
63 |
foreach (get_ref_points() as $name => $vals) { |
|
64 |
$json['features'][] = ref_point_to_geoJSONFeature($name, $vals); |
|
65 |
} |
|
66 |
|
|
67 |
echo json_encode($json); |
|
68 |
|
|
69 |
?> |
js/utils_osm.js | ||
---|---|---|
257 | 257 |
projection: new OpenLayers.Projection("EPSG:4326"), |
258 | 258 |
strategies: [new OpenLayers.Strategy.Fixed()], |
259 | 259 |
protocol: new OpenLayers.Protocol.HTTP({ |
260 |
url: 'ajax/ref_points.php',
|
|
260 |
url: 'ajax/all_points.php',
|
|
261 | 261 |
format: new OpenLayers.Format.GeoJSON(), |
262 | 262 |
}), |
263 | 263 |
styleMap: points_style |
Formats disponibles : Unified diff
FIXUP