<commit_before>odoo.define('geoengine_swisstopo.BackgroundLayers', function (require) {
    "use strict";

    var BackgroundLayers = require('base_geoengine.BackgroundLayers');

    BackgroundLayers.include({
        handleCustomLayers: function(l) {
            var out = this._super.apply(this, arguments);
            if (l.raster_type == 'swisstopo') {
                var urls = [];
                ['10', '11', '12', '13', '14'].map(function(i) {
                    var url = 'https://wmts{i}.geo.admin.ch/1.0.0/{layer}/default/{time}/{projection}/{z}/{x}/{y}.{format}';
                    url = url.replace('{i}', i);
                    url = url.replace('{layer}', l.layername || 'ch.swisstopo.pixelkarte-farbe');
                    url = url.replace('{time}', l.time || 'current');
                    url = url.replace('{projection}', l.projection || '3857');
                    url = url.replace('{format}', l.format_suffix || 'jpeg');
                    urls.push(url);
                });
                var source = new ol.source.XYZ({
                    attributions: [
                        new ol.Attribution({
                            html: '<a target="_blank" href="https://www.swisstopo.admin.ch">swisstopo</a>'
                        })
                    ],
                    urls: urls,
                    maxZoom: 17
                });
                out.push(
                    new ol.layer.Tile({
                        title: l.name,
                        visible: !l.overlay,
                        type: 'base',
                        source: source
                    })<commit_msg>Fix swiss 21781 projection<commit_after>/**
 * Available resolutions as defined in
 * https://api3.geo.admin.ch/services/sdiservices.html#wmts.
 * @const {!Array.<number>}
 */
var RESOLUTIONS = [
  4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250,
  1000, 750, 650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5,
  0.25, 0.1
];

var BASE_URL = 'https://wmts{0-9}.geo.admin.ch/1.0.0/{Layer}/default/{Time}/21781/{TileMatrix}/{TileRow}/{TileCol}.{format}';

var ATTRIBUTIONS = '<a target="_blank" href="https://www.swisstopo.admin.ch">swisstopo</a>';

/**
 * Extents of Swiss projections. (EPSG:21781)
 */
var EXTENT = [420000, 30000, 900000, 350000];


odoo.define('geoengine_swisstopo.BackgroundLayers', function (require) {
    "use strict";

    var BackgroundLayers = require('base_geoengine.BackgroundLayers');

    BackgroundLayers.include({

        createTileGrid: function() {
            return new ol.tilegrid.WMTS({
                extent: EXTENT,
                resolutions: RESOLUTIONS,
                matrixIds: RESOLUTIONS.map(function(item, index) {
                    return String(index);
                }),
            });
        },

        handleCustomLayers: function(l) {
            var out = this._super.apply(this, arguments);
            if (l.raster_type == 'swisstopo') {
                var format = l.format_suffix || 'jpeg';
                var layer = l.layername || 'ch.swisstopo.pixelkarte-farbe';

                var url = BASE_URL.replace('{format}', format);
                var source = new ol.source.WMTS({
                    attributions: [
                        new ol.Attribution({
                            html: ATTRIBUTIONS,
                        })
                    ],
                    url: url,
                    dimensions: {
                        'Time': l.time || 'current',
                    },
                    projection: 'EPSG:21781',
                    requestEncoding: 'REST',
                    layer: layer,
                    style: 'default',
                    matrixSet: '21781',
                    format: 'image/' + format,
                    tileGrid: this.createTileGrid(),
                    crossOrigin: 'anonymous',
                });
                out.push(
                    new ol.layer.Tile({
                        title: l.name,
                        visible: !l.overlay,
                        type: 'base',
                        source: source
                    })
{'fraction_non_alphanumeric': 0.1375992302140967, 'fraction_numerical': 0.03848929516478229, 'mean_word_length': 1.3571428571428572, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889255', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1143, 'n_words': 223}