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(),
27 new OpenLayers.Control.ScaleLine({geodesic: true})
30 maxResolution: 156543.0339,
32 displayProjection: new OpenLayers.Projection("EPSG:4326")
35 var mapnik = new OpenLayers.Layer.OSM.Mapnik(i18n("javascripts.map.base.mapnik"), {
37 displayOutsideMaxExtent: true,
43 var osmarender = new OpenLayers.Layer.OSM.Osmarender(i18n("javascripts.map.base.osmarender"), {
45 displayOutsideMaxExtent: true,
49 map.addLayer(osmarender);
51 var cyclemap = new OpenLayers.Layer.OSM.CycleMap(i18n("javascripts.map.base.cycle_map"), {
53 displayOutsideMaxExtent: true,
57 map.addLayer(cyclemap);
59 var nonamekey = nonamekeys[document.domain];
60 var noname = new OpenLayers.Layer.OSM(i18n("javascripts.map.base.noname"), [
61 "http://a.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
62 "http://b.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png",
63 "http://c.tile.cloudmade.com/" + nonamekey + "/3/256/${z}/${x}/${y}.png"
65 displayOutsideMaxExtent: true,
72 var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
74 markers = new OpenLayers.Layer.Markers("Markers", {
75 displayInLayerSwitcher: false,
76 numZoomLevels: numZoomLevels,
77 maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
78 maxResolution: 156543,
80 projection: "EPSG:900913"
82 map.addLayer(markers);
87 function getArrowIcon() {
88 var size = new OpenLayers.Size(25, 22);
89 var offset = new OpenLayers.Pixel(-30, -27);
90 var icon = new OpenLayers.Icon("/images/arrow.png", size, offset);
95 function addMarkerToMap(position, icon, description) {
96 var marker = new OpenLayers.Marker(position.clone().transform(epsg4326, map.getProjectionObject()), icon);
98 markers.addMarker(marker);
101 marker.events.register("mouseover", marker, function() { openMapPopup(marker, description) });
102 marker.events.register("mouseout", marker, function() { closeMapPopup() });
108 function addObjectToMap(url, zoom, callback) {
109 var layer = new OpenLayers.Layer.GML("Objects", url, {
110 format: OpenLayers.Format.OSM,
116 fillColor: "lightblue",
119 projection: new OpenLayers.Projection("EPSG:4326"),
120 displayInLayerSwitcher: false
123 layer.events.register("loadend", layer, function() {
126 if (this.features.length) {
127 extent = this.features[0].geometry.getBounds();
129 for (var i = 1; i < this.features.length; i++) {
130 extent.extend(this.features[i].geometry.getBounds());
135 this.map.zoomToExtent(extent);
137 this.map.zoomToMaxExtent();
152 function addBoxToMap(boxbounds, attributes, line) {
154 // Be aware that IE requires Vector layers be initialised on page load, and not under deferred script conditions
155 vectors = new OpenLayers.Layer.Vector("Boxes", {
156 displayInLayerSwitcher: false
158 map.addLayer(vectors);
163 vertices = boxbounds.toGeometry().getVertices();
164 vertices.push( new OpenLayers.Geometry.Point( vertices[0].x, vertices[0].y ) );
165 geometry = new OpenLayers.Geometry.LineString(vertices).transform(epsg4326, map.getProjectionObject());
167 geometry = boxbounds.toGeometry().transform(epsg4326, map.getProjectionObject());
169 var box = new OpenLayers.Feature.Vector(geometry, attributes, {
171 strokeColor: '#ee9900',
175 vectors.addFeatures(box);
180 function openMapPopup(marker, description) {
183 popup = new OpenLayers.Popup.FramedCloud("popup", marker.lonlat, null,
184 description, marker.icon, true);
185 popup.setBackgroundColor("#E3FFC5");
191 function closeMapPopup() {
193 map.removePopup(popup);
198 function removeMarkerFromMap(marker){
199 markers.removeMarker(marker);
202 function removeBoxFromMap(box){
203 vectors.removeFeature(box);
206 function getMapCenter() {
207 return map.getCenter().clone().transform(map.getProjectionObject(), epsg4326);
210 function setMapCenter(center, zoom) {
211 zoom = parseInt(zoom);
212 var numzoom = map.getNumZoomLevels();
213 if (zoom >= numzoom) zoom = numzoom - 1;
214 map.setCenter(center.clone().transform(epsg4326, map.getProjectionObject()), zoom);
217 function setMapExtent(extent) {
218 map.zoomToExtent(extent.clone().transform(epsg4326, map.getProjectionObject()));
221 function getMapExtent() {
222 return map.getExtent().clone().transform(map.getProjectionObject(), epsg4326);
225 function getMapZoom() {
226 return map.getZoom();
229 function getEventPosition(event) {
230 return map.getLonLatFromViewPortPx(event.xy).clone().transform(map.getProjectionObject(), epsg4326);
233 function getMapLayers() {
234 var layerConfig = "";
236 for (var i = 0; i < map.layers.length; i++) {
237 if (map.layers[i].layerCode && map.layers[i].getVisibility()) {
238 layerConfig += map.layers[i].layerCode;
245 function setMapLayers(layerConfig) {
246 if (layerConfig.charAt(0) == "B" || layerConfig.charAt(0) == "0") {
249 for (var layers = map.getLayersBy("isBaseLayer", true), i = 0; i < layers.length; i++) {
250 var c = layerConfig.charAt(l++);
253 map.setBaseLayer(layers[i]);
257 for (var i = 0; i < map.layers.length; i++) {
258 if (map.layers[i].layerCode) {
259 if (layerConfig.indexOf(map.layers[i].layerCode) >= 0) {
260 if (map.layers[i].isBaseLayer) {
261 map.setBaseLayer(map.layers[i]);
263 map.layers[i].setVisibility(true);
266 map.layers[i].setVisibility(false);
273 function scaleToZoom(scale) {
274 return Math.log(360.0/(scale * 512.0)) / Math.log(2.0);