There are two main reasons as to why you would want to proxy the WMTS basemap, these are:
You may have to provide a customer API Key in the URL for each request, as in the case with the OS Maps API. If this were to be used directly in iShare, the key would have to be transferred to the client which could expose it to misuse.
Proxying the basemap through MapProxy allows us to also query it directly with WMS which then means that it should work seamlessly with printing.
Configuration
MapProxy uses a YAML configuration file to define:
Layers: the layers that are available in the service
...
There are four parts to the configuration:
Layers
...
Caches: where the cache is stored
Sources: where the source files are stored
Grid: the Coordinate Reference System used in the layer, and the scales/resolutions available.
The YAML file itself will normally be stored with the MapProxy application, for example at D:/mapproxy/mapproxy.yaml.
Configuration of MapProxy layers in Studio is covered in this section: BaseMaps Details .
Layers
This section defines one or more layers to be served by MapProxy. Each layer should have:
name: used as a reference by Studio in the Details dialog
title: descriptive name for display purposes
sources: a reference to one or more sources defined elsewhere in the YAML file, defining the data to be displayed
See the example below.
Code Block |
---|
layers: - name: aerial2013 title: Aerial 2013 sources: [aerial2013_cache] - name: aerial2018 title: Aerial 2018 sources: [aerial2018_cache] - name: basemap title: os_raster_roadColour sources: [ "chc_os_raster_road" ] |
Caches
Code Block |
---|
chc_os_raster_roadbasemap_cache] |
Caches
This section defines the location of the cached data. The cache reference in the first line is referenced by the layers section, and the cache also identifies the source of the data.
Each cache will have:
grid: a reference to a grid definition elsewhere in the YAML file
sources: a reference to one or more source sections - if this is a MapServer WMS, the source include both the reference to the source name in the YAML file (e.g. aerial_wms_2013) and the name of the layer or group in the map file (e.g. aerial2013)
cache: details of the cache itself, containing
type: the type of cache storage
filename: the location of the cache
Code Block |
---|
caches: aerial2013_cache: grids: [ "grd_os_raster_road" grid_gb] sources: ['aerial_wms_2013:aerial2013'] cache: type: mbtiles filename: E:\Tiles\aerial2013.mbtiles aerial2018_cache: grids: [grid_gb] sources: [ "src_os_raster_road"] meta_buffer: 0'aerial_wms_2018:aerial2018'] cache: type: mbtiles minimize_meta_requests: true |
Sources
Code Block |
---|
src_os_raster_roadfilename: E:\Tiles\aerial2018.mbtiles |
Sources
This section defines the source of the data to be displayed and cached. The type will normally either be:
wms: for example a MapServer layer configured in Studio
tile: for example an existing tilecache on an iShare server
The Sources section will contain one or more sources, of which a single layer can reference one or more. The first line of the source will be used in the sources section of the layer as a reference. Each source will also have:
type: this will usually either be tile, referencing an existing tilecache, or wms, referencing a WMS service, either in iShare or externally
grid: a reference to a grid definition elsewhere in the YAML file
url: the location for the tilecache or WMS
Code Block |
---|
sources: aerial_wms_2013: type: wms req: tile grid: grd_os_raster_roadurl: http://127.0.0.1/Mapserver/ms761?map=E:/iShareData/LIVE/_MapServerConfig/base_raster_aerial_2013.map http: ssl_no_cert_checks: true aerial_wms_2018: type: wms req: url: httpshttp://api127.0.os.uk/maps/raster/v1/wmts?key=this_is_my_os_api_key&height=256&width=256&style=default&layer=Road_27700&version=1.0.0&service=WMTS&Request=GetTile&format=image/png&TileMatrixSet=EPSG:27700&TileMatrix=EPSG:27700:%(z)s&TileRow=%(y)s&TileCol=%(x)s |
Grids
Code Block |
---|
0.1/Mapserver/ms761?map=E:/iShareData/LIVE/_MapServerConfig/base_raster_aerial_2018.map
http:
ssl_no_cert_checks: true |
Grids
This section contains details of the coordinate reference system used by the cache. The first line contains the referenced used by the caches section. Each grid contains:
origin: the origin point of the grid in relation to the grid area - the default is sw
srs: the coordinate reference system/spatial reference system being used by the data, using the EPSG code
bbox: the bounding box of the grid, i.e. the extent of the data, using the units specified in bbox_srs
bbox_srs: the SRS of the units specified in bbox
res: the resolutions that MapProxy will cache - see the section below on Increasing the number of Scales for the Basemap for more detail on this.
Code Block |
---|
grd_os_raster_road: origin: nw srs: 'EPSG:27700' bbox: [-238375.0,0.0,900000.0,1376256.0] bbox_srs: 'EPSG:27700' res: [896.0, 448.0, 224.0, 112.0, 56.0, 28.0, 14.0, 7.0, 3.5, 1.75] |
Testing
Once these are incorporated into the main configuration file, you can then test it using the MapProxy demo site which should list the layer both in the WMS and WMTS sections. Clicking on the WMTS png
link will bring up an OpenLayers map which uses the specified basemap.
...
Configuring your WMTS basemap for use in iShare is done via in iShare Studio, and is covered in the following pages:
...