1 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
7 'openstreetmap.org': '2f59745a6b525b4ebdb100891d5b6711',
8 'www.openstreetmap.org': 'fd093e52f0965d46bb1c6c6281022199',
9 'openstreetmap.com': '4c60e7f5f31c576a9bb8da71c8d61152',
10 'www.openstreetmap.com': '142f25a0770a51a9a400b3513834a199',
11 'openstreetmap.net': '687c58fd1d715596bfc94abe653d8ac0',
12 'www.openstreetmap.net': '0bd1654141c85d30b9c2ccdb5302f2e4'
15 OpenLayers._getScriptLocation = function () {
16 // Should really have this file as an erb, so that this can return
17 // the real rails root
18 return "/openlayers/";
21 function createMap(divName, options) {
22 options = options || {};
24 map = new OpenLayers.Map(divName, {
25 controls: options.controls || [
26 new OpenLayers.Control.ArgParser(),
27 new OpenLayers.Control.Attribution(),
28 new OpenLayers.Control.LayerSwitcher(),
29 new OpenLayers.Control.Navigation(),
30 new OpenLayers.Control.PanZoomBar(),
31 new OpenLayers.Control.ScaleLine()
34 maxResolution: 156543.0339,
38 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
39 displayOutsideMaxExtent: true,
44 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
45 displayOutsideMaxExtent: true,
48 map.addLayer(osmarender);
50 var cyclemap = new OpenLayers.Layer.OSM.CycleMap("Cycle Map", {
51 displayOutsideMaxExtent: true,
54 map.addLayer(cyclemap);
56 var nonamekey = nonamekeys[document.domain];
57 var noname = new OpenLayers.Layer.OSM("NoName", [
58 "http://a.tile.cloudmade.com/" + nonamekey + "/3/256/",
59 "http://b.tile.cloudmade.com/" + nonamekey + "/3/256/",
60 "http://c.tile.cloudmade.com/" + nonamekey + "/3/256/"
62 displayOutsideMaxExtent: true,
68 var maplint = new OpenLayers.Layer.OSM.Maplint("Maplint", {
69 displayOutsideMaxExtent: true,
72 map.addLayer(maplint);
74 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
75 markers = new OpenLayers.Layer.Markers("Markers", {
76 displayInLayerSwitcher: false,
77 numZoomLevels: numZoomLevels,
78 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
79 maxResolution: 156543,
81 projection: "EPSG:900913"
83 map.addLayer(markers);
88 function getArrowIcon() {
89 var size = new OpenLayers.Size(25, 22);
90 var offset = new OpenLayers.Pixel(-30, -27);
91 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
96 function addMarkerToMap(position, icon, description) {
97 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
99 markers.addMarker(marker);
102 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
108 function openMapPopup(marker, description) {
111 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, null,
112 description, marker.icon, true);
113 popup.setBackgroundColor("#E3FFC5");
114 popup.autoSize = true;
120 function closeMapPopup() {
122 map.removePopup(popup);
127 function removeMarkerFromMap(marker){
128 markers.removeMarker(marker);
131 function getMapCenter(center, zoom) {
132 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
135 function setMapCenter(center, zoom) {
136 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
139 function setMapExtent(extent) {
140 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
143 function getMapExtent(extent) {
144 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
147 function getEventPosition(event) {
148 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
151 function getMapLayers() {
152 var layerConfig = "";
154 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
155 layerConfig += layers[i] == map.baseLayer ? "B" : "0";
158 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
159 layerConfig += layers[i].getVisibility() ? "T" : "F";
165 function setMapLayers(layerConfig) {
168 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
169 var c = layerConfig.charAt(l++);
172 map.setBaseLayer(layers[i]);
176 while (layerConfig.charAt(l) == "B" || layerConfig.charAt(l) == "0") {
180 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
181 var c = layerConfig.charAt(l++);
184 layers[i].setVisibility(true);
185 } else if(c == "F") {
186 layers[i].setVisibility(false);
191 function scaleToZoom(scale) {
192 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);