Plotting thousands or millions of points in Leaflet

Learn how to handle thousands or millions of location points with Leaflet JavaScript library using the leaflet-maptilersdk plugin. Download the Public School sample data.

In this Leaflet JS example, the size and color of points are scaled by the number of students in each school. You can load millions of points into Leaflet without affecting the performance of your application.

NPM module setup


npm install --save @maptiler/sdk @maptiler/leaflet-maptilersdk leaflet
import { ColorRampCollection } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { MaptilerLayer, MapStyle } from '@maptiler/leaflet-maptilersdk';
import L from 'leaflet';
import 'leaflet/dist/leaflet.css';

const map = L.map('map').setView([36.69, -92.570801], 5);
const mtLayer = new MaptilerLayer({
  apiKey: 'YOUR_MAPTILER_API_KEY_HERE',
  style: MapStyle.DATAVIZ.DARK, // optional
}).addTo(map);

mtLayer.on("ready", () => {     
  // Leverage the MapTiler SDK layer helpers to easily add polyline / point / polygon / heatmap layers
  mtLayer.addPoint({
    data: 'Public_School_Characteristics_2020-21_no_prop.geojson',
    property: "students",
    pointColor: ColorRampCollection.PORTLAND.scale(200, 2000).resample("ease-out-sqrt"),
    pointOpacity: 0.8,
    minPointRadius: 6,
    maxPointRadius: 30,
  });

});

Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

Learn more

Check out the Point Layer Helper documentation and look at the Point Helper examples to see the visualization possibilities.

Look at the Visualize points as cluster maps in Leaflet example.

Display thousands of lines in Leaflet

Display thousands of lines in Leaflet

Examples

Display thousands of lines efficiently in Leaflet using maptilersdk.

Display thousands of polygons in Leaflet

Display thousands of polygons in Leaflet

Examples

Display thousands of polygons efficiently in Leaflet using maptilersdk.

How to create a heatmap layer in Leaflet

How to create a heatmap layer in Leaflet

Examples

Create heatmap layers in Leaflet using the maptilersdk plugin.

Visualize points as cluster maps in Leaflet

Points as cluster

Examples

Visualize data points as cluster maps using Leaflet JS.

Was this helpful?