5 OpenLayers._getScriptLocation = function () {
9 function createMap(divName) {
10 map = new OpenLayers.Map(divName, {
12 new OpenLayers.Control.ArgParser(),
13 new OpenLayers.Control.Attribution(),
14 new OpenLayers.Control.LayerSwitcher(),
15 new OpenLayers.Control.Navigation(),
16 new OpenLayers.Control.PanZoomBar()
20 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
21 displayOutsideMaxExtent: true,
26 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
27 displayOutsideMaxExtent: true,
30 map.addLayer(osmarender);
32 var mapnik_local = new OpenLayers.Layer.OSM("Mapnik (Local)", "http://bericote.uk.cyberscience.com/tiles/", {
33 displayOutsideMaxExtent: true,
36 map.addLayer(mapnik_local);
38 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
39 markers = new OpenLayers.Layer.Markers("Markers", {
40 displayInLayerSwitcher: false,
41 numZoomLevels: numZoomLevels,
42 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
43 maxResolution: 156543,
45 projection: "EPSG:900913"
47 map.addLayer(markers);
52 function getArrowIcon() {
53 var size = new OpenLayers.Size(25, 22);
54 var offset = new OpenLayers.Pixel(-30, -27);
55 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
60 function addMarkerToMap(position, icon, description) {
61 var marker = new OpenLayers.Marker(position, icon);
63 markers.addMarker(marker);
66 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
72 function openMapPopup(marker, description) {
75 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
76 sizeMapPopup(description),
77 "<p style='padding-right: 28px'>" + description + "</p>",
79 popup.setBackgroundColor("#E3FFC5");
85 function closeMapPopup() {
87 map.removePopup(popup);
92 function sizeMapPopup(text) {
93 var box = document.createElement("div");
96 box.style.visibility = "hidden";
97 box.style.position = "absolute";
98 box.style.top = "0px";
99 box.style.left = "0px";
100 box.style.width = "200px";
101 box.style.height = "auto";
103 document.body.appendChild(box);
105 var width = box.offsetWidth;
106 var height = box.offsetHeight;
108 document.body.removeChild(box);
110 return new OpenLayers.Size(width + 30, height + 24);
113 function removeMarkerFromMap(marker){
114 markers.removeMarker(marker);
117 function getMapLayers() {
120 for (var i=0; i< this.map.layers.length; i++) {
121 var layer = this.map.layers[i];
123 if (layer.isBaseLayer) {
124 layers += (layer == this.map.baseLayer) ? "B" : "0";
126 layers += (layer.getVisibility()) ? "T" : "F";
133 function setMapLayers(layers) {
134 for (var i=0; i < layers.length; i++) {
135 var layer = map.layers[i];
136 var c = layers.charAt(i);
139 map.setBaseLayer(layer);
140 } else if ( (c == "T") || (c == "F") ) {
141 layer.setVisibility(c == "T");
146 function mercatorToLonLat(merc) {
147 var lon = (merc.lon / 20037508.34) * 180;
148 var lat = (merc.lat / 20037508.34) * 180;
150 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
152 return new OpenLayers.LonLat(lon, lat);
155 function lonLatToMercator(ll) {
156 var lon = ll.lon * 20037508.34 / 180;
157 var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
159 lat = lat * 20037508.34 / 180;
161 return new OpenLayers.LonLat(lon, lat);
164 function scaleToZoom(scale) {
165 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);