Commit 1d79380e authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Save style and base layer in URL (closes #53)

parent 3889f9fd
......@@ -16,6 +16,7 @@ The query part contains global parameters, such as options, level, tile layer to
Description of available parameters:
* t: the tile layer to use (integer value starting from 0, corresponding to the tile layer index in `config.json`)
* l: the building level (float value, corresponding to `level` tag in OSM)
* s: the map style to use (string value corresponding to style file name)
* o: the options, one character corresponds to an activated boolean option. For example `o=nut` means show OSM notes, show objects without style, and objects going through levels. The available parameters are:
* t: show objects going through levels (like stairs or elevators)
* b: show only buildings
......
......@@ -90,6 +90,7 @@ var Main = function(divId, configFolder, mode) {
this.url.write();
options.level = (this.url.getParameter("level") != null) ? parseFloat(this.url.getParameter("level")) : undefined;
options.tile = (this.url.getParameter("tile") != null) ? parseInt(this.url.getParameter("tile")) : undefined;
options.style = (this.url.getParameter("style") != null) ? this.url.getParameter("style") : undefined;
/*
* Init main view
......@@ -113,6 +114,29 @@ var Main = function(divId, configFolder, mode) {
this.url.setParameter("level", this.view.level.level);
this.url.write();
}.bind(this));
this.view.map.on("basechanged", function(o) {
//Find tile ID in config
var tileId = -1;
var confId = 0;
while(tileId < 0 && confId < this.config.tiles.length) {
if(this.config.tiles[confId].name == o.base) {
tileId = confId;
}
confId++;
}
if(tileId >=0) {
this.url.setParameter("tile", tileId);
}
this.url.write();
}.bind(this));
this.view.map.on("stylechanged", function(o) {
this.url.setParameter("style", this.styles[o.style].olu_shortname);
this.url.write();
}.bind(this));
};
//OTHER METHODS
......@@ -155,8 +179,10 @@ Main.prototype._initConfig = function(folder) {
async: false,
dataType: 'text',
success: function(data) {
var shortname = this.styles[i].replace(".mapcss", "").toLowerCase();
this.styles[i] = new RuleSet();
this.styles[i].parseCSS(data);
this.styles[i].olu_shortname = shortname;
}.bind(this)
}).fail(function() { throw new Error("[Controller] Error while retrieving MapCSS file: "+this.styles[i]); }.bind(this));
}
......
......@@ -38,7 +38,7 @@ var URL = function(read, write) {
//CONSTANTS
/** Recognized read parameters **/
URL.VALID_PARAMETERS = [ "tile", "level", "transcend", "buildings", "pictures", "unrendered", "notes", "deprecated_lat", "deprecated_lon", "deprecated_zoom" ];
URL.VALID_PARAMETERS = [ "tile", "level", "style", "transcend", "buildings", "pictures", "unrendered", "notes", "deprecated_lat", "deprecated_lon", "deprecated_zoom" ];
/** Legacy base 62 conversion array **/
URL.BASE62 = [ "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" ];
......@@ -144,6 +144,7 @@ URL.prototype.read = function() {
//Store valid parameters
if(!isNaN(parseInt(params.t))) { this._url.tile = params.t; }
if(!isNaN(parseFloat(params.l))) { this._url.level = params.l; }
if(typeof params.s === "string") { this._url.style = params.s; }
//Boolean options
if(params.o != undefined) {
......@@ -170,6 +171,10 @@ URL.prototype.write = function() {
if(this._url.tile != undefined) { query += '&'; }
query += 'l='+this._url.level;
}
if(this._url.style != undefined) {
if(this._url.tile != undefined || this._url.level != undefined) { query += '&'; }
query += 's='+this._url.style;
}
//Write options
var opts = "";
......
......@@ -179,6 +179,24 @@ var Main = function(divId, mode, config, rulesets, newNoteService, searchService
/***************************************************************************
* Define tile layers
*/
//Restore style from URL parameters
if(this.options.style) {
//Find ruleset ID
var rId = -1;
var crId = 0;
while(rId < 0 && crId < this.rulesets.length) {
if(this.rulesets[crId].olu_shortname == this.options.style) {
rId = crId;
}
crId++;
}
if(rId >= 0) {
this.currentRuleset = rId;
}
}
this.map.on("tileslayerready", function(o) {
var tileToShow = (this.options.tile) ? this.config.tiles[this.options.tile].name : o.first;
this.layers.tile = this.layersManager.layers.tiles[tileToShow];
......
......@@ -193,8 +193,6 @@ MapLayersManager.prototype.setOSMFeatures = function(f, ruleset, options) {
fIconRgxTagValue = feature.style.pointStyles.default.icon_image_aliases[fIconRgxTagValue];
}
console.log(fIconUrl);
console.log(fIconRgxTagValue);
fIconUrl = fIconUrl.replace(fIconRgx, fIconRgxTagValue);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment