5 OpenLayers._getScriptLocation = function () {
9 function createMap(divName) {
10 map = new OpenLayers.Map(divName);
12 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", { displayOutsideMaxExtent: true });
15 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", { displayOutsideMaxExtent: true });
16 map.addLayer(osmarender);
18 var maplint = new OpenLayers.Layer.OSM.Maplint("Maplint", { displayOutsideMaxExtent: true });
19 map.addLayer(maplint);
21 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
22 markers = new OpenLayers.Layer.Markers("Markers", {
23 displayInLayerSwitcher: false, numZoomLevels: numZoomLevels,
24 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
25 maxResolution: 156543,
27 projection: "EPSG:41001"
29 map.addLayer(markers);
31 map.addControl(new OpenLayers.Control.LayerSwitcher());
32 map.addControl(new OpenLayers.Control.KeyboardDefaults());
37 function getArrowIcon() {
38 var size = new OpenLayers.Size(25, 22);
39 var offset = new OpenLayers.Pixel(-30, -27);
40 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
45 function addMarkerToMap(position, icon, description) {
46 var marker = new OpenLayers.Marker(position, icon);
48 markers.addMarker(marker);
51 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
57 function openMapPopup(marker, description) {
60 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat,
61 sizeMapPopup(description),
62 "<p style='padding-right: 28px'>" + description + "</p>",
64 popup.setBackgroundColor("#E3FFC5");
70 function closeMapPopup() {
72 map.removePopup(popup);
77 function sizeMapPopup(text) {
78 var box = document.createElement("div");
81 box.style.visibility = "hidden";
82 box.style.position = "absolute";
83 box.style.top = "0px";
84 box.style.left = "0px";
85 box.style.width = "200px";
86 box.style.height = "auto";
88 document.body.appendChild(box);
90 var width = box.offsetWidth;
91 var height = box.offsetHeight;
93 document.body.removeChild(box);
95 return new OpenLayers.Size(width + 30, height + 24);
98 function removeMarkerFromMap(marker){
99 markers.removeMarker(marker);
102 function getMapLayers() {
105 for (var i=0; i< this.map.layers.length; i++) {
106 var layer = this.map.layers[i];
108 if (layer.isBaseLayer) {
109 layers += (layer == this.map.baseLayer) ? "B" : "0";
111 layers += (layer.getVisibility()) ? "T" : "F";
118 function setMapLayers(layers) {
119 for (var i=0; i < layers.length; i++) {
120 var layer = map.layers[i];
121 var c = layers.charAt(i);
124 map.setBaseLayer(layer);
125 } else if ( (c == "T") || (c == "F") ) {
126 layer.setVisibility(c == "T");
131 function mercatorToLonLat(merc) {
132 var lon = (merc.lon / 20037508.34) * 180;
133 var lat = (merc.lat / 20037508.34) * 180;
135 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
137 return new OpenLayers.LonLat(lon, lat);
140 function lonLatToMercator(ll) {
141 var lon = ll.lon * 20037508.34 / 180;
142 var lat = Math.log(Math.tan((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
144 lat = lat * 20037508.34 / 180;
146 return new OpenLayers.LonLat(lon, lat);
149 // for interacting with the PostGIS database which uses non spherical
150 // Mercator. Taken from Freemap which in turn was taken from a standard
151 // algorithm off the net.
153 function lonLatToNonSphericalMercator(ll) {
154 var custLat = ll.lat * (Math.PI/180);
156 var b = 6356752.3142;
158 var e = Math.sqrt(2*f-Math.pow(f,2));
159 custLat=a*Math.log(Math.tan(Math.PI/4+custLat/2)*
160 Math.pow(( (1-e*Math.sin(custLat)) / (1+e*Math.sin(custLat))),e/2));
161 custLon = ll.lon * (Math.PI/180) * 6378137;
162 return new OpenLayers.LonLat (custLon,custLat);
165 function nonSphericalMercatorToLonLat(merc) {
166 var lon_deg, lat_deg;
168 var b = 6356752.3142;
172 var e = Math.sqrt(es);
178 lat_deg = phi2(Math.exp(-lat_deg/k0), e);
179 lon_deg *= (180/M_PI);
180 lat_deg *= (180/M_PI);
181 return new OpenLayers.LonLat(lon_deg,lat_deg);
184 function phi2 (ts,e) {
186 var Phi = (PI/2) - 2.0*Math.atan(ts);
190 var con = e*Math.sin(Phi);
191 dphi = (PI/2) - 2.0*Math.atan(ts*Math.pow((1.0-con)/(1.0+con),eccnth))
195 while(Math.abs(dphi) > 0.0000000001 && --i);
199 function scaleToZoom(scale) {
200 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);