Generated with the help of an LLM.
Problem/Motivation
The map picker widgets and the split viewer formatter (mapillary_leaflet_split_viewer) take their base layer from the same Leaflet map definition, mapillary_picker, which copies the layers of Leaflet's openstreetmap definition. The widgets render the map with leaflet.service's leafletRenderMap(), so every layer type of the Leaflet module works there. The formatter builds its own L.map: MapillaryLeafletSplitViewerFormatter::tileLayer() passes only urlTemplate and options of the first layer to drupalSettings.mapillary.tileLayer, and mapillary-leaflet-formatter.js always adds it with L.tileLayer().
A site whose base layer is a vector layer ('type' => 'vector', a MapLibre style URL in urlTemplate, as in the example in leaflet.api.php) gets a working map in the widgets and an empty one in the formatter: the style URL is used as a raster tile template, and every tile request fails. A WMS layer ('type' => 'wms') breaks the same way. The formatter library does not depend on leaflet/maplibre-gl-leaflet either, so L.maplibreGL is not loaded.
Steps to reproduce
- In a custom module, implement
hook_leaflet_map_info_alter()and replace the layers of theopenstreetmapandmapillary_pickerdefinitions with a vector layer, for example the "Stadia Alidade Smooth Dark Vector" layer fromleaflet.api.php. Both, because the order of the two alter implementations depends on the module names. - Rebuild caches and open a content edit form with a Mapillary map picker widget: the vector base map is shown.
- Show the same image reference field with the "Mapillary Leaflet Split Viewer" formatter: the map has no base layer, and the browser requests the style JSON as tile images.
Proposed resolution
tileLayer()also returns the layer'stype(basewhen it is not set, as in the Leaflet module).mapillary-leaflet-formatter.jscreates the layer the wayDrupal.Leaflet.prototype.create_layer()does:L.maplibreGL({style, attribution, pitch, bearing})forvector,L.tileLayer.wms()forwms,L.tileLayer()otherwise.- The formatter attaches
leaflet/maplibre-gl-leafletonly when the layer is a vector layer, asleafletRenderMap()does, so pages with a raster base map do not load MapLibre. - Upgrade path: no schema or configuration change, no update hook. Sites with a raster base layer see no difference.
- Tests: the kernel test of the formatter checks
typeindrupalSettings.mapillary.tileLayerand the conditional library for a vector and a raster layer. A FunctionalJavascript test replacesleaflet/maplibre-gl-leafletwith a fakeL.maplibreGL(the pattern ofmapillary_viewer_test), so no WebGL is needed, and checks that the formatter creates it with the style URL. - A "Fixed" entry under
[Unreleased]inCHANGELOG.md.
Remaining tasks
- Merge request.
- Review.
User interface changes
None. The split viewer shows the base map the site has configured.
API changes
drupalSettings.mapillary.tileLayergets atypekey (base,wmsorvector).
Data model changes
None.
Issue fork mapillary-3633821
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #7
orkutmuratyilmaz