Retour à la documentation
define([
'dojo/_base/declare',
'spw/api/MapService',
'dojo/_base/lang',
'dojo/_base/array'
],
function(declare, MapService, lang, array) {
/**
* @class spw.api.TimerMapService
* @classdesc Service du viewer correspondant à un service voyage dans le temps
* @extends {spw.api.MapService}
*/
var TimerMapService = declare('spw.api.TimerMapService', [MapService], /** @lends spw.api.TimerMapService.prototype */ {
label: 'Timer',
hasLegend: false,
inTOC: true,
minScale: 0,
maxScale: 0,
loaded: false,
visible: true,
toLoad: false,
services: null,
mapServices: null,
_propertiesToKeep: [
'serviceId', 'label', 'alpha', 'toLoad', 'visible', 'type', 'metadataUrl', 'metadataPopup',
'url', 'hasLegend', 'checked', 'order', 'inTOC', 'identifiable', 'expanded', 'layersExpanded', 'description', 'ruleLabel'
],
/**
* Crée le layer Esri sur base de la configuration du MapService.
*/
createMapLayer: function() {
this.loaded = true;
this.mapServices = [];
require(['spw/api/MapServiceFactory'], lang.hitch(this, function(MapServiceFactory){
array.forEach(this.services, lang.hitch(this, function(s, idx){
lang.mixin(s, { spwMap: this.spwMap });
this.mapServices.push(MapServiceFactory.createService(s));
}));
this.layer = this.mapServices[0].get('layer');
}));
var handler = this.spwMap.esriMap.on("layer-add-result", lang.hitch(this, function(evt) {
if(evt.layer == this.get('layer')){
if(handler) {
handler.remove();
}
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
if(idx > 0){
s.set('alpha', 0);
this.spwMap.esriMap.addLayer(s.get('layer'));
}
}));
}
}));
//this.inherited(arguments);
},
/**
* Affiche le service
*/
show: function(){
this.visible = true;
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
s.show();
}));
},
/**
* Masque le service
*/
hide: function(){
this.visible = false;
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
s.hide();
}));
},
/**
* Détermine si le service est le premier dans la liste des services de la carte
*/
isFirst: function() {
return this.mapServices[0].isFirst();
},
/**
* Détermine si le service est le dernier dans la liste des services de la carte
*/
isLast: function() {
return this.mapServices[this.mapServices.length-1].isLast();
},
/**
* Change l'ordre du service sur base d'un delta
* @param {number} delta nombre de position dont il faut déplacer le service (peut être négatif)
*/
moveLayer: function(delta){
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
s.moveLayer(delta);
}));
},
_setVisibleAttr: function(visible){
this.visible = visible;
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
s.set('visible', visible);
}));
},
_getLayerAttr: function(){
return this.mapServices[0].get('layer');
},
/**
* Retire le service de la carte
*/
removeFromMap: function(esriMap){
array.forEach(this.mapServices, lang.hitch(this, function(s, idx){
esriMap.removeLayer(s.get('layer'));
}));
},
getServiceConfig: function(toKeep) {
toKeep = toKeep || this._propertiesToKeep;
var cfg = null;
for (var property in this) {
if (toKeep.indexOf(property) < 0) {
continue;
}
cfg = cfg || {};
cfg[property] = this[property];
}
cfg.services = [];
array.forEach(this.get('mapServices'), lang.hitch(this, function(mapService) {
cfg.services.push(mapService.getServiceConfig(toKeep));
}));
return cfg;
}
});
return TimerMapService;
});