webtrees icon indicating copy to clipboard operation
webtrees copied to clipboard

Add support for WMS maps

Open ekdahl opened this issue 9 months ago • 2 comments
trafficstars

Will detect that it is an WMS map by looking for layers in options.

I decided to put all tile layer options in a separate variable because of this:

If any custom options not documented here are used, they will be sent to the WMS server as extra parameters in each request URL.

This means that for example url will be appended as parameter in the request if they are mixed with the tile layer options.

Here are samples of WMTS and WMS maps:

    public function leafletJsTileLayers(): array
    {
        return [
            (object) [
                'default'     => true,
                'label'       => 'WMTS map',
                'url'         => 'https://minkarta.lantmateriet.se/map/topowebbcache?layer=topowebb&tilematrixset=3857&Service=WMTS&Request=GetTile&TileMatrix={z}&TileCol={x}&TileRow={y}',
                'options'  => 
                    (object) [
                        'attribution' => '<a href="https://www.lantmateriet.se">Lantmäteriet</a>',
                        'maxZoom'     => 17,
                        'minZoom'     => 2,
                    ],
            ],
            (object) [
                'label'       => 'WMS map',
                'url'         => 'https://minkarta.lantmateriet.se/map/ortofoto',
                'options'  => 
                    (object) [
                        'attribution' => '<a href="https://www.lantmateriet.se">Lantmäteriet</a>',
                        'layers'      => 'Ortofoto_0.5,Ortofoto_0.4,Ortofoto_0.25,Ortofoto_0.16',
                        'maxZoom'     => 19,
                        'minZoom'     => 2,
                        'service'     => 'WMS',
                    ],
            ],
        ];
    }

ekdahl avatar Jan 31 '25 18:01 ekdahl

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 34.99%. Comparing base (80e1855) to head (f02d955).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5110   +/-   ##
=========================================
  Coverage     34.99%   34.99%           
  Complexity    11520    11520           
=========================================
  Files          1189     1189           
  Lines         48502    48502           
=========================================
  Hits          16974    16974           
  Misses        31528    31528           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 31 '25 18:01 codecov[bot]

Any opinion on this? I guess an even cleaner approach is to explicitly set the service type, but that would require changes to existing modules if not providing backwards compatibility.

Would love to see WMS support in an upcoming release, so I can release a module with Swedish map services.

ekdahl avatar May 27 '25 12:05 ekdahl

This PR should be non-intrusive for current modules... Any hope of adding official WMS support (so I don't have to manually edit after each release)?

ekdahl avatar Aug 14 '25 08:08 ekdahl

Can you explain what WMS is?

Google tells me there are lots of things called "Wxxxx Mapping Service".

Is this a different mapping provider? Is this a different layer on an existing mapping provider?

fisharebest avatar Nov 02 '25 23:11 fisharebest

WMS is Web Map Service, as in the protocol used for delivering maps by many map servers. See https://en.wikipedia.org/wiki/Web_Map_Service The server generates the image file requested on demand (for the viewport size requested), unlike WMTS, XYZ or TMS services which delivers pre-rendered tiles. For WMS, the layer(s) you want can to be supplied in the GetMap request, therefore 'layers' is added to the configuration. See e.g. https://docs.qgis.org/3.40/en/docs/server_manual/services/wms.html#wms-getmap And as you can see here, Leaflet already supports WMS: https://leafletjs.com/reference.html#tilelayer-wms

ekdahl avatar Nov 07 '25 15:11 ekdahl