Commit f0426cc2 authored by Yohan Boniface's avatar Yohan Boniface

Make layer browsable switch more generic

parent 8f9c749f
......@@ -710,7 +710,7 @@ L.Storage.Map.include({
var appendAll = function () {
featuresContainer.innerHTML = '';
filterValue = filter.value;
this.eachDataLayerReverse(function (datalayer) {
this.eachBrowsableDataLayer(function (datalayer) {
append(datalayer);
});
};
......
......@@ -427,7 +427,8 @@ L.Storage.Help = L.Class.extend({
interactive: L._('If false, the polygon will act as a part of the underlying map.'),
outlink: L._('Define link to open in a new window on polygon click.'),
dynamicRemoteData: L._('Fetch data each time map view changes.'),
proxyRemoteData: L._('To use if remote server doesn\'t allow cross domain (slower)')
proxyRemoteData: L._('To use if remote server doesn\'t allow cross domain (slower)'),
browsable: L._('Set it to false to hide this layer from the slideshow, the data browser, the popup navigation…')
});
......
......@@ -229,7 +229,7 @@ L.FormBuilder.DataLayerSwitcher = L.FormBuilder.Select.extend({
getOptions: function () {
var options = [];
this.builder.map.eachDataLayerReverse(function (datalayer) {
if(datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.isBrowsable()) {
if(datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.canBrowse()) {
options.push([L.stamp(datalayer), datalayer.getName()]);
}
});
......
......@@ -146,8 +146,10 @@ L.Storage.Map.include({
}
delete this.options.displayDataBrowserOnLoad;
}
if (this.options.onLoadPanel === 'databrowser') this.openBrowser();
else if (this.options.onLoadPanel === 'caption') this.displayCaption();
this.onceDatalayersLoaded(function () {
if (this.options.onLoadPanel === 'databrowser') this.openBrowser();
else if (this.options.onLoadPanel === 'caption') this.displayCaption();
});
this.ui.on('panel:closed', function () {
this.invalidateSize({pan: false});
......@@ -848,7 +850,7 @@ L.Storage.Map.include({
},
openBrowser: function () {
this.whenReady(function () {
this.onceDatalayersLoaded(function () {
this._openBrowser();
});
},
......@@ -869,7 +871,7 @@ L.Storage.Map.include({
description.innerHTML = L.Util.toHTML(this.options.description);
}
var datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container);
this.eachDataLayerReverse(function (datalayer) {
this.eachBrowsableDataLayer(function (datalayer) {
var p = L.DomUtil.create('p', '', datalayerContainer),
color = L.DomUtil.create('span', 'datalayer-color', p),
headline = L.DomUtil.create('strong', '', p),
......@@ -926,12 +928,23 @@ L.Storage.Map.include({
}
},
eachDataLayerReverse: function (method, context) {
eachDataLayerReverse: function (method, context, filter) {
for (var i = this.datalayers_index.length - 1; i >= 0; i--) {
if (filter && !filter.call(context, this.datalayers_index[i])) continue;
method.call(context, this.datalayers_index[i]);
}
},
eachBrowsableDataLayer: function (method, context, filter) {
this.eachDataLayerReverse(method, context, function (d) { return d.allowBrowse(); });
},
findDataLayer: function (method, context) {
for (var i = this.datalayers_index.length - 1; i >= 0; i--) {
if (method.call(context, this.datalayers_index[i])) return this.datalayers_index[i];
}
},
backup: function () {
this.backupOptions();
this._datalayers_index_bk = [].concat(this.datalayers_index);
......@@ -1111,21 +1124,16 @@ L.Storage.Map.include({
defaultDataLayer: function () {
var datalayer, fallback;
datalayer = this.lastUsedDataLayer;
if (datalayer && !datalayer.isRemoteLayer() && datalayer.isBrowsable() && datalayer.isVisible()) {
if (datalayer && !datalayer.isRemoteLayer() && datalayer.canBrowse() && datalayer.isVisible()) {
return datalayer;
}
for (var i in this.datalayers) {
if (this.datalayers.hasOwnProperty(i)) {
datalayer = this.datalayers[i];
if (!datalayer.isRemoteLayer() && datalayer.isBrowsable()) {
if (datalayer.isVisible()) {
return datalayer;
} else {
fallback = datalayer;
}
}
datalayer = this.findDataLayer(function (datalayer) {
if (!datalayer.isRemoteLayer() && datalayer.canBrowse()) {
fallback = datalayer;
if (datalayer.isVisible()) return true;
}
}
});
if (datalayer) return datalayer;
if (fallback) {
// No datalayer visible, let's force one
this.addLayer(fallback.layer);
......@@ -1135,15 +1143,7 @@ L.Storage.Map.include({
},
getDataLayerByStorageId: function (storage_id) {
var datalayer;
for (var i in this.datalayers) {
if (this.datalayers.hasOwnProperty(i)) {
datalayer = this.datalayers[i];
if (datalayer.storage_id == storage_id) {
return datalayer;
}
}
}
return this.findDataLayer(function (d) { return d.storage_id == storage_id; });
},
edit: function () {
......
L.S.Layer = {
isBrowsable: true,
canBrowse: true,
getFeatures: function () {
return this._layers;
......@@ -70,7 +70,7 @@ L.S.Layer.Cluster = L.MarkerClusterGroup.extend({
L.S.Layer.Heat = L.HeatLayer.extend({
_type: 'Heat',
includes: [L.S.Layer],
isBrowsable: false,
canBrowse: false,
initialize: function (datalayer) {
this.datalayer = datalayer;
......@@ -138,7 +138,7 @@ L.Storage.DataLayer = L.Class.extend({
options: {
displayOnLoad: true,
slideshow: true
browsable: true
},
initialize: function (map, data) {
......@@ -246,7 +246,7 @@ L.Storage.DataLayer = L.Class.extend({
},
eachFeature: function (method, context) {
if (this.layer && this.layer.isBrowsable) {
if (this.layer && this.layer.canBrowse) {
for (var i = 0; i < this._index.length; i++) {
method.call(context || this, this._layers[this._index[i]]);
}
......@@ -703,7 +703,7 @@ L.Storage.DataLayer = L.Class.extend({
'options.description',
['options.type', {handler: 'LayerTypeChooser', label: L._('Type of layer')}],
['options.displayOnLoad', {label: L._('Display on load'), handler: 'Switch'}],
['options.slideshow', {label: L._('Use in slideshow'), handler: 'Switch'}]
['options.browsable', {label: L._('Data is browsable'), handler: 'Switch', helpEntries: 'browsable'}]
];
var title = L.DomUtil.add('h3', '', container, L._('Layer properties'));
var builder = new L.S.FormBuilder(this, metadataFields, {
......@@ -900,16 +900,16 @@ L.Storage.DataLayer = L.Class.extend({
if (bounds.isValid()) this.map.fitBounds(bounds);
},
useForSlideshow: function () {
return !!this.options.slideshow && this.isVisible() && this.isBrowsable() && this._index.length;
allowBrowse: function () {
return !!this.options.browsable && this.canBrowse() && this.isVisible() && this._index.length;
},
isVisible: function () {
return this.map.hasLayer(this.layer);
},
isBrowsable: function () {
return this.layer && this.layer.isBrowsable;
canBrowse: function () {
return this.layer && this.layer.canBrowse;
},
getFeatureByIndex: function (index) {
......@@ -921,28 +921,28 @@ L.Storage.DataLayer = L.Class.extend({
getNextFeature: function (feature) {
var id = this._index.indexOf(L.stamp(feature)),
nextId = this._index[id + 1];
return nextId? this._layers[nextId]: this.getNextForSlideshow().getFeatureByIndex(0);
return nextId? this._layers[nextId]: this.getNextBrowsable().getFeatureByIndex(0);
},
getPreviousFeature: function (feature) {
if (this._index <= 1) { return null; }
var id = this._index.indexOf(L.stamp(feature)),
previousId = this._index[id - 1];
return previousId? this._layers[previousId]: this.getPreviousForSlideshow().getFeatureByIndex(-1);
return previousId? this._layers[previousId]: this.getPreviousBrowsable().getFeatureByIndex(-1);
},
getNextForSlideshow: function () {
getNextBrowsable: function () {
var id = this.getRank(), next, index = this.map.datalayers_index;
while(id = index[++id] ? id : 0, next = index[id]) {
if (next === this || next.useForSlideshow()) break;
if (next === this || next.allowBrowse()) break;
}
return next;
},
getPreviousForSlideshow: function () {
getPreviousBrowsable: function () {
var id = this.getRank(), prev, index = this.map.datalayers_index;
while(id = index[--id] ? id : index.length - 1, prev = index[id]) {
if (prev === this || prev.useForSlideshow()) break;
if (prev === this || prev.allowBrowse()) break;
}
return prev;
},
......
......@@ -61,13 +61,7 @@ L.S.Slideshow = L.Class.extend({
},
defaultDatalayer: function () {
var datalayer;
for (var i in this.map.datalayers) {
if (this.map.datalayers.hasOwnProperty(i)) {
datalayer = this.map.datalayers[i];
if (datalayer.useForSlideshow()) return datalayer;
}
}
return this.map.findDataLayer(function (d) { return d.allowBrowse(); });
},
timeSpinner: function () {
......
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