francoisromain / leaflet-markers-canvas

A Leaflet plugin to render many markers in a canvas instead of the DOM
GNU Affero General Public License v3.0
42 stars 15 forks source link

Error: Uncaught TypeError: Cannot read properties of undefined (reading '0') #17

Open ndrean opened 2 years ago

ndrean commented 2 years ago
import { MarkersCanvas } from "leaflet-markers-canvas";
import RBush from "rbush";

const map = L.map(...)
const markersCanvas = new L.MarkersCanvas();
markersCanvas.addTo(map);
const marker = L.marker(e.latlng, { draggable: true }).bindPopup(html);
markersCanvas.addMarker(marker)

// => leaflet-markers-canvas.min.js:1 Uncaught TypeError: Cannot read properties of undefined (reading '0')
hi5on9 commented 1 year ago

i have same issue. did you resolve it? ?

ndrean commented 1 year ago

Two things I did wrong:

import * as L from 'leaflet'
import { MarkersCanvas } from "leaflet-markers-canvas";
...

then you can add a marker to the canvas with markersCavans.ddMarker(marker).

But you cannot drag it when added to a canvas. To do so, we need to pass into a Layer or directly to map.

Note also that there is no "guard" area around a marker when drawn into a canvas.