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 var newLayer = new OpenLayers.Layer.OSM("Local Tiles", options.mapurl, {numZoomLevels: 19, isBaseLayer: true});
42 map.addLayer(newLayer);
44 map.addLayer(new OpenLayers.Layer.OSM());
47 if (options.format == 'CSV') {
48 pois = new OpenLayers.Layer.Text( "CSV",
49 { location: options.csvurl,
50 projection: map.displayProjection
52 } else if (options.format == 'GeoJSON') {
53 pois = new OpenLayers.Layer.Vector("GeoJSON", {
54 protocol: new OpenLayers.Protocol.HTTP({
56 format: new OpenLayers.Format.GeoJSON()
58 strategies: [new OpenLayers.Strategy.Fixed()]
61 pois = new OpenLayers.Layer.Vector("KML", {
62 protocol: new OpenLayers.Protocol.HTTP({
64 format: new OpenLayers.Format.KML({
66 extractAttributes: true
69 strategies: [new OpenLayers.Strategy.Fixed()]});
72 select = new OpenLayers.Control.SelectFeature(pois);
73 map.addControl(select);
77 "featureselected": function (event) {
78 var feature = event.feature;
79 var content = '<h2><a href="' + feature.attributes.href + '">' +feature.attributes.name + "</a></h2>" + feature.attributes.description;
80 popup = new OpenLayers.Popup.FramedCloud("chicken",
81 feature.geometry.getBounds().getCenterLonLat(),
82 new OpenLayers.Size(100,100),
84 null, true, function () {select.unselectAll()});
85 feature.popup = popup;
88 "featureunselected": function (event) {
89 var feature = event.feature;
91 map.removePopup(feature.popup);
92 feature.popup.destroy();
98 if (options.editable) {
99 vlayer = new OpenLayers.Layer.Vector( "Editable" );
100 map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
101 map.addLayer(vlayer);
104 if (options.fullscreen) {
105 map.addControl(new OpenLayers.Control.PanZoomBar());
106 map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
107 map.addControl(new OpenLayers.Control.MousePosition());
108 map.addControl(new OpenLayers.Control.KeyboardDefaults());
110 map.addControl(new OpenLayers.Control.ZoomPanel());
113 //Set start centrepoint and zoom
114 if (!options.lat || !options.lon) {
115 options.lat = urlParams['lat'];
116 options.lon = urlParams['lon'];
119 options.zoom = urlParams['zoom'];
121 if (options.lat && options.lon) {
122 var lat = options.lat;
123 var lon = options.lon;
124 var zoom= options.zoom || 10;
125 center = new OpenLayers.LonLat( lon, lat ).transform(
126 new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
127 map.getProjectionObject() // to Spherical Mercator Projection
129 map.setCenter (center, zoom);
131 pois.events.register("loadend", this, function () { map.zoomToExtent(pois.getDataExtent()); });