Igor-Vladyka / leaflet.browser.print

A leaflet plugin which allows users to print the map directly from the browser
https://igor-vladyka.github.io/leaflet.browser.print/
MIT License
154 stars 76 forks source link

Problems with register L.nonTiledLayer.wms #132

Closed Lauranna closed 3 months ago

Lauranna commented 3 months ago

Hello, on my map you can display overlays such as hiking trails or municipal boundaries. I have combined the layers in an overlay group. I would like to have these included in the print as well if a overlay layer is displayed. Unfortunately I always get the error: "Unknown layer, cannot clone this layer. Leaflet version: 1.9.4". I tried registering the layers but to no avail.

Here is my Layerdefintion:

// Layerdefintion (example)
var groupedOverlayLayers = {
            "Orientierungshilfen": {
                "Wanderwege": L.nonTiledLayer.wms(intern, {
                    layers: 'fw_wanderweg',
                    format: 'image/png',
                    srs: 'EPSG:3857',
                    exceptions: 'application/vnd.ogc.se_inimage',
                    transparent: true
                }),
                "Radwege": L.nonTiledLayer.wms(intern, {
                    layers: 'fw_radweg',
                    format: 'image/png',
                    srs: 'EPSG:3857',
                    exceptions: 'application/vnd.ogc.se_inimage',
                    transparent: true
                })
}

Here is my non-working layer registration:

L.BrowserPrint.Utils.registerLayer(L.nonTiledLayer.wms, 'L.nonTiledLayer.wms', function (layer, utils) {
    return new L.nonTiledLayer.wms(layer._url, utils.cloneOptions(layer.options));
});

I also tried cloning the layers individually with "cloneLayer();" , but the same error occurs.

Could the nonTiledLayer be causing problems here? I need a nudge in the right direction please -.-

Many thanks in advance for your help. Regards, Anna

Igor-Vladyka commented 3 months ago

Hey Anna. new-print-layersrenderers-registration => here is all you need to register layer. Please note where uppercase and lover case is used. Uppercase means object and lovercase means function. You need to register an Object constructor for Object type, in your example above it most likelly you are mixing function with object. You need to find out what is the actual object created under L.nonTiledLayer.wms function and try something like:

L.BrowserPrint.Utils.registerLayer(L.nonTiledLayer.WMS, 'L.nonTiledLayer.WMS', function (layer, utils) {
    return L.nonTiledLayer.wms(layer._url, utils.cloneOptions(layer.options));
});
Lauranna commented 3 months ago

Hi Igor, thanks for your quick response. The Uppercase parts were part of the solution. But the featurenames in this function are also different. Here is my solution:

L.BrowserPrint.Utils.registerLayer(L.NonTiledLayer.WMS, 'L.NonTiledLayer.WMS', function (layer, utils) {
    return new L.nonTiledLayer.wms(layer._wmsUrl, utils.cloneOptions(layer.wmsParams));
});

Now it works pretty fine.

Thanks a lot. Regards, Anna