-
Notifications
You must be signed in to change notification settings - Fork 1
/
embed.html
146 lines (127 loc) · 4.97 KB
/
embed.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OpenStreetMap Embedded</title>
<style type="text/css">
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
height: 100%;
margin: 0px;
}
#map {
width: 100%;
height: 100%;
}
.olControlAttribution {
bottom: 3px!important;
}
</style>
<script src="https://osm.toolforge.org/libs/openlayers/2.11/OpenLayers.js" type="text/javascript"></script>
<script src="https://osm.toolforge.org/libs/openstreetmap/latest/OpenStreetMap.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
var map, layer, tempCounter;
function init(){
function mapEvent(event) {
if (tempCounter && mapnik['buffer']==0)
{//alert(event.type+map[baseLayer]);
mapnik['buffer']=2;}
tempCounter=true;
}
var urlRegex = new RegExp('^http://([abc]).www.toolserver.org/tiles/([^/]+)/(.*)$');
// 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 = '//'+inst+'.tile.openstreetmap.org/'+tile;;
if(console && console.log)
console.log('redirecting request for '+tile+' to openstreetmap.org: '+this.src);
return;
}
this.src = '//www.openstreetmap.org/openlayers/img/404.png';
}
};
// create the custom layer
OpenLayers.Layer.OSM.Toolserver = OpenLayers.Class(OpenLayers.Layer.OSM, {
initialize: function(name, options) {
var url = [
"//a.toolserver.org/tiles/" + name + "/${z}/${x}/${y}.png",
"//b.toolserver.org/tiles/" + name + "/${z}/${x}/${y}.png",
"//c.toolserver.org/tiles/" + name + "/${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"
});
map = new OpenLayers.Map ("map", {
eventListeners: { "moveend":mapEvent},
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation()
],
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,
20037508.34,20037508.34),
numZoomLevels: 20,
maxResolution: 156543.0339,
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913")
});
var attribution = '© <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a> and contributors';
var args = OpenLayers.Util.getParameters();
if (!args.layer || args.layer == "mapnik-OSM") {
var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
displayOutsideMaxExtent: true,
wrapDateLine: true,
attribution: attribution,
'buffer':0
});
map.addLayer(mapnik);
} else if (args.layer == "mapnik") {
var mapnik=new OpenLayers.Layer.OSM.Toolserver('osm')
map.addLayer(mapnik);
} else if (args.layer == "cycle map") {
var cyclemap = new OpenLayers.Layer.OSM.CycleMap("Cycle Map", {
displayOutsideMaxExtent: true,
wrapDateLine: true,
attribution: attribution
});
map.addLayer(cyclemap);
}
if (args.marker) {
var markers = new OpenLayers.Layer.Markers();
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(args.marker[1], args.marker[0]).transform(map.displayProjection, map.getProjectionObject())));
map.marker = true;
}
if (args.bbox) {
var bounds = OpenLayers.Bounds.fromArray(args.bbox).transform(map.displayProjection, map.getProjectionObject());
map.zoomToExtent(bounds)
} else {
map.zoomToMaxExtent();
}
var size = map.getSize();
if (size.h > 320) {
map.addControl(new OpenLayers.Control.PanZoomBar());
} else {
map.addControl(new OpenLayers.Control.PanZoom());
}
}
// -->
</script>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>