2GIS Map API + raster tiles from ever gis

Raster source example

by Trufi

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>2GIS Map API</title>
        <meta name="description" content="Raster source example">
    </head>
    <body>
        <div id="container"></div>
        <script src="https://mapgl.2gis.com/api/js/v1"></script>
    </body>
</html>

CSS

html,
body,
#container {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

JavaScript

// API key can be used on jsfiddle.net only!
// You can get more info on https://docs.2gis.com/

const map = new mapgl.Map('container', {
    center: [55.425, 25.355],
    zoom: 13,
    key: 'bfd8bbca-8abf-11ea-b033-5fa57aae2de7',
});
const source = new mapgl.RasterTileSource(map, {
    url: (x, y, zoom) => `https://2gis.evergis.ru/sp/layers/admin.saudi_basemap/tile/${zoom}/${x}/${y}`,
    // Source attribute for data filtering logic
    attributes: { bar: 'asd' },
})
const layer = {
    // Drawing object type
    type: 'raster',
    // Each layer ID must be unique
    id: 'raster-tile-layer',
    // Data filtering logic
    filter: [
        'match',
        ['sourceAttr', 'bar'], // Match with attribute from data source
        ['asd'],
        true, // Result if value of bar source attribute equals "asd"
        false // Result if not
    ],
    // Style of drawing object
    style: {
        opacity: 1,
    },
};
map.on('styleload', () => {
    map.addLayer(layer);
});