2017-04-02 87 views
1

我已經設置了MapServer WMS服務的圖層。現在我正在嘗試使用OpenLayers庫編寫一個簡單的WMS客戶端。一般來說,我有一些結果,但有一些問題。有些點比其他點小。我嘗試使用QGIS和Leaflet庫連接到我的WMS服務。結果是完美的! OpenLayers lib有一些麻煩。這個例子有什麼問題?OpenLayers庫呈現MapServer WMS圖層出錯

客戶端:

  • 的OpenLayers V4.0.1
  • 視窗7 X64的SP1
  • 鉻57.0.2987.133 [Mozilla的/ 5.0(Windows NT的6.1; WOW64)爲AppleWebKit/537.36(KHTML,像壁虎)鉻/ 57.0.2987.133 Safari瀏覽器/ 537.36]
  • IE 11.0.9600 [Mozilla的/ 5.0(Windows NT的6.1; WOW64;三叉戟/ 7.0; RV:11.0)等壁虎]
  • 火狐51.0.1 [Mozilla的/ 5.0(Windows NT 6.1; WOW64; rv:51.0)Geck O/20100101火狐/ 51.0]

服務器端:

  • ms4w 3.1.4

活生生的例子:http://vector-sol.ru/apps/ol.html
下載ZIP與形狀文件,HTML頁面和配置映射文件:http://map31.ru:8080/example.zip

html頁面:

<!doctype html> 
<html lang="ru"> 
    <head> 
    <link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css"> 
    <style> 
    html, body { 
     margin: 0; 
     padding: 0; 
     height:100%; 
    } 
    #info { 
     position:absolute; 
     z-index:10; 
     background-color:yellow; 
     right: 0; 
    } 
    #map { 
     height:100%; 
    } 
    </style> 
    <script src="https://openlayers.org/en/v4.0.1/build/ol.js" type="text/javascript"></script> 
    <title>OpenLayers example</title> 
    </head> 
    <body> 
    <div id="map" class="map"> 
     <div id="info">OpenLayers example</div> 
    </div> 
    <script type="text/javascript"> 
     var map = new ol.Map({ 
     target: 'map', 
     layers: [ 
      new ol.layer.Tile({ 
      source: new ol.source.OSM() 
      }), 
      new ol.layer.Tile({ 
       source: new ol.source.TileWMS(({ 
        projection: 'EPSG:4326', 
        url: 'http://map31.ru:8080/cgi-bin/mapserv.exe?map=../htdocs/mydemo/wms_ol.map', 
        params: { 'LAYERS': 'pop_places', 'TILED': true }, 
        serverType: 'mapserver' 
       })) 
      })   
     ], 
     view: new ol.View({ 
      center: ol.proj.fromLonLat([37.41, 8.82]), 
      zoom: 4 
     }) 
     }); 
    </script> 
    </body> 
</html> 

MAP文件:

MAP 

    NAME "WMS" 
    IMAGETYPE  PNG 
    EXTENT -180 -90 180 90 # Geographic 
    SIZE 800 400 
    IMAGECOLOR 220 221 239 

    SYMBOL 
    NAME 'circle' 
    TYPE ELLIPSE 
    POINTS 1 1 END 
    FILLED TRUE 
    END 

    WEB 
    METADATA 
     wms_title     "WMS Demo" 
     wms_abstract    "Demo WMS Server" 
     wms_onlineresource   "http://map31.ru:8080/cgi-bin/mapserv.exe?map=../htdocs/mydemo/wms_ol.map&" 
     wms_srs     "EPSG:4326" 
     wms_getfeatureinfo   "http://map31.ru:8080/cgi-bin/mapserv.exe?map=../htdocs/mydemo/wms_ol.map&" 
     wms_featureinfoformat  "text/plain" 
     wms_enable_request   "*" 
    END 
    END 

    PROJECTION 
    "init=epsg:4326" 
    END 

    LAYER 
     NAME "pop_places" 
     TYPE POINT 
     STATUS ON 
     DATA 'shape/ne_10m_populated_places.shp' 
     PROJECTION 
     "init=epsg:4326" 
     END 
     CLASS 
     NAME "Pop Places" 
     STYLE 
      COLOR 10 100 50 
      SYMBOL 'circle' 
      SIZE 6   
     END 
     END 

     METADATA 
     wms_title "Populated Places" 
     wms_abstract "Populated places of the world" 
     wms_srs "EPSG:4326" 
     wms_include_items "all" 
     wms_enable_request "*" 
     #wms_extent "-180 -90 180 90" 
     END  

    END # layer 

END 

回答

0

projection: 'EPSG:4326'設置觸發客戶端光柵重投影,因爲默認視圖投影是'EPSG:3857'。您可能想要在該投影中使您的地圖工作,只需從ol.source.TileWMS配置中刪除projection: 'EPSG:4326'行。

+0

非常感謝!但我必須將我的WMS服務器輸出投影更改爲'EPSG:3857'。在這一步移除投影之後:'EPSG:4326'線產生了影響。所以,這是服務器端解決方案。但是,OpenLayers再投影有什麼問題? – bestjack

+0

它沒有錯。但在EPSG:4326和EPSG:3857之間重新投影時,目標分辨率隨緯度而變化。否則,你會看到模糊的圖像。 – ahocevar

+0

或者您可以將'wms_srs「EPSG:4326」'更改爲'wms_srs「EPSG:4326 EPSG:3857」'以獲得服務器端重新投影 – user27874