• <small id='i3xix'></small><noframes id='i3xix'>

  • <tfoot id='i3xix'></tfoot>
  • <legend id='i3xix'><style id='i3xix'><dir id='i3xix'><q id='i3xix'></q></dir></style></legend>
      • <bdo id='i3xix'></bdo><ul id='i3xix'></ul>

        <i id='i3xix'><tr id='i3xix'><dt id='i3xix'><q id='i3xix'><span id='i3xix'><b id='i3xix'><form id='i3xix'><ins id='i3xix'></ins><ul id='i3xix'></ul><sub id='i3xix'></sub></form><legend id='i3xix'></legend><bdo id='i3xix'><pre id='i3xix'><center id='i3xix'></center></pre></bdo></b><th id='i3xix'></th></span></q></dt></tr></i><div id='i3xix'><tfoot id='i3xix'></tfoot><dl id='i3xix'><fieldset id='i3xix'></fieldset></dl></div>

        如何将 Leaflet 地图嵌入到 Reveal.js 演示文稿中?

        时间:2023-08-08
            <i id='did4g'><tr id='did4g'><dt id='did4g'><q id='did4g'><span id='did4g'><b id='did4g'><form id='did4g'><ins id='did4g'></ins><ul id='did4g'></ul><sub id='did4g'></sub></form><legend id='did4g'></legend><bdo id='did4g'><pre id='did4g'><center id='did4g'></center></pre></bdo></b><th id='did4g'></th></span></q></dt></tr></i><div id='did4g'><tfoot id='did4g'></tfoot><dl id='did4g'><fieldset id='did4g'></fieldset></dl></div>
              1. <legend id='did4g'><style id='did4g'><dir id='did4g'><q id='did4g'></q></dir></style></legend>
                  <tbody id='did4g'></tbody>

                  <bdo id='did4g'></bdo><ul id='did4g'></ul>

                  <small id='did4g'></small><noframes id='did4g'>

                  <tfoot id='did4g'></tfoot>
                  本文介绍了如何将 Leaflet 地图嵌入到 Reveal.js 演示文稿中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个在 Reveal.js 之上运行的演示文稿,该演示文稿将在其中一张幻灯片中包含一个 Leaflet.js 地图.我已经包含了所有必要的 Javascript &CSS 文件到我的 Reveal.js 演示文稿中,我可以使地图出现在幻灯片上.

                  I am trying to create a presentation running on top of Reveal.js, which would include a Leaflet.js map within one of the slides. I have included all necessary Javascript & CSS files into my Reveal.js presentation and I can make the map appear on the slide.

                  但是,问题是:地图图块显示不正确.我看到的不是实际的地图图块,而是灰色背景和一些水平黑线.我可以放大/缩小并平移地图,并且黑线会相应移动.

                  However, the problem is: map tiles are not displayed correctly. Instead of the actual map tiles, all I am seeing is gray background and some horizontal black lines. I can zoom in/out and pan the map, and the black lines are moving accordingly.

                  Javascript 控制台中没有错误消息,并且浏览器似乎正在按照应有的方式从服务器下载地图图块.我相信这个问题与 Leaflet 地图图块的 CSS 代码有关 - .leaflet-tile 在 leaflet.css 中 - 在某种程度上与 Reveal.js 不兼容.

                  There are no error message in the Javascript console, and the browser seems to be downloading map tiles from server exactly as it should. I believe the problem has something to do with the CSS code of Leaflet map tiles - .leaflet-tile within leaflet.css - being somehow incompatible with Reveal.js.

                  问题是:有谁知道如何解决这个问题?还是没有解决办法的死胡同?

                  The question is: Does anyone know how to get around this issue? Or is it a deadend with no possible solution?

                  <div id="map"> 我有以下 CSS:

                  #map {
                      height:400px;
                      width:100%;
                  }
                  

                  一个明显的解决方法是使用 <iframe> 标签将地图嵌入到演示文稿中.似乎工作得很好,也许将框架分开会更好.然而,不利的一面是,如果演示文稿中有多个地图,每个地图都在其自己的 <iframe> 中,则 Leaflet.js 的副本会为每个 iframe 加载到内存中.

                  One obvious workaround for this is to use <iframe> tag to embed the map into the presentation. Seems to work just fine, and maybe it is better to keep the frameworks separated. However, the downside is that if there are several maps in the presentation, each within its own <iframe>, a copy of Leaflet.js is loaded to memory for each and every iframe.

                  编辑 #2: 一个更好的解决方案似乎是使用 PolymapsLeaflet.js.似乎可以将多个 Polymaps 地图嵌入到 reveal.js 演示文稿中.没有问题.

                  EDIT #2: A better solution, it seems, is to use Polymaps instead of Leaflet.js. It seems that several Polymaps maps can be embedded into a reveal.js presentaion. No issues.

                  推荐答案

                  我发现用 web 组件很容易做到,这样,shadow dom 将保护我的传单地图免受揭示 css 的邪恶之手

                  I found it easily to do it with a web component, this way, the shadow dom will protect my leaflet map from the evil hands of reveals css

                  这是一个带有示例的仓库

                  <link rel="import" href="./leaflet-map.html">
                  ...
                  <div class="reveal">
                    <div class="slides">
                      <section data-state="map">
                         <leaflet-map></leaflet-map>
                      </section>
                    </div>
                  </div>
                  

                  这是网页组件

                  <template id="leaflet-map-template">
                  <link rel="stylesheet" href="./bower_components/leaflet/dist/leaflet.css">
                  <div id="mapid" style="height: 500px"></div>
                      <!-- LEAFLET JS -->
                  </template>
                  <script src="./bower_components/leaflet/dist/leaflet.js"></script>
                  <script>
                      class LeafletMap extends HTMLElement {
                          constructor () {
                              super();
                              let tmpl = document.currentScript.ownerDocument.querySelector('template')
                              let shadowRoot = this.attachShadow({mode: 'open'})
                              shadowRoot.appendChild(tmpl.content.cloneNode(true))
                  
                              let mapDiv = this.shadowRoot.getElementById('mapid')
                              this.map = L.map(mapDiv).setView([19.39682052576622, -99.13478851318361], 13)
                              // this.setAttribute('map', map)
                              // Tiles de open street maps
                              //L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(map)
                  
                              L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
                                  maxZoom: 18,
                                  attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
                                      '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
                                      'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
                                  id: 'mapbox.streets'
                              }).addTo(this.map)
                              let myIcon = L.icon({
                                  iconUrl: './lentes.png',
                  
                                  iconSize:     [40, 40], // size of the icon
                                  iconAnchor:   [20, 20], // point of the icon which will correspond to marker's location
                                  tooltipAnchor: [20,0]
                              })
                              L.marker(
                                  [19.418657758792698, -99.14065182209016],
                                  {icon: myIcon}
                              ).bindTooltip('Ranchito').addTo(this.map)
                          }
                  
                          resize() {
                              this.map.invalidateSize()
                          }
                      }
                      window.customElements.define('leaflet-map', LeafletMap)
                  </script>
                  

                  这篇关于如何将 Leaflet 地图嵌入到 Reveal.js 演示文稿中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:OpenStreetMap 经常发送网关超时错误 下一篇:如何在传单地图上突出显示选定的行?

                  相关文章

                  最新文章

                  <tfoot id='7zGpP'></tfoot>

                    <bdo id='7zGpP'></bdo><ul id='7zGpP'></ul>

                    <small id='7zGpP'></small><noframes id='7zGpP'>

                    1. <legend id='7zGpP'><style id='7zGpP'><dir id='7zGpP'><q id='7zGpP'></q></dir></style></legend>
                    2. <i id='7zGpP'><tr id='7zGpP'><dt id='7zGpP'><q id='7zGpP'><span id='7zGpP'><b id='7zGpP'><form id='7zGpP'><ins id='7zGpP'></ins><ul id='7zGpP'></ul><sub id='7zGpP'></sub></form><legend id='7zGpP'></legend><bdo id='7zGpP'><pre id='7zGpP'><center id='7zGpP'></center></pre></bdo></b><th id='7zGpP'></th></span></q></dt></tr></i><div id='7zGpP'><tfoot id='7zGpP'></tfoot><dl id='7zGpP'><fieldset id='7zGpP'></fieldset></dl></div>