1 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
8 'openstreetmap.org': '2f59745a6b525b4ebdb100891d5b6711',
9 'www.openstreetmap.org': 'fd093e52f0965d46bb1c6c6281022199',
10 'openstreetmap.com': '4c60e7f5f31c576a9bb8da71c8d61152',
11 'www.openstreetmap.com': '142f25a0770a51a9a400b3513834a199',
12 'openstreetmap.net': '687c58fd1d715596bfc94abe653d8ac0',
13 'www.openstreetmap.net': '0bd1654141c85d30b9c2ccdb5302f2e4'
16 OpenLayers._getScriptLocation = function () {
17 // Should really have this file as an erb, so that this can return
18 // the real rails root
19 return "/openlayers/";
22 function createMap(divName, options) {
23 options = options || {};
25 map = new OpenLayers.Map(divName, {
26 controls: options.controls || [
27 new OpenLayers.Control.ArgParser(),
28 new OpenLayers.Control.Attribution(),
29 new OpenLayers.Control.LayerSwitcher(),
30 new OpenLayers.Control.Navigation(),
31 new OpenLayers.Control.PanZoomBar(),
32 new OpenLayers.Control.ScaleLine()
35 maxResolution: 156543.0339,
37 displayProjection: new OpenLayers.Projection("EPSG:4326")
40 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
41 displayOutsideMaxExtent: true,
46 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
47 displayOutsideMaxExtent: true,
50 map.addLayer(osmarender);
52 var cyclemap = new OpenLayers.Layer.OSM.CycleMap("Cycle Map", {
53 displayOutsideMaxExtent: true,
56 map.addLayer(cyclemap);
58 var nonamekey = nonamekeys[document.domain];
59 var noname = new OpenLayers.Layer.OSM("NoName", [
60 "http://a.tile.cloudmade.com/" + nonamekey + "/3/256/",
61 "http://b.tile.cloudmade.com/" + nonamekey + "/3/256/",
62 "http://c.tile.cloudmade.com/" + nonamekey + "/3/256/"
64 displayOutsideMaxExtent: true,
70 var maplint = new OpenLayers.Layer.OSM.Maplint("Maplint", {
71 displayOutsideMaxExtent: true,
74 map.addLayer(maplint);
76 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
78 markers = new OpenLayers.Layer.Markers("Markers", {
79 displayInLayerSwitcher: false,
80 numZoomLevels: numZoomLevels,
81 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
82 maxResolution: 156543,
84 projection: "EPSG:900913"
86 map.addLayer(markers);
91 function getArrowIcon() {
92 var size = new OpenLayers.Size(25, 22);
93 var offset = new OpenLayers.Pixel(-30, -27);
94 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
99 function addMarkerToMap(position, icon, description) {
100 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
102 markers.addMarker(marker);
105 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
111 function addBoxToMap(boxbounds) {
113 // Be aware that IE requires Vector layers be initialised on page load, and not under deferred script conditions
114 vectors = new OpenLayers.Layer.Vector("Box Layer", {
115 displayInLayerSwitcher: false
117 map.addLayer(vectors);
119 var geometry = boxbounds.toGeometry().transform(epsg4326, map.getProjectionObject());
120 var box = new OpenLayers.Feature.Vector(geometry, {}, {
122 strokeColor: '#ee9900',
126 vectors.addFeatures(box);
131 function openMapPopup(marker, description) {
134 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, null,
135 description, marker.icon, true);
136 popup.setBackgroundColor("#E3FFC5");
137 popup.autoSize = true;
143 function closeMapPopup() {
145 map.removePopup(popup);
150 function removeMarkerFromMap(marker){
151 markers.removeMarker(marker);
154 function removeBoxFromMap(box){
155 vectors.removeFeature(box);
158 function getMapCenter(center, zoom) {
159 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
162 function setMapCenter(center, zoom) {
163 zoom = parseInt(zoom);
164 var numzoom = map.getNumZoomLevels();
165 if (zoom >= numzoom) zoom = numzoom - 1;
166 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
169 function setMapExtent(extent) {
170 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
173 function getMapExtent() {
174 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
177 function getEventPosition(event) {
178 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
181 function getMapLayers() {
182 var layerConfig = "";
184 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
185 layerConfig += layers[i] == map.baseLayer ? "B" : "0";
188 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
189 layerConfig += layers[i].getVisibility() ? "T" : "F";
195 function setMapLayers(layerConfig) {
198 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
199 var c = layerConfig.charAt(l++);
202 map.setBaseLayer(layers[i]);
206 while (layerConfig.charAt(l) == "B" || layerConfig.charAt(l) == "0") {
210 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
211 var c = layerConfig.charAt(l++);
214 layers[i].setVisibility(true);
215 } else if(c == "F") {
216 layers[i].setVisibility(false);
221 function scaleToZoom(scale) {
222 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);