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);
77 markers = new OpenLayers.Layer.Markers("Markers", {
78 displayInLayerSwitcher: false,
79 numZoomLevels: numZoomLevels,
80 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
81 maxResolution: 156543,
83 projection: "EPSG:900913"
85 map.addLayer(markers);
87 vectors = new OpenLayers.Layer.Vector("Vectors", {
88 displayInLayerSwitcher: false,
89 numZoomLevels: numZoomLevels,
90 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
91 maxResolution: 156543,
93 projection: "EPSG:900913"
95 map.addLayer(vectors);
101 function getArrowIcon() {
102 var size = new OpenLayers.Size(25, 22);
103 var offset = new OpenLayers.Pixel(-30, -27);
104 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
109 function addMarkerToMap(position, icon, description) {
110 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
112 markers.addMarker(marker);
115 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
121 function addBoxToMap(boxbounds) {
122 box = new OpenLayers.Feature.Vector(
123 boxbounds.toGeometry().transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()) );
127 'strokeColor': '#0000ff',
130 vectors.addFeatures(box);
134 function openMapPopup(marker, description) {
137 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, null,
138 description, marker.icon, true);
139 popup.setBackgroundColor("#E3FFC5");
140 popup.autoSize = true;
146 function closeMapPopup() {
148 map.removePopup(popup);
153 function removeMarkerFromMap(marker){
154 markers.removeMarker(marker);
157 function removeBoxFromMap(box){
158 vectors.removeFeature(box);
161 function getMapCenter(center, zoom) {
162 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
165 function setMapCenter(center, zoom) {
166 zoom = parseInt(zoom);
167 var numzoom = map.getNumZoomLevels();
168 if (zoom >= numzoom) zoom = numzoom - 1;
169 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
172 function setMapExtent(extent) {
173 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
176 function getMapExtent() {
177 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
180 function getEventPosition(event) {
181 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
184 function getMapLayers() {
185 var layerConfig = "";
187 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
188 layerConfig += layers[i] == map.baseLayer ? "B" : "0";
191 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
192 layerConfig += layers[i].getVisibility() ? "T" : "F";
198 function setMapLayers(layerConfig) {
201 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
202 var c = layerConfig.charAt(l++);
205 map.setBaseLayer(layers[i]);
209 while (layerConfig.charAt(l) == "B" || layerConfig.charAt(l) == "0") {
213 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
214 var c = layerConfig.charAt(l++);
217 layers[i].setVisibility(true);
218 } else if(c == "F") {
219 layers[i].setVisibility(false);
224 function scaleToZoom(scale) {
225 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);