Change building color based on zoom level

Use the interpolate expression to ease-in the building layer and smoothly fade from one color to the next.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.BASE,
    center: [-90.73414, 14.55524],
    zoom: 13
});

map.on('load', function () {
    map.setPaintProperty('Building', 'fill-color', [
        'interpolate',
        ['exponential', 0.5],
        ['zoom'],
        15,
        '#e2714b',
        22,
        '#eee695'
    ]);

    map.setPaintProperty('Building', 'fill-opacity', [
        'interpolate',
        ['exponential', 0.5],
        ['zoom'],
        15,
        0,
        22,
        1
    ]);
});

document.getElementById('zoom').addEventListener('click', function () {
    map.zoomTo(19, { duration: 9000 });
});
Change a layer's color with buttons

Change a layer's color with buttons

Examples

Change layer fill colors dynamically using the setPaintProperty method.

Style lines with a data-driven property

Style lines with a data-driven property

Examples

Create visualizations using data expressions for line colors.

Custom color ramp (color ramp)

Custom color ramp (color ramp)

Examples

Visualize point layers by creating custom map color ramps.

Point layer colored and sized according to a property (point helper)

Point layer colored and sized according to a property (point helper)

Examples

Style point layer by property using point helper.

Was this helpful?