98 lines
2.6 KiB
JavaScript
98 lines
2.6 KiB
JavaScript
"use strict";
|
|
|
|
import {Utils} from "../Utils/Utils.ecma.js";
|
|
import {EventModel} from "../Models/EventModel.ecma.js";
|
|
import {BaseView} from "../Views/BaseView.ecma.js";
|
|
import {MenuView} from "../Views/MenuView.ecma.js";
|
|
import {MapView} from "../Views/MapView.ecma.js";
|
|
|
|
/**
|
|
* @callback routes_maker_ready_callback
|
|
* @param {!RoutesMaker} routes_maker
|
|
* @returns {void}
|
|
*/
|
|
|
|
/**
|
|
* @class
|
|
* @constructor
|
|
* @param {!(string|HTMLElement)} [position = "body"]
|
|
* @param {?routes_maker_ready_callback} [callback = null]
|
|
* @returns {void}
|
|
* @access public
|
|
* @static
|
|
*/
|
|
export const RoutesMaker = (function(){
|
|
|
|
/**
|
|
* @constructs RoutesMaker
|
|
* @param {!(string|HTMLElement)} [position = "body"]
|
|
* @param {?routes_maker_ready_callback} [callback = null]
|
|
* @returns {void}
|
|
* @access private
|
|
* @static
|
|
*/
|
|
const RoutesMaker = function(position = "body", callback = null){
|
|
|
|
/** @type {RoutesMaker} */
|
|
const self = this;
|
|
/** @type {number} */
|
|
let latitude = 0,
|
|
/** @type {number} */
|
|
longitude = 0;
|
|
|
|
/** @type {HTMLElement|null} */
|
|
this.item_self = null;
|
|
|
|
/** @type {EventModel} */
|
|
this.on_ready = new EventModel();
|
|
|
|
/** @type {BaseView} */
|
|
this.base = new BaseView(self);
|
|
/** @type {MenuView} */
|
|
this.menu = new MenuView(self);
|
|
/** @type {MapView} */
|
|
this.map = new MapView(self);
|
|
|
|
const constructor = () => {
|
|
self.on_ready.add(callback);
|
|
navigator.geolocation.getCurrentPosition(location => {
|
|
longitude = location.coords.longitude;
|
|
latitude = location.coords.latitude;
|
|
build();
|
|
}, () => {
|
|
build();
|
|
});
|
|
};
|
|
|
|
/**
|
|
* @returns {void}
|
|
* @access private
|
|
*/
|
|
const build = () => {
|
|
Utils.preload(position, (position, asynchronous, ok) => {
|
|
if(ok){
|
|
try{
|
|
self.base.build(position);
|
|
self.map.build();
|
|
self.menu.build();
|
|
self.on_ready.autoexecute = true;
|
|
self.on_ready.execute(self);
|
|
}catch(exception){
|
|
console.error(exception);
|
|
};
|
|
};
|
|
});
|
|
};
|
|
|
|
/**
|
|
* @returns {[number, number]}
|
|
* @access public
|
|
*/
|
|
this.get_user_coordenates = () => [latitude, longitude];
|
|
|
|
constructor();
|
|
|
|
};
|
|
|
|
return RoutesMaker;
|
|
})(); |