2

I have simple line layer created based on shapefiles. It can be viewed in GeoServer with OpenLayers preview:

enter image description here

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: <div class="leaflet-layer ">
_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: <div class="leaflet-tile-container leaflet-zoom-animated">, origin: Object, zoom: 8}
_levels: {8: Object}
_loading: false
_map: e {options: Object, _container: <div id="map">, _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …}
_mapToAdd: e {options: Object, _container: <div id="map">, _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", …}
12
  • is there any data actually returned by the request? Does it work for other formats?
    – Ian Turton
    Jan 14, 2022 at 10:15
  • What does the WMS request generated by Leaflet look like compared with the request in Geoserver preview? What is the CRS of the layer?
    – TomazicM
    Jan 14, 2022 at 10:23
  • Is that blank space at ' fch:OHL-fch' intended? Jan 14, 2022 at 12:11
  • @IvanSanchez its a typo. I shortened layer name when copying code due to privacy. I have edited it in text above. Anyway not working with original name. Jan 14, 2022 at 12:53
  • @TomazicM Added link from WMS request from Geoserver. Not sure how to view Leaflet request? I have added print out of entire layer to code. If you need any particular data I can print it out. CRS of layer is WGS84 - EPSG:4326. Jan 14, 2022 at 13:13

1 Answer 1

0

I eventually figured out what was the problem. Part of leaflet request:

format_options: 'layout:message',
//attribution: "Algum texto de teste",
layout: 'message'

was calling for layout:message WMS decorator which wasn't declared in Geoserver settings. Hence, after removing these from leaflet request, everything worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.