Ich habe MapServer WMS-Dienst mit einer Punktschicht eingerichtet. Und jetzt versuche ich mit der OpenLayers-Bibliothek einen einfachen WMS-Client zu schreiben. Im Allgemeinen habe ich einige Ergebnisse, aber mit einigen Problemen. Einige Punkte sind kleiner als andere. Ich habe versucht, eine Verbindung zu meinem WMS-Service mit QGIS und Leaflet-Bibliothek herzustellen. Die Ergebnisse sind perfekt! Es gibt einige Probleme mit OpenLayers lib. Was ist falsch an diesem Beispiel?OpenLayers-Bibliothek rendert MapServer WMS-Layer mit Fehlern
Client-Seite:
- Openlayers v4.0.1
- Windows 7 x64 SP1
- Chrome 57.0.2987.133 [Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537,36 (KHTML, wie Gecko) Chrom/57.0.2987.133 Safari/537,36]
- IE 11.0.9600 [Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv: 11.0) wie Gecko]
- Firefox 51.0.1 [Mozilla/5.0 (Windows NT 6.1; WOW64; rv: 51.0) Geck o/20100101 Firefox/51,0]
Server-Seite:
- MS4W 3.1.4
anschauliches Beispiel: http://vector-sol.ru/apps/ol.html
Download zip mit Shape-Datei, HTML-Seite und Config-Map-Datei : http://map31.ru:8080/example.zip
html seite:
<!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-Datei:
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
Vielen Dank! Aber ich musste meine WMS-Server-Ausgangsprojektion auf "EPSG: 3857" ändern. Und nach diesem Schritt die Projektion zu entfernen: 'EPSG: 4326' Linie hatte einen Einfluss. Also, das ist Server-seitige Lösung. Aber was ist falsch mit OpenLayers Reprojektion? – bestjack
Es ist nichts falsch daran. Die Zielauflösung ändert sich jedoch mit der Breite bei der Neuprojektion zwischen EPSG: 4326 und EPSG: 3857. Sonst würden Sie unscharfe Bilder bekommen. – ahocevar
oder Sie könnten 'wms_srs 'ändern EPSG: 4326" 'zu' wms_srs "EPSG: 4326 EPSG: 3857" ', um serverseitige Reprojektion zu erhalten – user27874