src/gm3/trackers/hash.js
/* Batch and issue commands to handle the restoration of layers.
     */
Batch and issue commands to handle the restoration of layers.
Batch and issue commands to handle the restoration of layers .
restoreLayers(layersOn) {
        const layers = layersOn.split(this.joinSymbol);
        const visible_layers = getVisibleLayers(this.store.getState().mapSources);
        const turn_off = [];
        const turn_on = [];
        for(let i = 0, ii = layers.length; i < ii; i++) {
            if(visible_layers.indexOf(layers[i]) < 0) {
                turn_on.push(layers[i]);
            }
        }
        for(let i = 0, ii = visible_layers.length; i < ii; i++) {
            if(layers.indexOf(visible_layers[i]) < 0) {
                turn_off.push(visible_layers[i]);
            }
        }
        for(const layer of turn_on) {
            this.store.dispatch({
                type: MAPSOURCE.LAYER_VIS,
                mapSourceName: util.getMapSourceName(layer),
                layerName: util.getLayerName(layer),
                on: true
            })
        }
        const map_sources = this.store.getState().mapSources;
        for(const layer of turn_off) {
            const ms_name = util.getMapSourceName(layer);
            if(!this.isAlwaysOn(map_sources[ms_name])) {
                this.store.dispatch({
                    type: MAPSOURCE.LAYER_VIS,
                    mapSourceName: ms_name,
                    layerName: util.getLayerName(layer),
                    on: false
                });
            }
        }
    }
restoreLayers ( layersOn ) { const layers = layersOn . split ( this . joinSymbol ) ; const visible_layers = getVisibleLayers ( this . store . getState ( ) . mapSources ) ; const turn_off = [ ] ; const turn_on = [ ] ; for ( let i = 0 , ii = layers . length ; i < ii ; i ++ ) { if ( visible_layers . indexOf ( layers [ i ] ) < 0 ) { turn_on . push ( layers [ i ] ) ; } } for ( let i = 0 , ii = visible_layers . length ; i < ii ; i ++ ) { if ( layers . indexOf ( visible_layers [ i ] ) < 0 ) { turn_off . push ( visible_layers [ i ] ) ; } } for ( const layer of turn_on ) { this . store . dispatch ( { type : MAPSOURCE . LAYER_VIS , mapSourceName : util . getMapSourceName ( layer ) , layerName : util . getLayerName ( layer ) , on : true } ) } const map_sources = this . store . getState ( ) . mapSources ; for ( const layer of turn_off ) { const ms_name = util . getMapSourceName ( layer ) ; if ( ! this . isAlwaysOn ( map_sources [ ms_name ] ) ) { this . store . dispatch ( { type : MAPSOURCE . LAYER_VIS , mapSourceName : ms_name , layerName : util . getLayerName ( layer ) , on : false } ) ; } } }
Batch and issue commands to handle the restoration of layers.
Batch and issue commands to handle the restoration of layers .
// get the list of layers from the query. // check for what the visible layers are now. // layers to turn on // the layer from the URL is not "visible" // get the mapsources from the current state