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,
36 displayProjection: new OpenLayers.Projection("EPSG:4326")
39 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
40 displayOutsideMaxExtent: true,
45 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
46 displayOutsideMaxExtent: true,
49 map.addLayer(osmarender);
51 var cyclemap = new OpenLayers.Layer.OSM.CycleMap("Cycle Map", {
52 displayOutsideMaxExtent: true,
55 map.addLayer(cyclemap);
57 var nonamekey = nonamekeys[document.domain];
58 var noname = new OpenLayers.Layer.OSM("NoName", [
59 "http://a.tile.cloudmade.com/" + nonamekey + "/3/256/",
60 "http://b.tile.cloudmade.com/" + nonamekey + "/3/256/",
61 "http://c.tile.cloudmade.com/" + nonamekey + "/3/256/"
63 displayOutsideMaxExtent: true,
69 var maplint = new OpenLayers.Layer.OSM.Maplint("Maplint", {
70 displayOutsideMaxExtent: true,
73 map.addLayer(maplint);
75 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
76 markers = new OpenLayers.Layer.Markers("Markers", {
77 displayInLayerSwitcher: false,
78 numZoomLevels: numZoomLevels,
79 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
80 maxResolution: 156543,
82 projection: "EPSG:900913"
84 map.addLayer(markers);
89 function getArrowIcon() {
90 var size = new OpenLayers.Size(25, 22);
91 var offset = new OpenLayers.Pixel(-30, -27);
92 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
97 function addMarkerToMap(position, icon, description) {
98 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
100 markers.addMarker(marker);
103 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
109 function openMapPopup(marker, description) {
112 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, null,
113 description, marker.icon, true);
114 popup.setBackgroundColor("#E3FFC5");
115 popup.autoSize = true;
121 function closeMapPopup() {
123 map.removePopup(popup);
128 function removeMarkerFromMap(marker){
129 markers.removeMarker(marker);
132 function getMapCenter(center, zoom) {
133 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
136 function setMapCenter(center, zoom) {
137 var numzoom = map.getNumZoomLevels();
138 if (zoom >= numzoom) zoom = numzoom - 1;
139 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
142 function setMapExtent(extent) {
143 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
146 function getMapExtent(extent) {
147 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
150 function getEventPosition(event) {
151 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
154 function getMapLayers() {
155 var layerConfig = "";
157 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
158 layerConfig += layers[i] == map.baseLayer ? "B" : "0";
161 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
162 layerConfig += layers[i].getVisibility() ? "T" : "F";
168 function setMapLayers(layerConfig) {
171 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
172 var c = layerConfig.charAt(l++);
175 map.setBaseLayer(layers[i]);
179 while (layerConfig.charAt(l) == "B" || layerConfig.charAt(l) == "0") {
183 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
184 var c = layerConfig.charAt(l++);
187 layers[i].setVisibility(true);
188 } else if(c == "F") {
189 layers[i].setVisibility(false);
194 function scaleToZoom(scale) {
195 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);