cartodb-4.42/lib/assets/javascripts/builder/data/custom-baselayers-collection.js
2024-04-06 05:25:13 +00:00

55 lines
1.3 KiB
JavaScript
Executable File

var Backbone = require('backbone');
var CustomBaselayerModel = require('./custom-baselayer-model');
var checkAndBuildOpts = require('builder/helpers/required-opts');
var REQUIRED_OPTS = [
'configModel',
'currentUserId'
];
module.exports = Backbone.Collection.extend({
model: function (d, opts) {
var self = opts.collection;
var m = new CustomBaselayerModel(d, {
parse: true,
collection: self
});
return m;
},
url: function () {
var baseUrl = this._configModel.get('base_url');
var version = this._configModel.urlVersion('user');
return baseUrl + '/api/' + version + '/users/' + this._currentUserId + '/layers';
},
initialize: function (models, opts) {
checkAndBuildOpts(opts, REQUIRED_OPTS, this);
},
isCustomCategory: function () {
var custom = this.where(function (mdl) {
return ['NASA', 'TileJSON', 'WMS', 'Mapbox', 'Custom', undefined].some(function (category) {
return mdl.get('category') === category;
});
});
return custom;
},
getSelected: function () {
return this.findWhere({ selected: true });
},
hasCustomBaseLayer: function (className) {
if (!className) return;
var customBaseLayer = this.where({ className: className });
return customBaseLayer.length > 0;
}
});