Generated with the help of an LLM.
Problem/Motivation
Every MapillaryJS viewer holds a WebGL context, and browsers keep only about 16 of them per page; when the limit is reached, the oldest context is lost and that viewer goes blank. The two viewer formatters (mapillary_street_level_viewer and mapillary_leaflet_split_viewer) create their viewers as soon as the page loads, so a multi-value field or a Views listing with many images runs out of contexts. A split viewer with a vector base layer uses a second context for the map.
Without a browser token, both formatters show only the text "Mapillary viewer is not configured.", although the image entity stores thumbnail URLs and the image could be linked on mapillary.com.
The module ships MapillaryJS 4.1.0. 4.1.1 fixes how the owner (organization) and 4.1.2 how the creator (user) of an image are requested from the Graph API.
Steps to reproduce
- Add an unlimited
mapillary_image_referencefield to a content type and show it with the "Mapillary Street-Level Viewer" formatter. - Reference 20 images in one node and view it: the first viewers go blank, and the browser console warns about too many active WebGL contexts.
- Empty the browser token on the Mapillary settings form and view the node again: the whole field is replaced by "Mapillary viewer is not configured."
Proposed resolution
- A new formatter setting on both formatters, "Open the viewer": "When the page loads" (
immediate, the default and today's behavior) or "On click" (on_click). With "On click", the image's thumbnail is shown with an "Open image" button, and the viewer is created when the button is pressed. In the split viewer only the viewer waits; the map loads with the page, and a click on the map before the viewer is open opens it at the nearest image. - A fixed limit of 8 viewers per page in
Drupal.mapillary.createViewer(), which every viewer of the module goes through. A viewer over the limit stays as thumbnail and button; pressing the button while the limit is reached shows a message instead of opening it. Viewers removed withDrupal.mapillary.removeViewer()free their place. 8 leaves room for a second WebGL context per split viewer. The limit can become a setting later if sites need it. - Without a browser token, the formatters show the thumbnail and a "View on Mapillary" link (
https://www.mapillary.com/app/?pKey=<id>) instead of the text, and attach no viewer library. The same markup is the fallback when MapillaryJS is not loaded. - Thumbnail:
thumb_1024_url, thenthumb_256_url; a URL that has already expired (MapillaryThumbnailUrl::expiresAt()) is skipped, and without a thumbnail only the button or link is shown. The render array keeps the image as a cacheable dependency, so a thumbnail refresh updates the page. - MapillaryJS 4.1.2: version in
mapillary.libraries.yml, the Composer package in the README's requirements. The module's JavaScript does not change for it; a site that keeps 4.1.0 keeps working. - README: the new setting, the limit, and why (WebGL contexts per page).
- Upgrade path: post update functions in
mapillary_fieldandmapillary_leafletwriteviewer_load: immediateto every entity view display component that uses one of the two formatters, so existing displays behave as before and their exported configuration matches the schema. - Tests: kernel tests for the setting, the markup with and without a browser token, and the expired thumbnail; kernel update tests for the post updates; FunctionalJavascript tests with the fake MapillaryJS of
mapillary_viewer_testfor "On click" in both formatters and for the ninth viewer on a page staying closed. - An "Added" and a "Changed" entry under
[Unreleased]inCHANGELOG.md.
Remaining tasks
- Implementation and tests.
- Merge request.
- Review.
User interface changes
- Formatter settings: an "Open the viewer" select on both formatters, also shown in the settings summary.
- Pages: with "On click", or over the limit, a thumbnail and an "Open image" button in place of the viewer. Without a browser token, a thumbnail and a "View on Mapillary" link in place of "Mapillary viewer is not configured."
API changes
Drupal.mapillary.createViewer()also returnsnullwhen 8 viewers are open on the page.- The
mapillary/mapillary_jslibrary declares version 4.1.2.
Data model changes
- A
viewer_loadkey in the formatter settings schema ofmapillary_street_level_viewerandmapillary_leaflet_split_viewer, written to existing displays by the post updates.
Issue fork mapillary-3633914
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