0

I'm looking inside LeafletJs source code and I cannot find where L is defined nor exported. L is referred many times and main functions are called against it.

So where is L defined ? What is its nature (object, prototype) ?

A little bit of context : I'm trying to use leaflet with reasonml so I need bucklescript bindings to leaflet and for that I must understand how leaflet is designed. I'm aware of bs-leaflet library but it hasn't show any activity in 2 years.

Yvain
  • 882
  • 1
  • 10
  • 27

1 Answers1

3

Leaflet's source code have classes/prototypes/objects.

There's no L though. If you look at leaflet's src code, It's exported default. Not by name.

The reason why we type in our code something like this:

import L from 'Leaflet'

is because it's a common approach to name that L. That's what Leaflet recommends and states in their docs.

Edit:

Look into node_modules/leaflet/Leaflet.js . Everything gets imported without names, so when you import L, it has Map, geometry and other objects already in it.

Giorgi Lagidze
  • 773
  • 4
  • 24
  • That's what I though but this https://leafletjs.com/reference-1.6.0.html#noconflict confuse me : the scripts are referenced without any mention of L and yet there is an L existing in the scope – Yvain Nov 19 '19 at 11:23
  • 3
    What I explained is through npm. If you take a look at directly importing it, this is what they have at the last line : window.L = exports; and exports are the whole things one by one. https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet-src.js – Giorgi Lagidze Nov 19 '19 at 11:27
  • 1
    Thanks that's the part I was missing ! – Yvain Nov 19 '19 at 11:30