-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajapaikimageinfo.php
143 lines (121 loc) · 3.62 KB
/
ajapaikimageinfo.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
<?php
require_once("common.php");
header("Access-Control-Allow-Origin: *");
$callback="";
if (isset($_GET['callback']) && trim($_GET['callback'])!="" && preg_match("|\A[a-zA-z0-9_]*\z|", $_GET['callback'])) {
$callback=trim($_GET['callback']);
}
if ($callback!="") {
header('Content-Type: application/javascript');
}
else
{
header('Content-Type: application/json');
}
// Example Query
// https://ajapaik.ee/photo/511580/v2/manifest.json
// https://ajapaik.ee/photo/ID/v2/manifest.json
// Flutter app image info parameters
$params=array(
'lat'=>64,
'lon'=>24,
'id'=>511580,
'orderby'=>'date',
'orderdirection'=>'desc',
'limit'=>1000
);
$stringkeys=array("orderby", "orderdirection");
$params=merge_get_parameters($params, $stringkeys);
$url="https://ajapaik.ee/photo/".$params['id']."/v2/manifest.json";
$file=file_get_contents($url);
$json=json_decode($file, true);
$featurelist=array();
$number_of_rephotos=count($json['sequences'][0]['canvases'])-1;
foreach($json['sequences'][0]['canvases'] as $k=>$v) {
$metadata=array();
foreach($v['metadata'] as $m) {
$key=$m["label"]["@value"];
if ($key=="Source") {
if (preg_match("|href= ?\"?(.*?)[\" >]|ism", $m["value"], $mm))
{
$metadata[$key]=$mm[1];
}
else
{
die("Error: Source = " . $m["value"]);
}
}
elseif ($key=="Coordinates") {
$coord=array();
if (preg_match("|Latitude: ?([0-9.]+)|ism", $m["value"], $mm))
{
$coord["Latitude"]=floatval($mm[1]);
}
else
{
die("Error: Latitude = " . $m["value"]);
}
if (preg_match("|Longitude: ?([0-9.]+)|ism", $m["value"], $mm))
{
$coord["Longitude"]=floatval($mm[1]);
}
else
{
die("Error: Longitude = " . $m["value"]);
}
$metadata[$key]=$coord;
}
else {
$metadata[$key]=$m["value"];
}
}
//print_r($metadata);
$label=$v['label']['@value'];
$description="";
if (preg_match("|https://ajapaik.ee/photo/".$params['id']."/canvas/.*?_([0-9]+)\z|ism", $v['@id'], $mm)) {
$photo_id=$mm[1];
}
// Geojson properties
$properties=array(
'id' =>$photo_id,
'name' =>$label,
'name_orig' => "ORIG: " . $label,
'description' =>isset($description) ? "ORIG:" . $description : "",
'description_orig' =>isset($description) ? "ORIG: " . $description : "",
'date' =>isset($metadata['Date']) ? $metadata['Date'] :"",
'author' =>isset($metadata['Author']) ? $metadata['Author'] :"",
'source_url' =>isset($metadata['Source']) ? $metadata['Source'] :"",
'source_label'=>isset($metadata['Identifier']) ? $metadata['Identifier'] :"",
'favorites' =>"",
'rephotos' =>$k==0 ? $number_of_rephotos : "",
'thumbnail' =>$v["thumbnail"]["@id"],
'iiif_manifest' => 'https://ajapaik.ee/photo/'.$photo_id.'/v2/manifest.json',
// 'licence_url' => 'https://creativecommons.org/licenses/by/4.0/deed.fi',
// 'licence_label' => 'CC-BY-4.0',
);
// Geojson geometry
$geometry=array();
if (isset($metadata["Coordinates"])) {
$properties['distance'] = wgs84_distance($metadata["Coordinates"]["Latitude"], $metadata["Coordinates"]['Longitude'], $params['lat'], $params['lon']);
$geometry=array(
'type'=>"Point",
'coordinates'=>array($metadata["Coordinates"]["Longitude"], $metadata["Coordinates"]["Latitude"])
);
}
// Geojson feature
$feature=array(
'type'=>"Feature",
'geometry'=>$geometry,
'properties'=>$properties
);
$featurelist[$properties["id"]]=$feature;
}
// Do sort
//$sortedfeatureslist = sortfeatures($featurelist, $params['orderby'], $params['orderdirection'], $params['limit']);
$outjson=array(array(
"type"=> "FeatureCollection",
"features"=> array_values($featurelist)
));
print(json_encode($outjson, JSON_PRETTY_PRINT));
die(1);
?>