1 // taken from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
5 a = /\\+/g, // Regex for replacing addition symbol with a space
6 r = /([^&=]+)=?([^&]*)/g,
7 d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
8 q = window.location.search.substring(1);
11 urlParams[d(e[1])] = d(e[2]);
14 function mapsetup(divname, options) {
15 div = document.getElementById(divname);
16 if (options.fullscreen) {
17 permalink = 'permalink';
20 div.style.position = 'absolute';
21 div.style.width = '100%';
22 div.style.height = '100%';
25 div.style.height = options.height;
26 div.style.width = options.width;
27 div.style.float = options.float;
28 permalink = {base: options.href, title: "View larger map"};
30 map = new OpenLayers.Map(divname, {
32 new OpenLayers.Control.Navigation(),
33 new OpenLayers.Control.ScaleLine(),
34 new OpenLayers.Control.Permalink(permalink)
36 displayProjection: new OpenLayers.Projection("EPSG:4326"),
37 maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
38 projection: "EPSG:900913",
40 maxResolution: 156543.0339,
45 var newLayer = new OpenLayers.Layer.OSM("Local Tiles", options.mapurl, {numZoomLevels: 19, isBaseLayer: true});
46 map.addLayer(newLayer);
48 map.addLayer(new OpenLayers.Layer.OSM());
51 // this nightmare is possible through http://docs.openlayers.org/library/spherical_mercator.html
52 if (options.google_apikey && options.google_apikey != 'null') {
53 googleLayer = new OpenLayers.Layer.Google(
56 'sphericalMercator': true,
57 'maxExtent': new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
58 projection: new OpenLayers.Projection("EPSG:3857")}
60 map.addLayer(googleLayer);
62 if (options.format == 'CSV') {
63 pois = new OpenLayers.Layer.Text( "CSV",
64 { location: options.csvurl,
65 projection: new OpenLayers.Projection("EPSG:4326")
67 } else if (options.format == 'GeoJSON') {
68 pois = new OpenLayers.Layer.Vector("GeoJSON", {
69 protocol: new OpenLayers.Protocol.HTTP({
71 format: new OpenLayers.Format.GeoJSON()
73 strategies: [new OpenLayers.Strategy.Fixed()],
74 projection: new OpenLayers.Projection("EPSG:4326")
77 pois = new OpenLayers.Layer.Vector("KML", {
78 protocol: new OpenLayers.Protocol.HTTP({
80 format: new OpenLayers.Format.KML({
82 extractAttributes: true
85 strategies: [new OpenLayers.Strategy.Fixed()],
86 projection: new OpenLayers.Projection("EPSG:4326")
90 select = new OpenLayers.Control.SelectFeature(pois);
91 map.addControl(select);
95 "featureselected": function (event) {
96 var feature = event.feature;
97 var content = '<h2><a href="' + feature.attributes.href + '">' +feature.attributes.name + "</a></h2>" + feature.attributes.description;
98 popup = new OpenLayers.Popup.FramedCloud("chicken",
99 feature.geometry.getBounds().getCenterLonLat(),
100 new OpenLayers.Size(100,100),
102 null, true, function () {select.unselectAll()});
103 feature.popup = popup;
106 "featureunselected": function (event) {
107 var feature = event.feature;
109 map.removePopup(feature.popup);
110 feature.popup.destroy();
111 delete feature.popup;
116 if (options.editable) {
117 vlayer = new OpenLayers.Layer.Vector( "Editable" );
118 map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
119 map.addLayer(vlayer);
122 if (options.fullscreen) {
123 map.addControl(new OpenLayers.Control.PanZoomBar());
124 map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
125 map.addControl(new OpenLayers.Control.MousePosition());
126 map.addControl(new OpenLayers.Control.KeyboardDefaults());
128 map.addControl(new OpenLayers.Control.ZoomPanel());
131 //Set start centrepoint and zoom
132 if (!options.lat || !options.lon) {
133 options.lat = urlParams['lat'];
134 options.lon = urlParams['lon'];
137 options.zoom = urlParams['zoom'];
139 if (options.lat && options.lon) {
140 var lat = options.lat;
141 var lon = options.lon;
142 var zoom= options.zoom || 10;
143 center = new OpenLayers.LonLat( lon, lat ).transform(
144 new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
145 map.getProjectionObject() // to Spherical Mercator Projection
147 map.setCenter (center, zoom);
149 pois.events.register("loadend", this, function () { map.zoomToExtent(pois.getDataExtent()); });