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

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

        • <bdo id='dBJML'></bdo><ul id='dBJML'></ul>
      1. <small id='dBJML'></small><noframes id='dBJML'>

        用于编辑谷歌地图折线的事件处理程序?

        时间:2023-09-04

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

              <bdo id='41Mof'></bdo><ul id='41Mof'></ul>

                  <tfoot id='41Mof'></tfoot>

                  <small id='41Mof'></small><noframes id='41Mof'>

                • <legend id='41Mof'><style id='41Mof'><dir id='41Mof'><q id='41Mof'></q></dir></style></legend>
                  本文介绍了用于编辑谷歌地图折线的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在寻找在您在 Google 地图中编辑折线时触发的事件,类似于标记上的拖动"事件.我找到了 'capturing_changed' 事件,但它似乎在 dragstart 和 dragend 上触发,而不是在 drag 上触发.因为我不得不重新发明轮子,允许拖动标记并根据标记的位置更新折线,基本上是重新发明可编辑的折线.我希望能够添加标记,可编辑的折线可以顺利完成,但我必须能够在拖动时检测到.我在 API 文档或 Google 搜索中找不到任何内容,所以我想我会在这里问.

                  I'm looking for an event that fires while you are editing a Polyline in Google Maps, similar to the 'drag' event on Markers. I've found the 'capturing_changed' event, but it seems to fire on dragstart and dragend, not on drag. As is I'm having to reinvent the wheel by allowing a Marker to be dragged and updating the Polyline based on where the Marker is, basically reinventing editable Polylines. I'd like to be able to add Markers, which editable Polylines do smoothly, but I have to be able to detect on drag. I can't find anything in the API documentation or on a Google search, so I thought I'd ask here.

                  推荐答案

                  文档中的简单折线示例 修改为添加更改事件(insert_at、remove_at、set_at、dragend).

                  The simple Polyline example from the documentation modified to add events on changes (insert_at, remove_at, set_at, dragend).

                  <!DOCTYPE html>
                  <html>
                    <head>
                      <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
                      <meta charset="utf-8">
                      <title>Google Maps JavaScript API v3 Example: Polyline Simple</title>
                      <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
                      <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
                      <script>
                  var flightPath = null;
                  
                        function initialize() {
                          var myLatLng = new google.maps.LatLng(0, -180);
                          var mapOptions = {
                            zoom: 3,
                            center: myLatLng,
                            mapTypeId: google.maps.MapTypeId.TERRAIN
                          };
                  
                          var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                  
                          var flightPlanCoordinates = [
                              new google.maps.LatLng(37.772323, -122.214897),
                              new google.maps.LatLng(21.291982, -157.821856),
                              new google.maps.LatLng(-18.142599, 178.431),
                              new google.maps.LatLng(-27.46758, 153.027892)
                          ];
                          flightPath = new google.maps.Polyline({
                            path: flightPlanCoordinates,
                            strokeColor: '#FF0000',
                            strokeOpacity: 1.0,
                            strokeWeight: 2,
                            editable: true,
                            draggable: true
                          });
                          google.maps.event.addListener(flightPath, "dragend", getPath);
                          google.maps.event.addListener(flightPath.getPath(), "insert_at", getPath);
                          google.maps.event.addListener(flightPath.getPath(), "remove_at", getPath);
                          google.maps.event.addListener(flightPath.getPath(), "set_at", getPath);
                          flightPath.setMap(map);
                        }
                  
                  function getPath() {
                     var path = flightPath.getPath();
                     var len = path.getLength();
                     var coordStr = "";
                     for (var i=0; i<len; i++) {
                       coordStr += path.getAt(i).toUrlValue(6)+"<br>";
                     }
                     document.getElementById('path').innerHTML = coordStr;
                  }
                  
                      </script>
                    </head>
                    <body onload="initialize()">
                      <div id="map-canvas" style="height:500px; width:600px;"></div>
                      <div id="path"></div>
                    </body>
                  </html>
                  

                  工作示例

                  代码片段:

                  var flightPath = null;
                  
                  function initialize() {
                    var myLatLng = new google.maps.LatLng(0, -180);
                    var mapOptions = {
                      zoom: 3,
                      center: myLatLng,
                      mapTypeId: google.maps.MapTypeId.TERRAIN
                    };
                  
                    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                  
                    var flightPlanCoordinates = [
                      new google.maps.LatLng(37.772323, -122.214897),
                      new google.maps.LatLng(21.291982, -157.821856),
                      new google.maps.LatLng(-18.142599, 178.431),
                      new google.maps.LatLng(-27.46758, 153.027892)
                    ];
                    flightPath = new google.maps.Polyline({
                      path: flightPlanCoordinates,
                      strokeColor: '#FF0000',
                      strokeOpacity: 1.0,
                      strokeWeight: 2,
                      editable: true,
                      draggable: true
                    });
                    google.maps.event.addListener(flightPath, "dragend", getPath);
                    google.maps.event.addListener(flightPath.getPath(), "insert_at", getPath);
                    google.maps.event.addListener(flightPath.getPath(), "remove_at", getPath);
                    google.maps.event.addListener(flightPath.getPath(), "set_at", getPath);
                    flightPath.setMap(map);
                  }
                  
                  function getPath() {
                    var path = flightPath.getPath();
                    var len = path.getLength();
                    var coordStr = "";
                    for (var i = 0; i < len; i++) {
                      coordStr += path.getAt(i).toUrlValue(6) + "<br>";
                    }
                    document.getElementById('path').innerHTML = coordStr;
                  }
                  google.maps.event.addDomListener(window, 'load', initialize);

                  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
                  <div id="path"></div>
                  <div id="map-canvas" style="height:500px; width:600px;"></div>

                  这篇关于用于编辑谷歌地图折线的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 jQuery 中绑定现有的 JavaScript 函数 下一篇:为什么必须将事件对象作为参数传递?

                  相关文章

                  最新文章

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

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

                      <tfoot id='cXMO0'></tfoot>
                      <legend id='cXMO0'><style id='cXMO0'><dir id='cXMO0'><q id='cXMO0'></q></dir></style></legend>