Retour à la documentation
define(["dojo/_base/declare", "dojo/_base/array","spw/api/Utils"], function (declare, array, Utils) {
var StateManager = null;
/**
* @class spw.api.StateManager
* @classdesc Manager permettant de gérer l'état du viewer
*/
StateManager = declare("spw.api.StateManager", null, /** @lends spw.api.StateManager.prototype */{
_widgetsRegistred:null,
_catalogState:null,
_baseMapState:null,
_mapServicesState:null,
constructor:function(){
this._widgetsRegistred = {};
},
register: function(stateId, methodReference){
this._widgetsRegistred[stateId] = methodReference;
},
getStateFromRegistred: function(stateId){
if(typeof this._widgetsRegistred[stateId].methodReference == "function")
return this._widgetsRegistred[stateId](opts);
},
getStateFromURL: function(stateId){
return Utils.gua(stateId);
},
getAnchors: function(opts) {
var toReturn = [];
for(stateId in this._widgetsRegistred) {
var val = this._widgetsRegistred[stateId](opts);
if (val == null) {
return null;
}
toReturn.push({
key: stateId,
value: val
});
}
if (opts.extent) {
toReturn.push({
key: 'BBOX',
value: opts.extent.xmin + "," + opts.extent.xmax + "," + opts.extent.ymin + "," + opts.extent.ymax
});
}
return toReturn;
},
getCompleteUrl: function(opts){
var currentUrl = window.location.toString();
for(stateId in this._widgetsRegistred){
currentUrl = Utils.addAnchor(stateId, this._widgetsRegistred[stateId](opts), currentUrl);
}
return currentUrl;
},
removeStateFromUrl: function(stateId){
Utils.rua(stateId);
},
cleanUrl: function() {
this.removeStateFromUrl(StateManager.MAP_SERVICES_ID);
this.removeStateFromUrl(StateManager.BASEMAP_ID);
/** inutile pour l'instant... */
for (var stateId in this._widgetsRegistred){
this.removeStateFromUrl(stateId);
}
}
});
var _INSTANCE = null;
StateManager.getInstance = function() {
if(_INSTANCE == null){
_INSTANCE = new StateManager();
}
return _INSTANCE;
};
StateManager.MAP_SERVICES_ID = 'MAP_SERVICES';
StateManager.BASEMAP_ID = 'BASEMAPS';
StateManager.PANIER_ID = 'PANIER';
StateManager.RETRO_MAP_SERVICES_ID = 'MSS';
StateManager.RETRO_BASEMAP_ID = 'BMS';
return StateManager;
});