React-Leaflet marker files not found

后端 未结 2 1030
既然无缘
既然无缘 2020-12-31 08:28

I\'ve got very simple code to display a map using react-leaflet and place a marker on it. However, i get the following two errors in my browser console

<
相关标签:
2条回答
  • 2020-12-31 08:54

    It seems not all stuff is properly integrated together when using react, leaflet and react-leaflet. I had the same problem and found this

    https://github.com/PaulLeCam/react-leaflet/issues/453

    You need to setup leafelet itself again, as something brokes after importing leaflet.css.

    Hope it helps

    0 讨论(0)
  • 2020-12-31 09:13

    Try to do this :)

    React leaflet for some reason do not include images and you will need to reset default icons image.

    Below is some working example, I hope it will solve your issue.

    You also can add icons from one of public link

    https://cdnjs.com/libraries/Leaflet.awesome-markers

    import React, { Component } from 'react';
    import L from 'leaflet';
    import {
        Map, TileLayer, Marker, Popup
    } from 'react-leaflet'
    import 'leaflet/dist/leaflet.css';
    import './style.css';
    
    
    import icon from 'leaflet/dist/images/marker-icon.png';
    import iconShadow from 'leaflet/dist/images/marker-shadow.png';
    
    let DefaultIcon = L.icon({
        iconUrl: icon,
        shadowUrl: iconShadow
    });
    
    L.Marker.prototype.options.icon = DefaultIcon;
    
    0 讨论(0)
提交回复
热议问题