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

  1. In a custom module, implement hook_leaflet_map_info_alter() and replace the layers of the openstreetmap and mapillary_picker definitions with a vector layer, for example the "Stadia Alidade Smooth Dark Vector" layer from leaflet.api.php. Both, because the order of the two alter implementations depends on the module names.
  2. Rebuild caches and open a content edit form with a Mapillary map picker widget: the vector base map is shown.
  3. 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's type (base when it is not set, as in the Leaflet module).
  • mapillary-leaflet-formatter.js creates the layer the way Drupal.Leaflet.prototype.create_layer() does: L.maplibreGL({style, attribution, pitch, bearing}) for vector, L.tileLayer.wms() for wms, L.tileLayer() otherwise.
  • The formatter attaches leaflet/maplibre-gl-leaflet only when the layer is a vector layer, as leafletRenderMap() 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 type in drupalSettings.mapillary.tileLayer and the conditional library for a vector and a raster layer. A FunctionalJavascript test replaces leaflet/maplibre-gl-leaflet with a fake L.maplibreGL (the pattern of mapillary_viewer_test), so no WebGL is needed, and checks that the formatter creates it with the style URL.
  • A "Fixed" entry under [Unreleased] in CHANGELOG.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.tileLayer gets a type key (base, wms or vector).

Data model changes

None.

Issue fork mapillary-3633821

Command icon 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

orkutmuratyilmaz created an issue. See original summary.

  • orkutmuratyilmaz committed 0873df8f on 1.0.x
    docs: #3633821: Record the base layer types of the split viewer in the...

  • orkutmuratyilmaz committed 8223bc89 on 1.0.x
    fix: #3633821: Pass the type of the base layer to the split viewer and...
orkutmuratyilmaz’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.