Custom color ramp (color ramp)

This example shows how to create a custom color ramp and use it to visualize a point layer. Download the sample data here.

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',
    zoom: 11.6,
    center: [-119.807, 36.7828],
    style: MapStyle.DATAVIZ.DARK
});

const myCustomRamp = new maptilersdk.ColorRamp({
  stops: [
    { value: 100, color: [252, 222, 156] },
    { value: 500, color: [250, 164, 118] },
    { value: 1000, color: [240, 116, 110] },
    { value: 1500, color: [227, 79, 111] },
    { value: 2000, color: [220, 57, 119] },
    { value: 3000, color: [185, 37, 122] },
    { value: 4000, color: [124, 29, 111] },
  ]
});

map.on('load', async function () {
  await maptilersdk.helpers.addPoint(map, {
    data: 'schools.geojson',
    property: "students",
    pointColor: myCustomRamp,
    pointOpacity: 0.7,
    minPointRadius: 1,
    maxPointRadius: 100,
    showLabel: true,
  });
});
Color ramp resampling (color ramp)

Color ramp resampling (color ramp)

Examples

Visualize point layers by resampling existing map color ramps.

Polygon color ramp symbol (polygon helper)

Polygon color ramp symbol (polygon helper)

Examples

Style polygon fill color based on zoom level.

Line color ramp symbol (polyline helper)

Line color ramp symbol (polyline helper)

Examples

Style line color based on map zoom level.

Was this helpful?