Commit e78b22ee authored by Adrien Pavie's avatar Adrien Pavie

Ending main controller, Simple UI alpha done

parent 67fb39d9
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -28,8 +28,8 @@
},
"osm": {
"oapi": "http://api.openstreetmap.fr/oapi/interpreter/?data=",
"oapi_alt": "http://www.overpass-api.de/api/interpreter?data=",
"oapi_alt": "http://api.openstreetmap.fr/oapi/interpreter/?data=",
"oapi": "http://www.overpass-api.de/api/interpreter?data=",
"api": "http://api.openstreetmap.org/api/0.6/",
"api_dev": "http://api06.dev.openstreetmap.org/api/0.6/",
"attribution": "Map data © <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors",
......
......@@ -32,6 +32,7 @@
<meta name="author" content="Adrien PAVIE (PanierAvide)" />
<meta name="copyright" content="&copy; Adrien PAVIE 2015-2016, under AGPL v3" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="icon" type="image/png" href="img/favicon.png" />
<!-- Stylesheets -->
<link rel="stylesheet" href="OLU.min.css" />
......@@ -41,8 +42,8 @@
<div id="openlevelup"></div>
<!-- JS libraries -->
<!--script src="OLU.js"></script-->
<script src="OLU.min.js"></script>
<script src="OLU.js"></script>
<!--script src="OLU.min.js"></script-->
<!-- Init code -->
<script>
......
......@@ -16,6 +16,7 @@
*/
var $ = require("jquery");
var L = require("leaflet");
var MainView = require("../view/Main");
var ServiceURL = require("./service/URL");
......@@ -76,11 +77,23 @@ var Main = function(divId, configFolder, mode) {
/** Data providers **/
this.data = {
osm: new ProviderDataOSM(this.config.osm.oapi)/*,
osm: new ProviderDataOSM(this.config.osm.oapi, this.polygons, this.style.styles)/*,
notes: new ProviderDataNotes(this.config.osm.api)*/
};
//CONSTRUCTOR
var options = {};
/*
* Read URL parameters
*/
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;
/*
* Init main view
*/
this.view = new MainView(
this.divId,
this.mode,
......@@ -89,8 +102,17 @@ var Main = function(divId, configFolder, mode) {
this.newNote,
this.search,
this.data.osm,
this.pictures.flickr
this.pictures.flickr,
options
);
/*
* URL updates
*/
this.view.map.on("levelchanged", function() {
this.url.setParameter("level", this.view.level.level);
this.url.write();
}.bind(this));
};
//OTHER METHODS
......
......@@ -84,8 +84,8 @@ URL.prototype.read = function() {
var url = this._readURL();
//Parse given URL
this._base = url.split('?')[0];
var query = url.split('?')[1].split('#')[0];
this._base = (url.indexOf("?") >= 0) ? url.split('?')[0] : url.split('#')[0];
var query = (url.indexOf("?") >= 0) ? url.split('?')[1].split('#')[0] : "";
this._url = {};
//Read query parameters
......
......@@ -19,6 +19,7 @@ var L = require("leaflet");
require("leaflet.locatecontrol");
require("leaflet-easybutton");
require("leaflet-editinosm");
require("leaflet-hash");
var $ = require("jquery");
var MapLayersManager = require("./MapLayersManager");
......@@ -34,7 +35,7 @@ var Spinner = require("./Spinner");
*
* Main view
*/
var Main = function(divId, mode, config, style, newNoteService, searchService, osmProvider, flickrProvider) {
var Main = function(divId, mode, config, style, newNoteService, searchService, osmProvider, flickrProvider, options) {
//ATTRIBUTES
/** The view mode (basic, advanced) **/
this.mode = (mode == "advanced") ? mode : "basic";
......@@ -45,6 +46,9 @@ var Main = function(divId, mode, config, style, newNoteService, searchService, o
/** The leaflet map **/
this.map = null;
/** The view options **/
this.options = options;
/** The side bar **/
this.side = null;
......@@ -95,6 +99,7 @@ var Main = function(divId, mode, config, style, newNoteService, searchService, o
});
this.map.attributionControl.setPrefix('<img src="img/favicon.png" /> <a href="http://openlevelup.net">OpenLevelUp!</a>');
this.layersManager = new MapLayersManager(this.map);
var hash = new L.Hash(this.map);
/***************************************************************************
......@@ -144,7 +149,8 @@ var Main = function(divId, mode, config, style, newNoteService, searchService, o
* Define tile layers
*/
this.map.on("tileslayerready", function(o) {
this.layers.tile = this.layersManager.layers.tiles[o.first];
var tileToShow = (this.options.tile) ? config.tiles[this.options.tile].name : o.first;
this.layers.tile = this.layersManager.layers.tiles[tileToShow];
this.layers.tile.addTo(this.map);
if(mode == "advanced") {
......@@ -246,7 +252,7 @@ var Main = function(divId, mode, config, style, newNoteService, searchService, o
//Remove events handlers
if(this.map.hasEventListeners("levelchanged")) {
this.map.removeEventListener("levelchanged");
this.map.removeEventListener("levelchanged", levelChangedHandler);
}
}.bind(this);
......@@ -460,6 +466,10 @@ var Main = function(divId, mode, config, style, newNoteService, searchService, o
//Choose first level to show
var firstLvl = (o.levels.indexOf(0) >= 0) ? 0 : o.levels[0];
if(this.options.level != undefined) {
firstLvl = this.options.level;
this.options.level = undefined;
}
//Add level selector
if(this.level.map == null) {
......
......@@ -92,6 +92,38 @@ QUnit.test("getParameter with old short URL from readURL", function(assert) {
assert.equal(u.getParameter("deprecated_lon"), "-1.7113");
assert.equal(u.getParameter("deprecated_zoom"), "21");
});
QUnit.test("getParameter with no query part from readURL", function(assert) {
var geturl = function() { return "http://openlevelup.net/"; };
var seturl = function(url) { console.log("URL set to: "+url); };
var u = new OLU.ctrl.service.URL(geturl, seturl);
assert.equal(u.getParameter("tile"), null);
assert.equal(u.getParameter("level"), null);
assert.equal(u.getParameter("transcend"), null);
assert.equal(u.getParameter("buildings"), null);
assert.equal(u.getParameter("pictures"), null);
assert.equal(u.getParameter("unrendered"), null);
assert.equal(u.getParameter("notes"), null);
assert.equal(u.getParameter("deprecated_lat"), null);
assert.equal(u.getParameter("deprecated_lon"), null);
assert.equal(u.getParameter("deprecated_zoom"), null);
});
QUnit.test("getParameter with a hash part and no query part from readURL", function(assert) {
var geturl = function() { return "http://openlevelup.net/map.html#13/48.1126/-1.6613"; };
var seturl = function(url) { console.log("URL set to: "+url); };
var u = new OLU.ctrl.service.URL(geturl, seturl);
assert.equal(u.getParameter("tile"), null);
assert.equal(u.getParameter("level"), null);
assert.equal(u.getParameter("transcend"), null);
assert.equal(u.getParameter("buildings"), null);
assert.equal(u.getParameter("pictures"), null);
assert.equal(u.getParameter("unrendered"), null);
assert.equal(u.getParameter("notes"), null);
assert.equal(u.getParameter("deprecated_lat"), null);
assert.equal(u.getParameter("deprecated_lon"), null);
assert.equal(u.getParameter("deprecated_zoom"), null);
});
/*
......
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