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"),
41 map.addLayer(new OpenLayers.Layer.OSM());
42 if (options.format == 'CSV') {
43 pois = new OpenLayers.Layer.Text( "CSV",
44 { location: options.csvurl,
45 projection: map.displayProjection
47 } else if (options.format == 'GeoJSON') {
48 pois = new OpenLayers.Layer.Vector("GeoJSON", {
49 protocol: new OpenLayers.Protocol.HTTP({
51 format: new OpenLayers.Format.GeoJSON()
53 strategies: [new OpenLayers.Strategy.Fixed()]
56 pois = new OpenLayers.Layer.Vector("KML", {
57 protocol: new OpenLayers.Protocol.HTTP({
59 format: new OpenLayers.Format.KML({
61 extractAttributes: true
64 strategies: [new OpenLayers.Strategy.Fixed()]});
67 select = new OpenLayers.Control.SelectFeature(pois);
68 map.addControl(select);
72 "featureselected": function (event) {
73 var feature = event.feature;
74 var content = '<h2><a href="' + feature.attributes.href + '">' +feature.attributes.name + "</a></h2>" + feature.attributes.description;
75 popup = new OpenLayers.Popup.FramedCloud("chicken",
76 feature.geometry.getBounds().getCenterLonLat(),
77 new OpenLayers.Size(100,100),
79 null, true, function () {select.unselectAll()});
80 feature.popup = popup;
83 "featureunselected": function (event) {
84 var feature = event.feature;
86 map.removePopup(feature.popup);
87 feature.popup.destroy();
93 if (options.editable) {
94 vlayer = new OpenLayers.Layer.Vector( "Editable" );
95 map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
99 if (options.fullscreen) {
100 map.addControl(new OpenLayers.Control.PanZoomBar());
101 map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
102 map.addControl(new OpenLayers.Control.MousePosition());
103 map.addControl(new OpenLayers.Control.KeyboardDefaults());
105 map.addControl(new OpenLayers.Control.ZoomPanel());
108 //Set start centrepoint and zoom
109 if (!options.lat || !options.lon) {
110 options.lat = urlParams['lat'];
111 options.lon = urlParams['lon'];
114 options.zoom = urlParams['zoom'];
116 if (options.lat && options.lon) {
117 var lat = options.lat;
118 var lon = options.lon;
119 var zoom= options.zoom || 10;
120 center = new OpenLayers.LonLat( lon, lat ).transform(
121 new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
122 map.getProjectionObject() // to Spherical Mercator Projection
124 map.setCenter (center, zoom);
126 pois.events.register("loadend", this, function () { map.zoomToExtent(pois.getDataExtent()); });