zoukankan      html  css  js  c++  java
  • openlayers moveend getEventCoordinate

    <!DOCTYPE html>
    <html>
      <head>
        <title>Moveend Event</title>
        <link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css">
        <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
        <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
        <script src="https://openlayers.org/en/v4.0.1/build/ol.js"></script>
      </head>
      <body>
        <div id="map" class="map"></div>
        <label>top</label><input type="text" id="top">
        <label>right</label><input type="text" id="right"><br>
        <label>bottom</label><input type="text" id="bottom">
        <label>left</label><input type="text" id="left">
        <script>
          var map = new ol.Map({
            layers: [
              new ol.layer.Tile({
                source: new ol.source.OSM()
              })
            ],
            target: 'map',
            controls: ol.control.defaults({
              attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
                collapsible: false
              })
            }),
            view: new ol.View({
              center: [0, 0],
              zoom: 2
            })
          });
     
          function display(id, value) {
            document.getElementById(id).value = value.toFixed(2);
          }
     
          function wrapLon(value) {
            var worlds = Math.floor((value + 180) / 360);
            return value - (worlds * 360);
          }
     
          function onMoveEnd(evt) {
            var map = evt.map;
            var extent = map.getView().calculateExtent(map.getSize());
            var bottomLeft = ol.proj.transform(ol.extent.getBottomLeft(extent),
                'EPSG:3857', 'EPSG:4326');
            var topRight = ol.proj.transform(ol.extent.getTopRight(extent),
                'EPSG:3857', 'EPSG:4326');
            display('left', wrapLon(bottomLeft[0]));
            display('bottom', bottomLeft[1]);
            display('right', wrapLon(topRight[0]));
            display('top', topRight[1]);
          }
     
          map.on('moveend', onMoveEnd);
        </script>
      </body>
    </html>

    如果这篇文章对您有帮助,您可以打赏我

    技术交流QQ群:15129679

  • 相关阅读:
    .NET 2.0泛型集合类与.NET 1.1集合类的区别(二)
    关于插件的好文章
    MemberInfo.GetCustomAttributes和MemberDescriptor.Attributes获取特性的不同
    新一代编程语言
    .NET 2.0泛型集合类与.NET 1.1集合类的区别(一)
    发现一篇关于.NET 2.0中关于事务命名空间的好文章
    C# WinForm控件美化扩展系列之给TextBox加水印
    log4.net
    C# GDI+ 双缓冲
    C# WinForm控件美化扩展系列之ListBox
  • 原文地址:https://www.cnblogs.com/yeminglong/p/15339173.html
Copyright © 2011-2022 走看看