html – Leaflet.draw in Node with LWC configuration issues-ThrowExceptions

Exception or error:

I’ve been trying to add Leaflet Draw to my SFDX Project with limited success. I’ve looked at the other posts here regarding it as well as their documentation to try and replicate it to get everything working, but I haven’t been able to. All of this is very new to me so it is a struggle but doing what I can.

Currently, I am trying to enable the Draw toolbar in leaflet so users can draw shapes to define regions. In order to do that, I am trying to set-up my HTML file and my map.js file.


<!DOCTYPE html>
        <link href="" el="stylesheet" />
        <script src=""></script>
        <lightning-card title="Geospatial Map">
            <div class="map-root" lwc:dom="manual"></div>


I’ve tried a few permutations of the and tags in terms of location and nesting, but keep getting an error either saying LWC1051: Forbidden tag found in template: '<link>' tag is not allowed.

or in the current setup

LWC1075: Multiple roots found
LWC1079: Expected root tag to be template, found link

Do I need to be formatting this differently/putting it somewhere else?


import { LightningElement } from 'lwc';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import leaflet from '@salesforce/resourceUrl/leaflet';
var leafletDraw = require('leaflet-draw');
/* L is the Leaflet object constructed by the leaflet.js script */
/*global L*/

export default class Map extends LightningElement {

    map; //, a leaflet map. constructed in initializeleaflet

     * When the Map LWC is ready, start downloading Leaflet.
     * When this is complete, call initializeleaflet()

    connectedCallback() {
            loadScript(this, leaflet + '/leaflet.js'),
            loadStyle(this, leaflet + '/leaflet.css')
        ]).then(() => {
            this.dispatchEvent(new CustomEvent('ready', { detail: }));

     * Constructs the Leaflet map on the page and initializes
    initializeLeaflet() {
        const mapRoot = this.template.querySelector('.map-root'); =, {drawControl: true});;

    addDrawTools() {
        const drawnItems = new L.FeatureGroup();;

        const drawControl = new L.Control.Draw({
            edit: {
                featureGroup: drawnItems

        const toolbar = L.Toolbar();
        const modifiedDraw = L.drawLocal.extend({
            draw: {
                toolbar: {
                    buttons: {
                        polygon: 'Draw a polygon!'

     * Setup the base OpenStreetMap tile layer
    setupBaseTiles() {
        const mapLink = '<a href="">OpenStreetMap</a>';

                attribution: '&copy; ' + mapLink + ' Contributors',


When I deploy this to Salesforce, I get an error saying that L.Draw.Control is not a constructor, which I assume has to do with the incorrect set-up.

In the docs, it says to use npm install leaflet-draw, then to put var leafletDraw = require('leaflet-draw'); at the top of the file. Could someone provide insight on how I am to use the leafletDraw in conjuction with the other leafletDraw code snippets that I have in the file already, which come from the setup documentation?

Thank you in advance for any help!!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *