• <legend id='ngHjH'><style id='ngHjH'><dir id='ngHjH'><q id='ngHjH'></q></dir></style></legend>

    • <bdo id='ngHjH'></bdo><ul id='ngHjH'></ul>

  • <tfoot id='ngHjH'></tfoot>

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

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

        传单:找不到地图容器

        时间:2023-05-28
        <tfoot id='amDTB'></tfoot>

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

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

            1. <small id='amDTB'></small><noframes id='amDTB'>

              • <legend id='amDTB'><style id='amDTB'><dir id='amDTB'><q id='amDTB'></q></dir></style></legend>

                1. 本文介绍了传单:找不到地图容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有下面的反应类,它通过浏览器获取地理位置.

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

                  我正在绘制一张传单地图.我想将地理位置作为 setView 的输入,以便地图缩放"到客户端浏览器位置的区域.

                  I am mapping a leaflet map. I want to geolocation to be an input to the setView, for such that the map "zooms" into the region of the client browser location.

                  这是反应类:

                      import React from 'react';
                      import L from 'leaflet';
                      import countries from './countries.js'; 
                  
                      var Worldmap = React.createClass({
                  
                          render: function() {
                  
                              let geolocation = [];
                  
                              navigator.geolocation.getCurrentPosition(function(position) {
                                  let lat = position.coords.latitude;
                                  let lon = position.coords.longitude;
                                  geolocation.push(lat, lon);
                                  locationCode()
                              });
                  
                              function locationCode() {
                                  if(geolocation.length <= 0)
                                      geolocation.push(0, 0);
                              }
                  
                  
                              let map = L.map('leafletmap').setView(geolocation, 3);
                  
                              L.geoJSON(countries, {
                                  style: function(feature) {
                                      return {
                                          fillColor: "#FFBB78",
                                          fillOpacity: 0.6,
                                          stroke: true,
                                          color: "black",
                                          weight: 2
                                      };
                                  }
                              }).bindPopup(function(layer) {
                                  return layer.feature.properties.name;
                              }).addTo(map);
                  
                              return (
                                  <div id="leafletmap" style={{width: "100%", height: "800px" }}/>
                              )
                          }
                      });
                  
                      export default Worldmap
                  

                  在 HTML 呈现为 <WorldMap/> 的主文件中调用它.

                  It's called in a main file where the HTML is rendered as <WorldMap />.

                  我在加载页面时收到错误 Uncaught Error: Map container not found..环顾四周,通常是因为地图在提供值之前试图在 div 中显示(在这种情况下为 (gelocation, 3)).但是,它不应该在从下面的渲染函数返回之前显示它.

                  I get the error Uncaught Error: Map container not found. when loading the page. Looking around, usually it would be because the map is trying to be displayed in a div before being provided values((gelocation, 3) in this case). However, it shouldn't display it before being returned from the render function below.

                  可能是什么问题?

                  在控制台中打印出 geolocation 可以正确获取坐标,因此这似乎不是问题.

                  Printing out the geolocation in the console correctly fetches the coordinates, so that doesn't seem to be the issue.

                  推荐答案

                  <div id="leafletmap"> 必须添加到dom before 调用 L.map('leafletmap').

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

                  这篇关于传单:找不到地图容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将传单输出保存为 html 下一篇:Leaflet 是非地图图像的好工具吗?

                  相关文章

                  最新文章

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

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

                      <tfoot id='C4nmA'></tfoot>
                      • <bdo id='C4nmA'></bdo><ul id='C4nmA'></ul>