Remember which layers are active in the cookie and URLs.
This commit is contained in:
parent
04488fec2c
commit
9634ab8fc1
3 changed files with 47 additions and 9 deletions
|
@ -10,12 +10,14 @@
|
|||
<% lon = params['lon'] %>
|
||||
<% lat = params['lat'] %>
|
||||
<% zoom = params['zoom'] || '5' %>
|
||||
<% layers = params['layers'] %>
|
||||
<% elsif params['mlon'] and params['mlat'] %>
|
||||
<% lon = params['mlon'] %>
|
||||
<% lat = params['mlat'] %>
|
||||
<% zoom = params['zoom'] || '12' %>
|
||||
<% layers = params['layers'] %>
|
||||
<% elsif cookies.key?("location") %>
|
||||
<% lon,lat,zoom = cookies["location"].value.first.split(",") %>
|
||||
<% lon,lat,zoom,layers = cookies["location"].value.first.split(",") %>
|
||||
<% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
|
||||
<% lon = @user.home_lon %>
|
||||
<% lat = @user.home_lat %>
|
||||
|
@ -24,6 +26,7 @@
|
|||
<% lon = '-0.1' %>
|
||||
<% lat = '51.5' %>
|
||||
<% zoom = params['zoom'] || '5' %>
|
||||
<% layers = params['layers'] %>
|
||||
<% end %>
|
||||
|
||||
<script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
|
||||
|
@ -42,6 +45,7 @@
|
|||
function init(){
|
||||
var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
|
||||
var zoom = <%= zoom %>;
|
||||
var layers = "<%= layers %>";
|
||||
|
||||
<% if params['scale'] and params['scale'].length > 0 then %>
|
||||
zoom = scaleToZoom(<%= params['scale'].to_f() %>);
|
||||
|
@ -53,6 +57,10 @@
|
|||
addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
|
||||
<% end %>
|
||||
|
||||
<% if layers %>
|
||||
setMapLayers(layers);
|
||||
<% end %>
|
||||
|
||||
map.events.register("moveend", map, updateLocation);
|
||||
updateLocation();
|
||||
|
||||
|
@ -73,10 +81,11 @@
|
|||
function updateLocation() {
|
||||
var lonlat = mercatorToLonLat(map.getCenter());
|
||||
var zoom = map.getZoom();
|
||||
var layers = getMapLayers();
|
||||
|
||||
updatelinks(lonlat.lon, lonlat.lat, zoom);
|
||||
updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
|
||||
|
||||
document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom;
|
||||
document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
|
||||
}
|
||||
|
||||
function getStyle( el, property ) {
|
||||
|
|
|
@ -24,6 +24,9 @@ function createMap(divName, centre, zoom) {
|
|||
{ type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
|
||||
map.addLayer(osmarender);
|
||||
|
||||
markers = new OpenLayers.Layer.Markers("markers", { visibility: false });
|
||||
map.addLayer(markers);
|
||||
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.setCenter(centre, zoom);
|
||||
|
||||
|
@ -50,14 +53,10 @@ function getTileURL(bounds) {
|
|||
}
|
||||
|
||||
function addMarkerToMap(position, icon, description) {
|
||||
if (markers == null) {
|
||||
markers = new OpenLayers.Layer.Markers("markers");
|
||||
map.addLayer(markers);
|
||||
}
|
||||
|
||||
var marker = new OpenLayers.Marker(position, icon);
|
||||
|
||||
markers.addMarker(marker);
|
||||
markers.setVisibility(true);
|
||||
|
||||
if (description) {
|
||||
marker.events.register("click", marker, function() { openMapPopup(marker, description) });
|
||||
|
@ -96,6 +95,35 @@ function removeMarkerFromMap(marker){
|
|||
markers.removeMarker(marker);
|
||||
}
|
||||
|
||||
function getMapLayers() {
|
||||
var layers = "";
|
||||
|
||||
for (var i=0; i< this.map.layers.length; i++) {
|
||||
var layer = this.map.layers[i];
|
||||
|
||||
if (layer.isBaseLayer) {
|
||||
layers += (layer == this.map.baseLayer) ? "B" : "0";
|
||||
} else {
|
||||
layers += (layer.getVisibility()) ? "T" : "F";
|
||||
}
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
function setMapLayers(layers) {
|
||||
for (var i=0; i < layers.length; i++) {
|
||||
var layer = map.layers[i];
|
||||
var c = layers.charAt(i);
|
||||
|
||||
if (c == "B") {
|
||||
map.setBaseLayer(layer);
|
||||
} else if ( (c == "T") || (c == "F") ) {
|
||||
layer.setVisibility(c == "T");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mercatorToLonLat(merc) {
|
||||
var lon = (merc.lon / 20037508.34) * 180;
|
||||
var lat = (merc.lat / 20037508.34) * 180;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function updatelinks(lon,lat,zoom) {
|
||||
function updatelinks(lon,lat,zoom,layers) {
|
||||
var links = new Object();
|
||||
links['viewanchor'] = '/index.html';
|
||||
//links['editanchor'] = 'edit.html';
|
||||
|
@ -16,6 +16,7 @@ function updatelinks(lon,lat,zoom) {
|
|||
args["lat"] = lat;
|
||||
args["lon"] = lon;
|
||||
args["zoom"] = zoom;
|
||||
args["layers"] = layers;
|
||||
node.href = setArgs(node.href, args);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue