Sunday 31 July 2016

wmts layer in Openlayers from Geoserver


I have some layers in Geoserver(latest stable) that came from PostGIS data (they belong to a store with PostGIS type and gets data from a PostGIS database)


In those layers there are only WMS settings, not WMTS



I went to Caching Defaults in Geoserver, the WMTS Service is already enabled.


So I went to my Openlayers and try this, so I can get a PostGIS-based layer, from Geoserver to the map.


var projection = ol.proj.get('EPSG:3857');
var textent = ol.proj.transformExtent([2297128.5, 4618333, 2459120.25, 4763120], 'EPSG:900913', 'EPSG:3857');
var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(14);
var matrixIds = new Array(14);
for (var z = 0; z < 14; ++z) {
// generate resolutions and matrixIds arrays for this WMTS

resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = z;
}

var ait = new ol.layer.Tile({
opacity: 0.7,
extent: textent,
source: new ol.source.WMTS({
url: 'http://localhost:8080/geoserver/mymap/wmts?',
layer: 'mymap:planet_osm_polygon, mymap:planet_osm_line, mymap:planet_osm_roads, mymap:planet_osm_point',

matrixSet: 'EPSG:3857',
format: 'image/png',
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
resolutions: resolutions,
matrixIds: matrixIds
}),
style: 'default'
})

})

planet_osm_polygon, planet_osm_line, planet_osm_roads and planet_osm_point are composing the final layer. In simple WMS settings would be params: {'LAYERS': 'mymap:planet_osm_polygon, mymap:planet_osm_line, mymap:planet_osm_roads, mymap:planet_osm_point'.... but, in the WMTS case I dont know how I should set them, so that why I set them in layer


This does not work, I get


GET http://localhost:8080/geoserver/mymap/wmts?layer=mymap%3Aplanet_osm_polygon%2C%20mymap%3Aplanet_osm_line%2C%20mymap%3Aplanet_osm_roads%2C%20mymap%3Aplanet_osm_point&style=default&tilematrixset=EPSG%3A3857&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=9&TileCol=286&TileRow=196 404 (Not Found)


Am I using the wrong settings or Geoserver does not support WMTS for PostGIS-based layers?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...