【问题标题】:how to display leaflet map in specific div tag?如何在特定的 div 标签中显示传单地图?
【发布时间】:2020-02-05 18:11:03
【问题描述】:

我正在尝试显示传单地图,但我需要使用像 document.getElementById("map") 这样的 ID 在特定 div 标签中显示地图,我在下面给出了代码,我正在使用 vuejs。

下面是我用来渲染地图的 div 标签

         <div id="map">
         </div>

下面是我的脚本

         mounted () {
            //    L.Icon.Default.imagePath = 'assets/vendor/leaflet' TODO: make it work with webpack
            Leaflet.Icon.Default.imagePath = 'https://unpkg.com/leaflet@1.0.3/dist/images'

            let map = Leaflet.map(this.$el).setView([51.505, -0.09], 13)

            Leaflet.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
              attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors',
            }).addTo(map)

            Leaflet.marker([51.5, -0.09]).addTo(map)
              .bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
              .openPopup()
          },

【问题讨论】:

    标签: javascript google-maps dictionary vue.js leaflet


    【解决方案1】:

    我不知道 Vue,但通常你不需要创建 document.getElementById ("map")。 你只需要像这样在 L.map 中传递 id

    let map = Leaflet.map("map").setView([51.505, -0.09], 13)
    

    例如,您必须为 div“地图”指定高度

     <div id="map" height="500px">
     </div>
    

    编辑

    怎么了?在我的codesandbox 上,您可以看到正常显示的 html 和 javascrip 示例。这是一个使用Leaflet and Vuejs的教程的链接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 2017-01-10
      • 2021-08-02
      相关资源
      最近更新 更多