Commit 4a97a083 authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Moved styles configuration in Main Ctrl

parent a3d8d941
......@@ -47,7 +47,7 @@
<!-- Init code -->
<script>
var myOlu = OLU.init("openlevelup", "advanced");
var myOlu = OLU.init("openlevelup", "advanced", {});
</script>
</body>
</html>
......@@ -47,7 +47,7 @@
<!-- Init code -->
<script>
var myOlu = OLU.init("openlevelup", "basic");
var myOlu = OLU.init("openlevelup", "basic", {});
</script>
</body>
</html>
......@@ -93,8 +93,8 @@ var OLU = {
OLU.util.addCompatibility();
//Main OpenLevelUp method
OLU.init = function(divId, configFolder, mode) {
return new OLU.ctrl.Main(divId, configFolder, mode);
OLU.init = function(divId, mode, config) {
return new OLU.ctrl.Main(divId, mode, config);
};
......
......@@ -48,10 +48,15 @@ var Main = function(divId, mode, config) {
"lon": 1.934,
"zoom": 6
},
"defaultStyle": "basic.mapcss",
"styleFolder": "styles"
"defaultStyle": "basic.mapcss"
},
"styles": [
"styles/basic.mapcss",
"styles/default.mapcss",
"styles/details.mapcss"
],
"api": {
"overpass": "http://api.openstreetmap.fr/oapi/interpreter/?data=",
"overpass_alt": "http://www.overpass-api.de/api/interpreter?data=",
......@@ -401,46 +406,27 @@ var Main = function(divId, mode, config) {
* @param folder The folder containing JSON configuration files
*/
Main.prototype._initConfig = function(config) {
var overwriteStyle = (config.styles && config.styles.length > 0) ? config.styles : null;
//Update default config according to given one
$.extend(true, this.config, config);
if(overwriteStyle) { this.config.styles = overwriteStyle; }
//Load MapCSS styles
var that = this;
$.ajax({
url: this.config.map.styleFolder+'/',
async: false,
success: function(data){
//Parse the list of mapcss files
$(data).find("a:contains(.mapcss)").each(function(){
var file = $(this).attr("href");
var fileName = file.substring(file.lastIndexOf("/")+1);
if(that.config.map.defaultStyle && fileName == that.config.map.defaultStyle) {
that.styles[0] = file;
}
else {
that.styles.push(file);
}
});
//Then download them
for(var i=0; i < this.styles.length; i++) {
if(typeof this.styles[i] === 'string') {
$.ajax({
url: this.config.map.styleFolder+'/'+this.styles[i],
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));
}
}
}.bind(this)
}).fail(function() { throw new Error("[Controller] Error while retrieving MapCSS list"); });
for(var i=0; i < this.config.styles.length; i++) {
if(typeof this.config.styles[i] === 'string') {
$.ajax({
url: this.config.styles[i],
async: false,
dataType: 'text',
success: function(data) {
var shortname = this.config.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.config.styles[i]); }.bind(this));
}
}
};
......
......@@ -130,7 +130,7 @@ area[shop] {
*[department=store_section][vending] {
icon-image: url('vending_$[vending].png');
icon-image-aliases: '"news_papers": "newspapers", "drinks": "drink", "vegetables": "vegetable"');
icon-image-aliases: '"news_papers": "newspapers", "drinks": "drink", "vegetables": "vegetable"';
icon-width: 24;
icon-height: 24;
icon-opacity: 1;
......
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