Importing Leaflet 1.5.0 fails
See original GitHub issueWhen using with react, leaflet 1.5.0 fails. However 1.4.0 works as expected
Code fails excatly at init function line “const map = L.map(mapName, { …”
Class to render map
import React, { Component } from "react";
import L from "leaflet";
import { initMap } from "./init";
/**
* @return {*} undefined
*/
export default class MapPanel extends Component {
/**
* @return {*} undefined
*/
componentDidMount = () => {
this.leftMap = initMap("lmap", "http://{s}.tile.osm.org/{z}/{x}/{y}.png");
this.rightMap = initMap("rmap", "http://{s}.tile.osm.org/{z}/{x}/{y}.png");
};
render() {
const props = this.props;
const { job } = props;
if (job && job.generated_polygon) this.moveWindow(job.generated_polygon);
return (
<div className="relative flex flex-col sm:flex-row flex-1">
<div className="z-0 flex-1 sm:h-full" id="lmap" />
<div className="h-1 sm:h-full sm:w-1 bg-theme-800" />
<div className="z-0 flex-1 sm:h-full" id="rmap" />
</div>
);
}
}
The init function
import L from "leaflet";
export const initMap = (mapName, url) => {
// create map
const map = L.map(mapName, {
center: [49.8419, 24.0315],
zoom: 16,
layers: [
L.tileLayer(url, {
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
})
]
});
return map;
};
And the error
Webpack Config
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const outputDirectory = "dist";
module.exports = {
devtool: "source-map",
entry: ["@babel/polyfill", "./src/client/index.js", "./src/client/index.css"],
output: {
path: path.join(__dirname, outputDirectory),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader", "postcss-loader"]
},
{
test: /\.(png|jpg|jpeg|woff|woff2|eot|ttf|svg)$/,
loader: "url-loader?limit=100000"
}
]
},
optimization: {
splitChunks: {
chunks: "all"
}
}
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Using Leaflet map with Typescript, unable to import Leaflet ...
I'm currently trying to load a Leaflet map in a personal project. but my code does not execute because of an import problem....
Read more >@types/leaflet - npm
This package contains type definitions for Leaflet.js (https://github.com/Leaflet/Leaflet). Details. Files were exported from https://github.com ...
Read more >Download - Leaflet - a JavaScript library for interactive maps
Leaflet is available on the following free CDNs: unpkg, cdnjs, jsDelivr. Disclaimer: these services are external to Leaflet; for questions or support, please ......
Read more >Create Interactive Web Maps with the JavaScript 'Leaflet' Library
Description Create and customize interactive maps using the 'Leaflet'. JavaScript library and the 'htmlwidgets' package. These maps can be used directly from ...
Read more >Leaflet control window is not a function - GIS Stack Exchange
This simply means that Leaflet library is not loaded because it's not where you are referencing it in your `<script src=... ></scipt> statement....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Quick workaround on users side:
Also added webpack config