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

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

        传单 panTo(或 setview)功能?

        时间:2023-08-08
          <bdo id='Hqx3s'></bdo><ul id='Hqx3s'></ul>

            1. <tfoot id='Hqx3s'></tfoot>
                <tbody id='Hqx3s'></tbody>
              <i id='Hqx3s'><tr id='Hqx3s'><dt id='Hqx3s'><q id='Hqx3s'><span id='Hqx3s'><b id='Hqx3s'><form id='Hqx3s'><ins id='Hqx3s'></ins><ul id='Hqx3s'></ul><sub id='Hqx3s'></sub></form><legend id='Hqx3s'></legend><bdo id='Hqx3s'><pre id='Hqx3s'><center id='Hqx3s'></center></pre></bdo></b><th id='Hqx3s'></th></span></q></dt></tr></i><div id='Hqx3s'><tfoot id='Hqx3s'></tfoot><dl id='Hqx3s'><fieldset id='Hqx3s'></fieldset></dl></div>
                • <small id='Hqx3s'></small><noframes id='Hqx3s'>

                  <legend id='Hqx3s'><style id='Hqx3s'><dir id='Hqx3s'><q id='Hqx3s'></q></dir></style></legend>
                • 本文介绍了传单 panTo(或 setview)功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想创建一个 panTo 函数.当我单击链接时,地图会平移到坐标.但我不确定如何将值传递给函数.我开始为链接提供 Pointfield (pt) 值,如下所示:

                  I want to create a panTo -function. When I click a link the map pans to the coordinates. But im not sure how to pass the value to the function. I'm starting with giving the link the Pointfield (pt) value like this:

                  <a href="#" class="marker" value="{{ mymodel.pt }}">Link</a>
                  

                  然后我一直在尝试这个:

                  Then I've been trying this:

                  $("#dialog").on("click", ".marker", function(e) {
                      e.preventDefault();
                      map.panTo($(this).attr("value"));
                      });
                  

                  那没用.我认为这是一个范围问题,函数无法读取地图"变量,因为它不在初始地图脚本下.

                  That didn't work. I think it's a scope-issue where the function cant read the 'map' variable because it's not under the initial map script.

                  所以我的下一个想法是创建一个panTo"- 函数并将其放在初始地图脚本(这将是正确的范围)下,然后从点击事件中调用该函数.不确定它会起作用,但我想知道如何从链接中传递值"?

                  So my next idea is to create a "panTo"- function and place it under the inital map script (which would be the right scope) and call that function from the click event instead. Not sure it would work but Im wondering how to pass it the "value" from the link?

                  感谢您的回答!

                  推荐答案

                  您可以利用 HTML 中的 data 属性向地图添加导航.将纬度、经度和缩放保存到类似 data-position 的位置,然后在用户单击锚标记时使用一些 JavaScript 调用这些值.这里有一些代码来说明.

                  You can add navigation to your map by utilizing data attributes in your HTML. Save the latitude,longitude and zoom to something like data-position and then call those values with some JavaScript when the user clicks on the anchor tag. Here's some code to illustrate.

                  <div id="map">
                      <div id="map-navigation" class="map-navigation">
                          <a href="#" data-zoom="12" data-position="37.7733,-122.4367">
                              San Francisco
                          </a>
                      </div>
                  </div>
                  
                  <script>
                  var map = L.map('map').setView([51.505, -0.09], 13);
                  
                  L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
                                  maxZoom: 18,
                                  attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
                              }).addTo(map);
                  
                  document.getElementById('map-navigation').onclick = function(e) {
                      var pos = e.target.getAttribute('data-position');
                      var zoom = e.target.getAttribute('data-zoom');
                      if (pos && zoom) {
                          var loc = pos.split(',');
                          var z = parseInt(zoom);
                          map.setView(loc, z, {animation: true});
                          return false;
                      }
                  }
                  </script>
                  

                  这篇关于传单 panTo(或 setview)功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在传单地图上突出显示选定的行? 下一篇:基于 Leaflet 和 AngularJS 的地图未正确加载

                  相关文章

                  最新文章

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

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

                    <legend id='QsRNf'><style id='QsRNf'><dir id='QsRNf'><q id='QsRNf'></q></dir></style></legend>