-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommons-on-osm.php
311 lines (261 loc) · 9.78 KB
/
commons-on-osm.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<html>
<head>
<title>Commons on OSM</title>
<style type="text/css">
body {
padding: 0;
margin: 0;
}
.olPopupContent img {border: none;}
.olControlAttribution{bottom:0 !important;}
</style>
<?php
require_once ( "geo_param.php" ) ;
require_once ( "helpers.php" ) ;
$lang=addslashes(urldecode(param_get('lang', 'en')));
$position = '';
if ( isset ( $_REQUEST['params'] ) ) {
$p = new geo_param( $_REQUEST['params'] , "Dummy" );
$x = $p->londeg ;
$y = $p->latdeg ;
$position= "args.lon = $x; args.lat = $y;";
echo "<!--- //position:".$position." --->\n";
}
?>
<script src="https://osm.toolforge.org/libs/jquery/latest/jquery-min.js" type="text/javascript"></script>
<script src="https://osm.toolforge.org/libs/openlayers/2.12/OpenLayers-min.js" type="text/javascript"></script>
<script src="https://osm.toolforge.org/libs/openstreetmap/latest/OpenStreetMap.js"></script>
<script type="text/javascript">
// map object
var map;
// initiator
function init()
{
// show an error image for missing tiles
OpenLayers.Util.onImageLoadError = function()
{
if (urlRegex.test(this.src))
{
var style = RegExp.$2;
if (style == 'osm')
{
var tile = RegExp.$3;
var inst = RegExp.$1;
this.src = 'http://'+inst+'.tile.openstreetmap.org/'+tile;;
if (console && console.log)
console.log('redirecting request for '+tile+' to openstreetmap.org: '+this.src);
return;
}
this.src = 'http://www.openstreetmap.org/openlayers/img/404.png';
}
};
// show an error image for missing tiles
OpenLayers.Util.onImageLoadError=function() {
this.src = 'http://www.openstreetmap.org/openlayers/img/404.png';
};
// get the request-parameters
var args = OpenLayers.Util.getParameters();
// main map object
map = new OpenLayers.Map ("map", {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Permalink()
],
// mercator bounds
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
// create the custom layer
OpenLayers.Layer.OSM.Toolserver = OpenLayers.Class(OpenLayers.Layer.OSM, {
initialize: function(name, options) {
var url = [
//"//tiles.wmflabs.org/" + name + "/${z}/${x}/${y}.png"
"https://maps.wikimedia.org/osm-intl/${z}/${x}/${y}.png"
];
options = OpenLayers.Util.extend({numZoomLevels: 19}, options);
OpenLayers.Layer.OSM.prototype.initialize.apply(this, [name, url, options]);
},
CLASS_NAME: "OpenLayers.Layer.OSM.Toolserver"
});
// add the osm from Toolserver layers
var osm = new OpenLayers.Layer.OSM.Toolserver('osm',{
tileOptions: { crossOriginKeyword: null }
});
map.addLayer(osm);
// add the osm.org layers
map.addLayer(new OpenLayers.Layer.OSM.Mapnik("OSM.org"), {visibility: false});
var bboxStrategy = new OpenLayers.Strategy.BBOX( {
ratio : 1.1,
resFactor: 1
});
var pois = new OpenLayers.Layer.Vector("Commons", {
attribution:'CC-BY-SA by <a href="//commons.wikimedia.org/wiki/Commons:Geocoding">Wikimedia Commons</a>',
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [bboxStrategy],
protocol:
new OpenLayers.Protocol.HTTP({
url: "https://geocommons.toolforge.org/kml",
/* url: "//toolserver.org/~para/GeoCommons/kml.php?f=photos&simple",*/
/*url: "GeoworldProxy?lang=de",*/
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
map.addLayer(pois);
var feature = null;
var highlightFeature = null;
var lastFeature = null;
var selectPopup = null;
var tooltipPopup = null;
var selectCtrl = new OpenLayers.Control.SelectFeature(pois, {
toggle:true,
clickout: true
});
pois.events.on({ "featureselected": onMarkerSelect, "featureunselected": onMarkerUnselect});
function onMarkerSelect (evt) {
eventTooltipOff(evt);
if (selectPopup != null) {
map.removePopup(selectPopup);
selectPopup.feature=null;
if (feature != null && feature.popup != null) {
feature.popup = null;
}
}
feature = evt.feature;
//console.log("feature selected", feature) ;
//console.log("features in layer", pois.features.length);
selectPopup = new OpenLayers.Popup.AnchoredBubble("activepopup",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(320,320),
text='<b>'+feature.attributes.name +'</b><br>'+ feature.attributes.description,
null, true, onMarkerPopupClose );
selectPopup.closeOnMove = false;
selectPopup.autoSize = false;
feature.popup = selectPopup;
selectPopup.feature = feature;
map.addPopup(selectPopup);
}
function onMarkerUnselect (evt) {
feature = evt.feature;
if (feature != null && feature.popup != null) {
selectPopup.feature = null;
map.removePopup(feature.popup);
feature.popup = null;
}
}
function onMarkerPopupClose(evt) {
if (selectPopup != null) {
map.removePopup(selectPopup);
selectPopup.feature = null;
if (feature != null && feature.popup != null) {
feature.popup = null;
}
}
selectCtrl.unselectAll();
}
var highlightCtrl = new OpenLayers.Control.SelectFeature(pois, {
hover: true,
highlightOnly: true,
renderIntent: "temporary",
eventListeners: {
featurehighlighted: eventTooltipOn,
featureunhighlighted: eventTooltipOff
}
});
function eventTooltipOn (evt) {
highlightFeature = evt.feature;
if (tooltipPopup != null) {
map.removePopup(tooltipPopup);
tooltipPopup.feature=null;
if (lastFeature != null) {
lastFeature.popup = null;
}
}
lastFeature = highlightFeature;
//document.getElementById("map_OpenLayers_Container").style.cursor = "pointer";
tooltipPopup = new OpenLayers.Popup("activetooltip",
highlightFeature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(210,200),
" "+highlightFeature.attributes.description.replace(/<[hH][1-3][^>]*>(.*?)<\/[hH][1-3]>/,""), null, false, null );
tooltipPopup.contentDiv.style.backgroundColor='ffffff';
tooltipPopup.contentDiv.style.overflow='hidden';
tooltipPopup.contentDiv.style.padding='6px';
tooltipPopup.contentDiv.style.margin='0px';
tooltipPopup.border = '3px solid #DBDBD3';
tooltipPopup.closeOnMove = true;
tooltipPopup.autoSize = true;
highlightFeature.popup = tooltipPopup;
map.addPopup(tooltipPopup);
}
function eventTooltipOff (evt) {
highlightFeature = evt.feature;
//document.getElementById("map_OpenLayers_Container").style.cursor = "default";
if (highlightFeature != null && highlightFeature.popup != null) {
map.removePopup(highlightFeature.popup);
highlightFeature.popup = null;
tooltipPopup = null;
lastFeature = null;
}
}
map.addControl(highlightCtrl);
map.addControl(selectCtrl);
highlightCtrl.activate();
selectCtrl.activate();
// default zoon
var zoom = 12;
<?php echo $position;?>
// lat/lon requestes
if (args.lon && args.lat)
{
// zoom requested
if (args.zoom)
{
zoom = parseInt(args.zoom);
var maxZoom = map.getNumZoomLevels();
if (zoom >= maxZoom) zoom = maxZoom - 1;
}
// transform center
var center = new OpenLayers.LonLat(parseFloat(args.lon), parseFloat(args.lat)).
transform(map.displayProjection, map.getProjectionObject())
// move to
map.setCenter(center, zoom);
}
// bbox requestet
else if (args.bbox)
{
// transform bbox
var bounds = OpenLayers.Bounds.fromArray(args.bbox).
transform(map.displayProjection, map.getProjectionObject());
// move to
map.zoomToExtent(bounds)
}
// default center
else
{
// set the default center
var center = new OpenLayers.LonLat(0, 0).
transform(map.displayProjection, map.getProjectionObject());
// move to
map.setCenter(center, zoom);
}
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var size = new OpenLayers.Size(16,16);
var offset = new OpenLayers.Pixel(-(size.w/2), -(size.h/2));
var icon = new OpenLayers.Icon('Ol_icon_red_example.png',size,offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(map.center.lon,map.center.lat),icon));
}
</script>
</head>
<body onload="init();" id="map">
</body>
</html>