Leaflet: Map container not found

后端 未结 3 1568
孤街浪徒
孤街浪徒 2020-12-30 19:02

I have the below react class which fetches the geolocation through the browser.

I am mapping a leaflet map. I want to geolocation to be an input to the setView, for

相关标签:
3条回答
  • 2020-12-30 19:36

    In addition to @IvanSanchez's response, You could add the geolocation and L.map(...) code to componentDidMount() React lifecycle method (depending on what other goals you hope to achieve). You could also create and bind event handlers for location found as well.

    This way must have been added the dom and leaflet can find it.

    Happy to help with this if it's still unclear.

    0 讨论(0)
  • 2020-12-30 19:36

    I hope this helps if you are using Angular:

    const container = document.getElementById('map')
    if(container) {
        // code to render map here...
    }
    
    0 讨论(0)
  • 2020-12-30 19:38

    The <div id="leafletmap"> must be added to the dom before calling L.map('leafletmap').

    0 讨论(0)
提交回复
热议问题