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 function createMap(divName, options) {
17 options = options || {};
19 map = new OpenLayers.Map(divName, {
20 controls: options.controls || [
21 new OpenLayers.Control.ArgParser(),
22 new OpenLayers.Control.Attribution(),
23 new OpenLayers.Control.LayerSwitcher(),
24 new OpenLayers.Control.Navigation(),
25 new OpenLayers.Control.PanZoom(),
26 new OpenLayers.Control.PanZoomBar()
29 maxResolution: 156543.0339,
31 displayProjection: new OpenLayers.Projection("EPSG:4326")
34 var mapnik = new OpenLayers.Layer.OSM.Mapnik(i18n("javascripts.map.base.mapnik"), {
35 displayOutsideMaxExtent: true,
40 var osmarender = new OpenLayers.Layer.OSM.Osmarender(i18n("javascripts.map.base.osmarender"), {
41 displayOutsideMaxExtent: true,
44 map.addLayer(osmarender);
46 var cyclemap = new OpenLayers.Layer.OSM.CycleMap(i18n("javascripts.map.base.cycle_map"), {
47 displayOutsideMaxExtent: true,
50 map.addLayer(cyclemap);
52 var nonamekey = nonamekeys[document.domain];
53 var noname = new OpenLayers.Layer.OSM(i18n("javascripts.map.base.noname"), [
54 "http://a.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
55 "http://b.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
56 "http://c.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png"
58 displayOutsideMaxExtent: true,
64 var maplint = new OpenLayers.Layer.OSM.Maplint(i18n("javascripts.map.overlays.maplint"), {
65 displayOutsideMaxExtent: true,
68 map.addLayer(maplint);
70 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
72 markers = new OpenLayers.Layer.Markers("Markers", {
73 displayInLayerSwitcher: false,
74 numZoomLevels: numZoomLevels,
75 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
76 maxResolution: 156543,
78 projection: "EPSG:900913"
80 map.addLayer(markers);
85 function getArrowIcon() {
86 var size = new OpenLayers.Size(25, 22);
87 var offset = new OpenLayers.Pixel(-30, -27);
88 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
93 function addMarkerToMap(position, icon, description) {
94 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
96 markers.addMarker(marker);
99 marker.events.register("click", marker, function() { openMapPopup(marker, description) });
105 function addObjectToMap(url, zoom, callback) {
106 var layer = new OpenLayers.Layer.GML("Objects", url, {
107 format: OpenLayers.Format.OSM,
113 fillColor: "lightblue",
116 projection: new OpenLayers.Projection("EPSG:4326"),
117 displayInLayerSwitcher: false
120 layer.events.register("loadend", layer, function() {
123 if (this.features.length) {
124 extent = this.features[0].geometry.getBounds();
126 for (var i = 1; i < this.features.length; i++) {
127 extent.extend(this.features[i].geometry.getBounds());
132 this.map.zoomToExtent(extent);
134 this.map.zoomToMaxExtent();
149 function addBoxToMap(boxbounds) {
151 // Be aware that IE requires Vector layers be initialised on page load, and not under deferred script conditions
152 vectors = new OpenLayers.Layer.Vector("Boxes", {
153 displayInLayerSwitcher: false
155 map.addLayer(vectors);
157 var geometry = boxbounds.toGeometry().transform(epsg4326, map.getProjectionObject());
158 var box = new OpenLayers.Feature.Vector(geometry, {}, {
160 strokeColor: '#ee9900',
164 vectors.addFeatures(box);
169 function openMapPopup(marker, description) {
172 popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, null,
173 description, marker.icon, true);
174 popup.setBackgroundColor("#E3FFC5");
175 popup.autoSize = true;
181 function closeMapPopup() {
183 map.removePopup(popup);
188 function removeMarkerFromMap(marker){
189 markers.removeMarker(marker);
192 function removeBoxFromMap(box){
193 vectors.removeFeature(box);
196 function getMapCenter() {
197 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
200 function setMapCenter(center, zoom) {
201 zoom = parseInt(zoom);
202 var numzoom = map.getNumZoomLevels();
203 if (zoom >= numzoom) zoom = numzoom - 1;
204 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
207 function setMapExtent(extent) {
208 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
211 function getMapExtent() {
212 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
215 function getMapZoom() {
216 return map.getZoom();
219 function getEventPosition(event) {
220 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
223 function getMapLayers() {
224 var layerConfig = "";
226 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
227 layerConfig += layers[i] == map.baseLayer ? "B" : "0";
230 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
231 layerConfig += layers[i].getVisibility() ? "T" : "F";
237 function setMapLayers(layerConfig) {
240 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
241 var c = layerConfig.charAt(l++);
244 map.setBaseLayer(layers[i]);
248 while (layerConfig.charAt(l) == "B" || layerConfig.charAt(l) == "0") {
252 for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
253 var c = layerConfig.charAt(l++);
256 layers[i].setVisibility(true);
257 } else if(c == "F") {
258 layers[i].setVisibility(false);
263 function scaleToZoom(scale) {
264 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);