//= require jquery.cookie
//= require jquery.throttle-debounce
//= require augment
+//= require osm
//= require leaflet
//= require leaflet.osm
//= require leaflet.hash
//= require leaflet.locationfilter
//= require i18n/translations
//= require oauth
-//= require osm
//= require piwik
//= require map
//= require menu
*/
function updatelinks(loc, zoom, layers, bounds, object) {
$(".geolink").each(function(index, link) {
- var base = link.href.split('?')[0],
+ var href = link.href.split(/[?#]/)[0],
args = querystring.parse(link.search.substring(1));
if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
- if (layers && $(link).hasClass("layers")) args.layers = layers;
if (object && $(link).hasClass("object")) args[object.type] = object.id;
- var href = base + '?' + querystring.stringify(args);
+ var query = querystring.stringify(args);
+ if (query) href += '?' + query;
if ($(link).hasClass("llz")) {
- href += OSM.formatHash({lat: loc.lat, lon: loc.lon || loc.lng, zoom: zoom});
+ args = {
+ lat: loc.lat,
+ lon: loc.lon || loc.lng,
+ zoom: zoom
+ };
+
+ if (layers && $(link).hasClass("layers")) {
+ args.layers = layers;
+ }
+
+ href += OSM.formatHash(args);
}
link.href = href;
map.attributionControl.setPrefix('');
- new L.Hash(map);
+ map.hash = L.hash(map);
var layers = [
new L.OSM.Mapnik({
layers[0].addTo(map);
- map.noteLayer = new L.LayerGroup({code: 'N'});
+ map.noteLayer = new L.LayerGroup();
+ map.noteLayer.options = {code: 'N'};
+
map.dataLayer = new L.OSM.DataLayer(null);
+ map.dataLayer.options.code = 'D';
$("#sidebar").on("opened closed", function () {
map.invalidateSize();
}
initializeExport(map);
- initializeBrowse(map);
- initializeNotes(map);
+ initializeBrowse(map, params);
+ initializeNotes(map, params);
});
function updateLocation() {
var expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);
$.cookie("_osm_location", cookieContent(this), { expires: expiry });
+
+ // Trigger hash update on layer changes.
+ this.hash.onMapMove();
}
function setPositionLink(map) {
//= require templates/browse/feature_list
//= require templates/browse/feature_history
-function initializeBrowse(map) {
+function initializeBrowse(map, params) {
var browseBounds;
var layersById;
var selectedLayer;
}
});
+ if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
+ if (params.layers.indexOf(dataLayer.options.code) >= 0) {
+ map.addLayer(dataLayer);
+ }
+ }
+
function startBrowse(sidebarHtml) {
locationFilter = new L.LocationFilter({
enableButton: false,
//= require templates/notes/show
//= require templates/notes/new
-function initializeNotes(map) {
- var params = OSM.mapParams(),
- noteLayer = map.noteLayer,
+function initializeNotes(map, params) {
+ var noteLayer = map.noteLayer,
notes = {},
newNote;
});
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
- if (params.notes || (params.layers && params.layers.indexOf('N')) >= 0) {
+ if (params.layers.indexOf(noteLayer.options.code) >= 0) {
map.addLayer(noteLayer);
}
getUrl: function(marker) {
var precision = zoomPrecision(this.getZoom()),
- params = { layers: this.getLayersCode() };
+ params = {};
if (marker && this.hasLayer(marker)) {
params.mlat = marker.getLatLng().lat.toFixed(precision);
params.mlon = marker.getLatLng().lng.toFixed(precision);
}
- return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params) +
- OSM.formatHash({lat: this.getCenter().lat, lon: this.getCenter().lng, zoom: this.getZoom()});
+ var url = 'http://' + OSM.SERVER_URL + '/',
+ query = querystring.stringify(params),
+ hash = OSM.formatHash(this);
+
+ if (query) url += '?' + query;
+ if (hash) url += hash;
+
+ return url;
},
getShortUrl: function(marker) {
});
L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
+
+L.Hash.prototype.parseHash = OSM.parseHash;
+L.Hash.prototype.formatHash = OSM.formatHash;
mapParams.mlat = parseFloat(params.mlat);
}
- if (params.layers) {
- mapParams.layers = params.layers;
- }
-
if (params.node || params.way || params.relation) {
mapParams.object_zoom = true;
mapParams.box = bounds;
}
+ var hash = OSM.parseHash(location.hash);
+
// Decide on a map starting position. Various ways of doing this.
- var hash = L.Hash.parseHash(location.hash);
- if (hash) {
+ if (hash.lat && hash.lon) {
mapParams.lon = hash.center.lng;
mapParams.lat = hash.center.lat;
mapParams.zoom = hash.zoom;
mapParams.lon = parseFloat(loc[0]);
mapParams.lat = parseFloat(loc[1]);
mapParams.zoom = parseInt(loc[2]);
- mapParams.layers = loc[3];
} else if (OSM.home) {
mapParams.lon = OSM.home.lon;
mapParams.lat = OSM.home.lat;
mapParams.zoom = parseInt(params.zoom || 5);
}
- mapParams.notes = params.notes == "yes";
+ mapParams.layers = hash.layers || (loc && loc[3]) || '';
if (params.note) {
mapParams.note = parseInt(params.note);
return mapParams;
},
+ parseHash: function(hash) {
+ if (hash.indexOf('#') === 0) {
+ hash = hash.substr(1);
+ }
+ hash = querystring.parse(hash);
+ var args = L.Hash.parseHash(hash.map || '') || {};
+ if (hash.layers) args.layers = hash.layers;
+ return args;
+ },
+
formatHash: function(args) {
- var precision = zoomPrecision(args.zoom);
- return '#' + args.zoom +
- '/' + args.lat.toFixed(precision) +
- '/' + args.lon.toFixed(precision);
+ if (args instanceof L.Map) {
+ args = {
+ lat: args.getCenter().lat,
+ lon: args.getCenter().lng,
+ zoom: args.getZoom(),
+ layers: args.getLayersCode()
+ };
+ }
+
+ var precision = zoomPrecision(args.zoom),
+ hash = '#map=' + args.zoom +
+ '/' + args.lat.toFixed(precision) +
+ '/' + args.lon.toFixed(precision);
+
+ if (args.layers) {
+ args.layers = args.layers.replace('M', '');
+ }
+
+ if (args.layers) {
+ hash += '&layers=' + args.layers;
+ }
+
+ return hash;
}
};
before_filter :require_oauth, :only => [:index]
def index
+ anchor = []
+
if params[:lat] && params[:lon]
- params[:anchor] = "#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
- redirect_to params
+ anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
+ end
+
+ if params[:layers]
+ anchor << "layers=#{params.delete(:layers)}"
+ elsif params.delete(:notes) == 'yes'
+ anchor << "layers=N"
+ end
+
+ if anchor.present?
+ redirect_to params.merge(:anchor => anchor.join('&'))
return
end
def test_index_redirect
get :index, :lat => 4, :lon => 5
- assert_redirected_to :controller => :site, :action => 'index', :anchor => '5/4/5'
+ assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=5/4/5'
get :index, :lat => 4, :lon => 5, :zoom => 3
- assert_redirected_to :controller => :site, :action => 'index', :anchor => '3/4/5'
+ assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5'
+
+ get :index, :layers => 'T'
+ assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=T'
+
+ get :index, :notes => 'yes'
+ assert_redirected_to :controller => :site, :action => 'index', :anchor => 'layers=N'
+
+ get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
+ assert_redirected_to :controller => :site, :action => 'index', :anchor => 'map=3/4/5&layers=T'
end
def test_permalink