2017-10-28 94 views
0

我想移除座標並顯示有關地點數據的信息

AsslamOAlikum。您好,我在geoserver的幫助下創建了一個入門地圖。我的地圖應用程序基於JavaScript和Openlayers(OSM,WMS)。在我的應用程序中,我使用多層,鼠標處理&定位和彈出功能。但我想在彈出功能中改變一些。在我彈出的功能,當我點擊鼠標按鈕,然後顯示'E,W,度'等的座標。我想改變座標替換到獲取關於這個地方的特色信息。這是我的代碼......我想移除座標並顯示有關地點數據的信息

<!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> 
+0

座標顯示,但我想表中的格式的信息。在這樣的表中鏈接 https://openlayers.org/en/latest/examples/getfeatureinfo-image.html –

回答

0

不太明白你在問什麼。假設您想要該特徵的座標而不是點擊。

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

+0

座標顯示,但我想表中的格式的信息。在這樣的表中鏈接 https://openlayers.org/en/latest/examples/getfeatureinfo-image.html –

+0

座標正在工作,但我需要表中的信息我發送上面的鏈接 請觀看鏈接並解決我的問題。 我嘗試,但它的拋出異常。 –

+0

否。請執行此示例,並使用WMS信息URL或從功能中提取信息並構建表。 'var title = f.get('TITLE'); VAR HTML = '

​​' +標題+ '
標題
'; ' –

相關問題