首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想删除坐标并显示有关位置数据的信息

我想删除坐标并显示有关位置数据的信息
EN

Stack Overflow用户
提问于 2017-10-28 19:10:02
回答 1查看 383关注 0票数 0

我想删除坐标并显示有关位置数据的信息

AsslamOAlikum。嗨,我在geoserver的帮助下创建了openlayer地图。我的地图应用程序基于javascript和openlayer (OSM,WMS)。在我的应用程序中,我使用了多层、鼠标处理和定位以及弹出功能。但是我想在我的弹出功能中做一些改变。在弹出功能中,当我单击鼠标按钮时,显示'E,W,Degree‘等的坐标。我想将坐标替换更改为获取有关该地点的特色信息。这是我的代码......

代码语言:javascript
复制
<!DOCTYPE html>
<html>
  <head>
    <title>Overlay</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.4.2/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.4.2/build/ol.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <style>
      #marker {
        width: 20px;
        height: 20px;
        border: 1px solid #088;
        border-radius: 10px;
        background-color: #0FF;
        opacity: 0.5;
      }
      #vienna {
        text-decoration: none;
        color: white;
        font-size: 11pt;
        font-weight: bold;
        text-shadow: black 0.1em 0.1em 0.2em;
      }
      .popover-content {
        min-width: 180px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <div style="display: none;">
      <!-- Popup -->
      <div id="popup" title="Welcome to OpenLayers"></div>
    </div>

     <div id="nodelist">
        <em>Click on the map to get feature info</em>
    </div>
    <div id="mouse-position"></div>
    <form>
      <label>Projection </label>
      <select id="projection">
        <option value="EPSG:4326">EPSG:4326</option>
      </select>
      <label>Precision </label>
      <input id="precision" type="number" min="0" max="12" value="4"/>
    </form>

    <script>

        //MOUSE HANDLING
         var mousePositionControl = new ol.control.MousePosition({
        coordinateFormat: ol.coordinate.createStringXY(4),
        className: 'custom-mouse-position',
        target: document.getElementById('mouse-position'),
        undefinedHTML: '&nbsp;'
      });



        var LonLat = [69.3451, 30.3753];
    var pos = ol.proj.fromLonLat(LonLat);

      var layer =[ 
        new ol.layer.Tile({
        source: new ol.source.OSM()
      }),
      new ol.layer.Tile({
          //extent: [68.107725, 23.744288, 73.622861, 36.878836],
          source: new ol.source.TileWMS({
            url: 'http://gulraiz-pc:8080/geoserver/test/wms',
            params: {LAYERS: 'test:pak_ad3_gaul_ply_15072010', 'TILED': true},
            serverType: 'geoserver'

          })
        }),
        new ol.layer.Tile({
          //extent: [68.107725, 23.744288, 73.622861, 36.878836],
          source: new ol.source.TileWMS({
            url: 'http://gulraiz-pc:8080/geoserver/test/wms',
            params: {'LAYERS': '  test:longlist', 'TILED': true},
            serverType: 'geoserver'

          })
        })
    ];
      var map = new ol.Map({
          controls: ol.control.defaults({
          attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
//            collapsible: false
          })
        }).extend([mousePositionControl]),
        layers: layer,
        target: 'map',
        view: new ol.View({
          center: pos,
          zoom: 5
        })
      });



      // Popup showing the position the user clicked
      var popup = new ol.Overlay({
        element: document.getElementById('popup')
      });
      map.addOverlay(popup);



      map.on('click', function(evt) {
        var element = popup.getElement();
        var coordinate = evt.coordinate;
        var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
            coordinate, 'EPSG:4326', 'EPSG:4326'));

        $(element).popover('destroy');
        popup.setPosition(coordinate);
        // the keys are quoted to prevent renaming in ADVANCED mode.
        $(element).popover({
          'placement': 'top',
          'animation': false,
          'html': true,
          'content': '<p>The location you clicked was:</p><code>' + hdms + '</code>'
        });
        $(element).popover('show');
      });


    </script>
  </body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2017-10-29 21:40:39

不太明白你所要求的是什么。假设你想要的是特征的坐标,而不是点击。

forEachFeatureAtPixel(pixel, (f) => { coordinate = f.getGeometry().getCoordinates(); }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46989039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档