View vector GeoServer line layer in Leaflet
I have simple line layer created based on shapefiles. It can be viewed in GeoServer with OpenLayers preview:
I also can be imported and correctly viewed in QGIS.
I tried to visualize this layer over OSM map in my leaflet:
var map = L.map('map',
);
map.setView([35.6, 25], 8);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © OpenStreetMap contributors'
}).addTo(map);
var WMSe = "http://xx.xxx.xx.xxx:8080/geoserver/wms";
var OHLayer = L.tileLayer.wms(WMSe, {
layers: 'fch:OHL-fch',
format: 'image/png',
transparent: true,
format_options: 'layout:message',
attribution: "Algum texto de teste",
layout: 'message',
}).addTo(map)
where fch:OHL-fch in name of layer in layer preview in GeoServer.
When I run this, all I get is OSM map without line layer.
Any help in resolving this is appreciable.
Geoserver preview request:
http://xx.xxx.xx.xxx:8080/geoserver/fch/wms?service=WMS&version=1.1.0&request=GetMap&layers=fch%3AOHL-fch&bbox=23.6974544525146%2C35.0042533874512%2C26.1459541320801%2C35.4908332824707&width=768&height=330&srs=EPSG%3A4326&styles=&format=application/openlayers
leaflet request(NOT working):
URL: http://xx.xxx.xx.xxx:8080/geoserver/wms?service=WMS&request=GetMap&layers=%20fch%3AOHL-fch&styles=&format=image%2Fpng&transparent=true&version=1.1.1&format_options=layout%3Amessage&layout=message&height=256&width=256&srs=EPSG%3A3857&bbox=2191602.4749925733,4226661.916057106,2348145.5089206146,4383204.949985149
leaflet request(working):
URL: http://xx.xxx.xx.xxy:8080/geoserver/wms?service=WMS&request=GetMap&layers=%20fch%3AOHL-fch&styles=&format=image%2Fpng&transparent=true&version=1.1.1&format_options=layout%3Amessage&layout=message&height=256&width=256&srs=EPSG%3A3857&bbox=2817774.6107047372,3913575.848201024,2974317.644632778,4070118.8821290666
Print of leaflet layer:
_container:
_crs: {latLngToPoint: function, pointToLatLng: function, project: function, unproject: function, scale: function, …}
_events: {remove: Array}
_fadeFrame: 163
_globalTileRange: {min: Object, max: Object, extend: function, getCenter: function, getBottomLeft: function, …}
_initHooksCalled: true
_leaflet_id: 83
_level: {el: , origin: Object, zoom: 8}
_levels: {8: Object}
_loading: false
_map: e {options: Object, _container: , _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …}
_mapToAdd: e {options: Object, _container: , _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …}
_noPrune: false
_onMove: function()
_tileSize: {x: 256, y: 256, clone: function, add: function, _add: function, …}
_tileZoom: 8
_tiles: {145:100:8: Object, 145:101:8: Object, 144:100:8: Object, 146:100:8: Object, 144:101:8: Object, …}
_url: "http://xx.xxx.xx.xx:8080/geoserver/wms"
_wmsVersion: 1.1
_wrapX: [0, 256] (2)
_wrapY: undefined
_zoomAnimated: true
options: {layers: "fch:OHL-fch", format: "image/png", transparent: true, format_options: "layout:message", attribution: "Algum texto de teste", …}
wmsParams: {service: "WMS", request: "GetMap", layers: "fch:OHL-fch", styles: "", format: "image/png", …}