Cool, I had the same question one hour ago. Here goes the summary.
Note:
What the OP calls XYZ
format is the format popularized by Google Maps where a global/basemap is server-side split and served as tiles in a {z}/{x}/{y}
format where zoom, latitude and longitude are represented internally [1].
Effectively, the name of the service providing such "format" is Tile Map Service (TMS)
[2], and GeoServer does provide such service [3].
XYZ
is just the name of the class in OpenLayers used to access a TMS
server [4].
That being said, here is how you'd do to have a TMS service running between your GeoServer and OpenLayers:
- Check if your GeoServer' Caching Defaults has GeoWebCache and the TMS service enabled. I am currently using GS-2.14.3 and those are enabled by default.
With GWC and TMS enabled you should see your raster layers listed under http://localhost:8080/gwc/service/tms/1.0.0
(or, in general, <geoserver-path>/gmc/service/tms/1.0.0
).
Then, you just have to call one of those TileMaps from OpenLayer:
var tileURL = "<tilemap-from-gwc-list-above>" + "/{z}/{x}/{-y}.jpg" // or '.png'
var map = new ol.Map(<your params here>);
var bm = new ol.layer.Tile({
source: new ol.source.XYZ({
url: tileURL
})
})
map.addLayer(bm)
Hope that helps.
Cheers.
Refs:
- Google/TMS format: https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/
- TMS specification: https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification
- TMS in Leaflet: https://leafletjs.com/examples/wms/wms.html#tms-in-leaflet
- TMS/XYZ OpenLayers: https://openlayers.org/en/latest/apidoc/module-ol_source_XYZ-XYZ.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…