-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommons2geojson.html
More file actions
211 lines (168 loc) · 5.16 KB
/
commons2geojson.html
File metadata and controls
211 lines (168 loc) · 5.16 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<style type="text/css">
#map { height: 100%; }
</style>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="map"/>
<script>
var test_lonlat = { "lon": 9.89431, "lat":52.44972 };
var tempel = { "lon": 9.70410, "lat":52.38727 }
var mymap = L.map('map').setView([tempel.lat, tempel.lon], 18);
var ic = L.icon({
iconUrl: 'circle.png',
iconSize: [64,64],
iconAnchor: [32,32],
});
var osmlayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);
var baseMaps = {
"OSM":osmlayer,
};
var cir = L.marker([52.44972, 9.89431], {icon: ic}).addTo(mymap);
//L.marker([51.5, -0.09]).addTo(mymap);
function onMapClick(e) {
cir.setLatLng(e.latlng)
}
mymap.on('click', onMapClick);
var geojsonpoint = function(lon,lat,props) {
return {
"type": "Feature",
"properties": props,
"geometry": {
"type": "Point",
"coordinates": [
lon,
lat
]
}
}
}
var make_fc = function(geomarray) {
return {
"type": "FeatureCollection",
"features": geomarray
}
}
var fcoll_orig = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"prop1": "bar",
},
"geometry": {
"type": "Point",
"coordinates": [
9.89431,
52.44972
]
}
},
{
"type": "Feature",
"properties": {
"prop1": "foo",
},
"geometry": {
"type": "Point",
"coordinates": [
9.8949,
52.4491
]
}
}
]
}
var fcoll_orig_layer = L.geoJson(fcoll_orig);
var p1 = geojsonpoint(test_lonlat.lon, test_lonlat.lat, {"note": "bla"});
var p2 = geojsonpoint(test_lonlat.lon+0.005, test_lonlat.lat+0.005, {"note": "jjdjdjdj"})
var p3 = geojsonpoint(test_lonlat.lon-0.005, test_lonlat.lat-0.005, {"note": "XXXXXX"})
var fc_functions = make_fc([p1,p2,p3]);
var fcoll_from_func_layer = L.geoJson(fc_functions);
var geojsonpoints;
var commonsIcon = L.icon({
iconUrl: "commons_without_arrow.png",
iconSize: [16,16],
iconAnchor: [8,8],
});
// Commons
$.ajax( {
url: "https://commons.wikimedia.org/w/api.php",
data: {
action:'query',
generator:'geosearch',
ggsprimary:'all',
ggsnamespace:'6',
ggsradius:200,
//ggscoord:test_lonlat.lat+ '|'+test_lonlat.lon,
ggscoord:tempel.lat+"|"+tempel.lon, // Leibniztempel
ggslimit:50,
prop:'imageinfo|coordinates',
iilimit:50,
iiprop:'url|extmetadata',
iiurlwidth:200,
iiurlheight:200,
colimit:50,
coprimary: 'all',
format:'json',
},
jsonp: 'callback',
dataType: 'jsonp',
success: function(data,status,xhr) {
var txt = "";
if (data.query == undefined) {
$("#imagelist").html("<i>no images found</i>");
} else {
geojsonpoints = Array();
$.each(data.query.pages,
function(i,v) {
if (v.coordinates != undefined) {
var opts = {};
if (v.imageinfo != undefined) {
opts.thumburl = v.imageinfo[0].thumburl;
opts.descurl = v.imageinfo[0].descriptionurl;
if (v.imageinfo[0].extmetadata != undefined) {
if (v.imageinfo[0].extmetadata.Artist != undefined) {
opts.artist = v.imageinfo[0].extmetadata.Artist;
}
} // end if extmetadata
} // end if imageinfo != undefined
geojsonpoints.push( geojsonpoint(v.coordinates[0].lon, v.coordinates[0].lat, opts) );
} else {
// no coordinates
console.log("No coordinates");
}
}
); // end each
L.geoJson(make_fc(geojsonpoints), {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: commonsIcon});
},
onEachFeature: function(feature,layer) {
layer.on('click', function() {
// hier onclick für Bildmarker
var i;
alert(feature.properties.thumburl);
});
}
}).addTo(mymap);
}
},
}) // end ajax
// end commons
var overlays = { "Klickbarer Kreis ": cir, "JSON aus dem Code":fcoll_orig_layer, "JSON aus Funktionen":fcoll_from_func_layer };
L.control.layers(baseMaps, overlays).addTo(mymap);
</script>
</body>
</html>