From 67a65eec98848189662b0b7c68c0dfcffc74d566 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Wed, 22 Feb 2012 06:27:36 -0800 Subject: [PATCH] Add a permalink that opens the relevant view in OSM.org in a different window --- chaloBEST/static/js/editstops.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index ddd4b0e..8051b27 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -233,7 +233,8 @@ var API_BASE = "/1.0/", function initMap() { var center = new OpenLayers.LonLat(8110203.9998955, 2170000.4068373); map = new OpenLayers.Map("mapCol", { - projection: new OpenLayers.Projection("EPSG:900913") + projection: new OpenLayers.Projection("EPSG:900913"), + displayProjection: new OpenLayers.Projection("EPSG:4326") }); var layers = []; // layers[0] = new OpenLayers.Layer.OSM(); @@ -245,9 +246,15 @@ var API_BASE = "/1.0/", key: "AqGpO7N9ioFw3YHoPV3C8crGfJqW5YST4gGKgIOnijrUbitLlgcAS2A0M9SJrUv9", }); geojson_format = new OpenLayers.Format.GeoJSON(); + // //yes, jsonLayer is global. Yes, I know it's wrong. jsonLayer = layers[2] = new OpenLayers.Layer.Vector("Bus Stops"); map.addLayers(layers); + jsonLayer.events.on({ + 'featureselected': onFeatureSelect, + 'featureunselected': onFeatureUnselect + }); + map.setCenter(center, 12); var navigationControl = new OpenLayers.Control.Navigation({ defaultDblClick: function(event) { @@ -274,28 +281,30 @@ var API_BASE = "/1.0/", var pt = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat); var feature = new OpenLayers.Feature.Vector(pt, stop); $('.selectedStop').removeClass("no_has_point").addClass("has_point"); - //console.log("trying to add", feature); jsonLayer.addFeatures([feature]); mapControl.select(feature); } -// console.log(lonlat); return; } }); map.addControl(navigationControl); + + // Feature selection control mapControl = new OpenLayers.Control.SelectFeature(jsonLayer, { clickout: false, toggle: true }); - map.addControl(new OpenLayers.Control.LayerSwitcher()); map.addControl(mapControl); - // map.addControl(zoomControl); mapControl.activate(); - // zoomControl.activate(); - jsonLayer.events.on({ - 'featureselected': onFeatureSelect, - 'featureunselected': onFeatureUnselect - }); + + // Add a LayerSwitcher since we now have Bing + map.addControl(new OpenLayers.Control.LayerSwitcher()); + + // Add a permalink that opens the relevant view in OSM.org in a different window + var permalink = new OpenLayers.Control.Permalink({base: "http://www.openstreetmap.org/"}); + map.addControl(permalink); + $(".olControlPermalink a").attr("target","_blank").html("View in OSM"); + } function onFeatureSelect(e) {