5 function createMap(divName) {
6 OpenLayers.Util.onImageLoadError = function() {
7 this.src = OpenLayers.Util.getImagesLocation() + "404.png";
10 map = new OpenLayers.Map(divName,
11 { maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
13 maxResolution: 156543,
15 projection: "EPSG:41001" });
17 var mapnik = new OpenLayers.Layer.TMS("Mapnik",
18 "http://tile.openstreetmap.org/",
19 { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
22 var osmarender = new OpenLayers.Layer.TMS("Osmarender",
23 "http://dev.openstreetmap.org/~ojw/Tiles/tile.php/",
24 { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
25 map.addLayer(osmarender);
27 markers = new OpenLayers.Layer.Markers("markers", { visibility: false });
28 map.addLayer(markers);
30 map.addControl(new OpenLayers.Control.LayerSwitcher());
35 function getTileURL(bounds) {
36 var res = this.map.getResolution();
37 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
38 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
39 var z = this.map.getZoom();
40 var limit = Math.pow(2, z);
42 if (y < 0 || y >= limit)
44 return OpenLayers.Util.getImagesLocation() + "404.png";
48 x = ((x % limit) + limit) % limit;
50 return this.url + z + "/" + x + "/" + y + "." + this.type;
54 function getArrowIcon() {
55 var size = new OpenLayers.Size(25, 22);
56 var offset = new OpenLayers.Pixel(-30, -27);
57 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
62 function addMarkerToMap(position, icon, description) {
63 var marker = new OpenLayers.Marker(position, icon);
65 markers.addMarker(marker);
66 markers.setVisibility(true);
69 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
75 function openMapPopup(marker, description) {
78 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
79 sizeMapPopup(description),
80 "<p style='padding-right: 28px'>" + description + "</p>",
82 popup.setBackgroundColor("#E3FFC5");
88 function closeMapPopup() {
90 map.removePopup(popup);
95 function sizeMapPopup(text) {
96 var box = document.createElement("div");
99 box.style.visibility = "hidden";
100 box.style.position = "absolute";
101 box.style.top = "0px";
102 box.style.left = "0px";
103 box.style.width = "200px";
104 box.style.height = "auto";
106 document.body.appendChild(box);
108 var width = box.offsetWidth;
109 var height = box.offsetHeight;
111 document.body.removeChild(box);
113 return new OpenLayers.Size(width + 30, height + 24);
116 function removeMarkerFromMap(marker){
117 markers.removeMarker(marker);
120 function getMapLayers() {
123 for (var i=0; i< this.map.layers.length; i++) {
124 var layer = this.map.layers[i];
126 if (layer.isBaseLayer) {
127 layers += (layer == this.map.baseLayer) ? "B" : "0";
129 layers += (layer.getVisibility()) ? "T" : "F";
136 function setMapLayers(layers) {
137 for (var i=0; i < layers.length; i++) {
138 var layer = map.layers[i];
139 var c = layers.charAt(i);
142 map.setBaseLayer(layer);
143 } else if ( (c == "T") || (c == "F") ) {
144 layer.setVisibility(c == "T");
149 function mercatorToLonLat(merc) {
150 var lon = (merc.lon / 20037508.34) * 180;
151 var lat = (merc.lat / 20037508.34) * 180;
153 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
155 return new OpenLayers.LonLat(lon, lat);
158 function lonLatToMercator(ll) {
159 var lon = ll.lon * 20037508.34 / 180;
160 var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
162 lat = lat * 20037508.34 / 180;
164 return new OpenLayers.LonLat(lon, lat);
167 function scaleToZoom(scale) {
168 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);