cartodb-4.42/lib/assets/javascripts/builder/editor/layers/layer-views/base-tiled-layer-view.js

53 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
/* global Image */
var BaseLayerViewBase = require('./base-layer-view-base');
var template = require('./image-thumbnail-layer.tpl');
var DEFAULT_SUBDOMAIN = 'a';
var DEFAULT_X_POSITION = 30;
var DEFAULT_Y_POSISTION = 24;
var DEFAULT_ZOOM = 6;
var DEFAULT_IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAAXNSR0IArs4c6QAAAZ9JREFUWAntWUtugzAUNKbAJl1EYtcz9Ba5UE6SC+UWPUN3SNlkw78zVhJRCeIXbCup6ic5gP08Ho/x40ESBauq6iNJkgPKDpdb1j3RTuM4HlH2ZVl+JySXpukXygaksiViRVEsNd3qu65Tfd/frpdO8jxXEGO2GcTUMAxtXddnYH1qKqe1fof3IrlZpECVJA6xMgiyMdzws0N5CzTealiIlpGbBsKz77nZSYAc67ck+NIWCbouj1cFL/eNK6df/UW7FztKMT7ZTOJDDMQ5RUyJGYK2IMyBm6ax4nFQGxZBEIStWFcH2TSu3pZjiCX2StDCf1VzJLhKtkmnqOBEjFWn/0tBaaB+REoTqJkJ2wxJpM3FtPvGMgQlabrkCUEcCcF7Kf9UBT5xvN6DIZbYK8Hp7H2dR4KuSkYFo4KPKBAiYTWBmoHznvEdQpKm82ljw+I4DObElJghaJu59AWHA9qw6CMlR9+4i6mCi0UFXdRj3z+hIL8Ju040VP+TBrkjtn0bagQH3JbcSHB/+WDNCgc8r11bZOdncjPfWV/5b4gfOaaYLUG/QVoAAAAASUVORK5CYII=';
var DEFAULT_NAME = _t('editor.layers.basemap.custom-basemap');
module.exports = BaseLayerViewBase.extend({
_getCompiledTemplate: function () {
var title = this.model.getName() || DEFAULT_NAME;
var desc = _t('editor.layers.basemap.title-label');
return template({
title: title,
desc: title === desc ? '' : desc,
imgURL: this._getImageURL()
});
},
_getImageURL: function () {
var self = this;
var url = this._lowerXYZ();
var image = new Image();
image.onerror = function () {
self.$('.js-thumbnailImg').attr('src', DEFAULT_IMG);
};
image.src = url;
return url;
},
_getSubdomain: function () {
var subdomains = this.model.get('subdomains'); // eg: 'abcd' or '1234'
return (subdomains && subdomains.length) ? subdomains[0] : DEFAULT_SUBDOMAIN;
},
_lowerXYZ: function () {
return this.model.get('urlTemplate')
.replace('{s}', this._getSubdomain())
.replace('{z}', DEFAULT_ZOOM)
.replace('{x}', DEFAULT_X_POSITION)
.replace('{y}', DEFAULT_Y_POSISTION);
}
});