Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet: Uncaught TypeError: L.markerClusterGroup is not a function

I am trying to add markercluster into leaflet.

var markers = L.markerClusterGroup();

My header file include:

   script(src='https://unpkg.com/[email protected]/dist/leaflet.js')
   link(type='text/css', rel='stylesheet', href='/stylesheets/MarkerCluster.css')
   link(type='text/css', rel='stylesheet', href='/stylesheets/MarkerCluster.Default.css')        
   script(src=/javascripts/leaflet.markercluster-src.js')

But I keep getting the error of : L.markerClusterGroup is not a function

I am not sure why I get that error.

like image 505
Tenz Avatar asked Oct 30 '22 18:10

Tenz


2 Answers

This was a simple import mistake with angular, changing imports to the following, resolves this issue:

import * as L from 'leaflet';
import 'leaflet.markercluster';

// Compile & run = OK
private myClusterGroup = L.markerClusterGroup();

Tested using Angular 7, leaflet 1.6.0 and leaflet.markercluster 1.4.1

like image 157
Ross Avatar answered Nov 12 '22 17:11

Ross


I think you miss a quote in your declaration

script(src='/javascripts/leaflet.markercluster-src.js')
like image 21
YaFred Avatar answered Nov 12 '22 15:11

YaFred