leaflet js: draw POIs as canvas

Andrew picture Andrew · Mar 26, 2012 · Viewed 10.8k times · Source

I want to draw many geo points with Leaflet. Therefore I want to use HTML5 canvas to improve the performance. My datasoure is geoJSON. As I saw in the documention of Leaflet, it is not possible to draw the geo positions as canvas yet.

var anotherGeojsonLayer = new L.GeoJSON(coorsField, {
        pointToLayer: function (latlng){
            return new L.Marker(latlng, {
                icon: new BaseballIcon()
            });
        }
    });

I think I should hook up here:

pointToLayer: function (latlng) { }

Does somebody know how to draw my latlng objects as canvas?

Answer

Mourner picture Mourner · Jun 22, 2012

I'm Leaflet author. You can do this by using L.CircleMarker instead of regular Marker, and also using an experimental L_PREFER_CANVAS switch to render vectors as Canvas (instead of SVG), like this: https://github.com/CloudMade/Leaflet/blob/master/debug/vector/vector-canvas.html