Skip to content

Missing layerscontrol variable (or incomplete documentation) #341

@thibault

Description

@thibault

Hi django-leaflet team,

I just installed django-leaflet and ran into an issue with a missing variable.

Context

I want to display a map with default values, and add an overlay layer. I followed the doc about adding overlays with js.

My code is pretty much exactly copy-pasted from the docs' excerpts.

{% block content %}
{% leaflet_map 'cadastre_map' callback="window.map_init" %}
{% endblock %}

{% block head %}
{% leaflet_css %}
{% leaflet_js %}
<script>
  function map_init(map, options) {
    var lc = map.layerscontrol;

    // An example from the Atlas of Living Australia https://www.ala.org.au/
    lc.addOverlay(
      L.tileLayer.wms(
        'https://spatial-beta.ala.org.au/geoserver/ALA/wms', {
          layers: 'ALA:aus2',
          format: 'image/png',
          transparent: true
        }),
      'Australia'
    );
  }
</script>
{% endblock %}

In my settings:

LEAFLET_CONFIG = {
    "DEFAULT_CENTER": (47, 1.7),
    "DEFAULT_ZOOM": 6,
}

Expected result

The overlay should display properly, according to the documentation.

Actual result

The console throws this error: Uncaught TypeError: lc is undefined

It seems to me that, according to this line or this one, the line that defines the layersControl var is never reached if no layers or overlays are defined in django settings.

I'm not sure if this is a bug with django-leaflet or is something is missing from the documentation?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions