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
155 stars 76 forks source link

Esri Vector Tile Printing? #130

Open dcisson opened 11 months ago

dcisson commented 11 months ago

This is an excellent Leaflet extension that I've used for a number of projects, and now I'm working with a hosted vector tile layer on AGOL and I'm curious if it's possible to use such a service as the printLayer, and if not, would it even be possible, and how heavy a lift would it be?

As a ham-fisted attempt I simply tried slipping the vectorTileLayer in as the printLayer:

  L.control.browserPrint({
    position : "topleft",
    printLayer: L.esri.Vector.vectorTileLayer('https://tiles.arcgis.com/tiles/OSbOBWdLkmvu5I9F/arcgis/rest/services/VTP27/VectorTileServer/tiles/{z}/{x}/{y}.pbf')...

Unsurprisingly this returns "Unknown layer, cannot clone this layer. Leaflet version: 1.9.4", and to be honest I'm not even certain if the vector tile service even supports the "/tiles/{z}/{x}/{y}" operations.

It would be great if this were possible or could be added, but I can also see where this may not be possible given the format of data being returned from such a service

Igor-Vladyka commented 10 months ago

Hey there.

This has nothing to do with a data or it's format, but pure JS, basicslly plugin has no idea what is ESRI Vector. It sends you an error stating that it does not know what to do with it. You need to register it properly for a plugin, something like

L.BrowserPrint.Utils.registerLayer(
    // Actual typeof object to compare with
    L.esri.Vector.VectorTileLayer,
    // Any string you would like for current function for print events
    'L.esri.Vector.VectorTileLayer',
    function (layer, utils) {
        return L.esri.Vector.vectorTileLayer('https://tiles.arcgis.com/tiles/OSbOBWdLkmvu5I9F/arcgis/rest/services/VTP27/VectorTileServer/tiles/{z}/{x}/{y}.pbf');
    });

Please read more here: new-print-layers/renderers-registration