{
  "version": 3,
  "sources": ["trip_map.js"],
  "sourcesContent": ["/*\n * static/js/trip_map.js \u2014 the trip page's map and elevation profile\n * (SNOW-820).\n *\n * One MapLibre canvas: the trip's route drawn as the map draws it (its legs\n * below z14, slope classes from z14 \u2014 `route_drawing_core.js`, SNOW-1212), a\n * marker where the group meets, and the viewport fitted to the snapshot's\n * own bbox, with +/\u2212 and cooperative gestures so the page still scrolls\n * past it. Beneath it, in the same card, the map's own route profile\n * (route_profile.js, drawn by trip_route_profile.js \u2014 SNOW-1216); a press\n * or a drag on the profile places a point there, and this module draws\n * the same point on the line.\n *\n * ## What this module owns, and what it deliberately does not\n *\n * It owns ONE camera and the route's and meeting point's sources, built\n * from a payload the page already holds (`#trip-map-payload`, written by `apps.trips.views._trip_map_payload`).\n * It does not fetch anything, it registers no overlay with\n * `window.pwaMapOverlays`, and it never touches `window.snowdeskMapState` \u2014\n * the map page's shared state belongs to the map page, and a trip page is a\n * document with a picture in it rather than a second map application.\n *\n * The meeting marker is `self.pwaRouteMarkersCore`, reused UNCHANGED.\n *\n * ## The profile's point, on the map (SNOW-1216)\n *\n * The profile owns no map and this module owns no profile. The profile\n * announces the sample index a press placed as a `trip:route-cursor`\n * event on the document (`{index}`, null to clear), and this module turns\n * the index into a place with route_cursor_map_core.js \u2014 the map page's\n * own conversion, from the slope record's boundary points on a sampled\n * route, by equal shares of the line on one never sampled \u2014 and draws a\n * dot there, panning only when the dot would land off the canvas. The\n * index, never a distance, crosses the boundary, for the reason that\n * module's header gives: the profile's distances and the sampler's do not\n * agree.\n *\n * ## The rule a trip's figures inherit from Route\n *\n * `bounds` is stored FLAT (`[w, s, e, n]`, a GeoJSON bbox) and `fitBounds`\n * wants it nested (`[[w, s], [e, n]]`). The reshape happens once, here.\n *\n * ## Colours\n *\n * The route's are the shared drawing's, which names the tokens they mirror.\n * The meeting dot is the route line's fuchsia, passed to the markers core\n * as channels.\n *\n * ## The reader's own basemap (SNOW-829)\n *\n * This canvas renders on whatever the reader picked on the map page, not\n * on the site default. `localStorage` is scoped per ORIGIN, so the key the\n * map's picker writes (`snowdesk.map.basemap`) is readable here; the\n * catalogue to resolve it against is emitted by the page\n * (`trips/partials/_trip_basemaps.html`). Read ONCE at boot \u2014 there is no\n * picker on this page, so no `snowdesk:basemap-changed` will ever fire.\n *\n * The national basemaps cover one country each and render BLANK outside\n * it, and unlike the map page this one has no picker in front of the\n * reader to fix that with. So after the map goes idle it asks the canvas\n * what it actually painted (`pwaBasemapStyleCore.drewNothing`) and, if\n * only this page's own two sources drew, reveals a notice offering the\n * standard map. Coverage is detected and never declared: the providers'\n * own extents are unusable for it \u2014 swisstopo's declared box CONTAINS\n * Chamonix, and IGN's is the whole world (see that module's header).\n *\n * ## Exports (frozen `self.pwaTripMapCore`)\n *\n *   readPayload(doc)              \u2192 the parsed payload, or null\n *   fitBoundsFor(bounds)          \u2192 [[w, s], [e, n]], or null\n *   routeSourceData(payload)      \u2192 the LineString FeatureCollection\n *   meetingSourceData(payload)    \u2192 the Point FeatureCollection\n *   installLayers(map, payload)   \u2192 adds the sources and layers (its test)\n *   installMeetingMarker(map, sourceId, layerId, data)\n *                                 \u2192 adds the meeting marker; SNOW-1571's\n *                                   review on a trip's page pins it too\n *   cursorFeature(payload, index) \u2192 the profile's point as a Point\n *                                   Feature, or null\n *   readBasemaps(doc)             \u2192 the {key: url} catalogue, or null\n *   resolveBasemapFor(el, doc)    \u2192 {key, url} for this reader, or null\n *\n * SNOW-1019 took the fall-line arrows and no-fall passage split line off\n * this map, as off the map page (where rail two's bank ribbon and passage\n * bars stood in for them until SNOW-1065 retired it). The snapshot still\n * carries both records.\n *\n * Everything above is a pure function of the payload, so it is unit-tested\n * directly (tests/js/test_trip_map.js) with no browser and no WebGL.\n */\n\n(function () {\n  'use strict';\n\n  /**\n   * The prefix the shared route drawing names this page's sources and\n   * layers with (`trip-route`, `trip-route-legs`, \u2026).\n   */\n  var ROUTE_PREFIX = 'trip-route';\n\n  /** Padding, in pixels, around the fitted route. */\n  var FIT_PADDING = 40;\n\n  /** The image ids the meeting marker is registered under. */\n  var MEETING_ICON = 'trip-meeting-point';\n\n  /** The source, and the one layer, the profile's point is drawn from. */\n  var CURSOR_SOURCE = 'trip-route-cursor';\n\n  /** The route line's colour, the dot's fill where no class colours it. */\n  var ROUTE_LINE_COLOUR = (self.pwaRouteDrawingCore && self.pwaRouteDrawingCore.ROUTE_LINE_COLOUR) || '#c026d3';\n\n  /** The ring round the dot, so it reads over the line it sits on. */\n  var CURSOR_HALO = '#ffffff';\n\n  /**\n   * The profile's last index, kept so a style swapped in later reinstalls\n   * the dot where it was.\n   *\n   * @type {?number}\n   */\n  var cursorIndex = null;\n\n  // The English fallbacks are the only copy of these strings a reader of\n  // this file can see, so they double as documentation of what each key\n  // means. `i18n_strings.js` is loaded first by `_trip_map.html`, in\n  // document order, so `self.pwaStrings` is here.\n  var STRINGS = self.pwaStrings.read('trip-strings-template', {\n    'meeting-point': 'Meeting point',\n    'map-failed':\n      \"The map couldn't be loaded. The route details above are unaffected.\",\n  });\n\n  /**\n   * Read and parse the inline payload.\n   *\n   * Defensive about what it finds: the element is written by\n   * `json_script`, so a parse failure means the page is not the page this\n   * module was written for, and drawing nothing is the right answer.\n   *\n   * @param {Document} [doc] Injectable for tests.\n   * @returns {?Object} The payload, or null.\n   */\n  function readPayload(doc) {\n    var d = doc || (typeof document !== 'undefined' ? document : null);\n    if (!d) return null;\n    var el = d.getElementById('trip-map-payload');\n    if (!el) return null;\n    try {\n      var parsed = JSON.parse(el.textContent || 'null');\n      return parsed && typeof parsed === 'object' ? parsed : null;\n    } catch (err) {\n      return null;\n    }\n  }\n\n  /**\n   * Reshape a stored flat bbox into the nested pair `fitBounds` takes.\n   *\n   * `[w, s, e, n]` is what `Route.bounds` and therefore `Trip.bounds`\n   * store (a GeoJSON bbox, RFC 7946 \u00A75); MapLibre's `fitBounds` wants\n   * `[[w, s], [e, n]]`. Returns null for anything that is not four\n   * finite numbers, so a malformed snapshot leaves the map at its\n   * default frame rather than throwing inside the constructor.\n   *\n   * @param {*} bounds\n   * @returns {?Array<Array<number>>}\n   */\n  function fitBoundsFor(bounds) {\n    if (!Array.isArray(bounds) || bounds.length !== 4) return null;\n    for (var i = 0; i < 4; i += 1) {\n      if (typeof bounds[i] !== 'number' || !isFinite(bounds[i])) return null;\n    }\n    return [\n      [bounds[0], bounds[1]],\n      [bounds[2], bounds[3]],\n    ];\n  }\n\n  /**\n   * Wrap the payload's route Feature in the FeatureCollection a GeoJSON\n   * source takes.\n   *\n   * A collection rather than the bare Feature so the source's shape\n   * matches every other GeoJSON source in this project, and so an empty\n   * one is expressible (a payload with no geometry draws no line rather\n   * than a source MapLibre rejects).\n   *\n   * @param {?Object} payload\n   * @returns {Object} A FeatureCollection, possibly empty.\n   */\n  function routeSourceData(payload) {\n    var feature = payload && payload.route;\n    var coordinates =\n      feature && feature.geometry && feature.geometry.coordinates;\n    var usable = Array.isArray(coordinates) && coordinates.length > 1;\n    return { type: 'FeatureCollection', features: usable ? [feature] : [] };\n  }\n\n  /**\n   * Wrap the payload's meeting-point Feature the same way.\n   *\n   * @param {?Object} payload\n   * @returns {Object} A FeatureCollection, possibly empty.\n   */\n  function meetingSourceData(payload) {\n    var feature = payload && payload.meeting;\n    var coordinates =\n      feature && feature.geometry && feature.geometry.coordinates;\n    var usable =\n      Array.isArray(coordinates) &&\n      coordinates.length >= 2 &&\n      typeof coordinates[0] === 'number' &&\n      typeof coordinates[1] === 'number';\n    return { type: 'FeatureCollection', features: usable ? [feature] : [] };\n  }\n\n  /** An unsampled route's share midpoints, worked out once per feature. */\n  var MIDPOINTS = new WeakMap();\n\n  /**\n   * The profile's point as a place on the route, or null.\n   *\n   * The sample index is converted as the map page converts it\n   * (route_cursor_map_core.js): on a sampled route, the middle of the\n   * index's segment of the slope record, carrying the segment's class\n   * colour; on a route never sampled, the middle of the index's equal\n   * share of the line, out of the count the profile used \u2014 the last leg's\n   * `to` plus one (route_profile.js `sampleCountOf`).\n   *\n   * @param {?Object} payload\n   * @param {?number} index The profile's sample index; null for none.\n   * @returns {?Object} A Point Feature, or null.\n   */\n  function cursorFeature(payload, index) {\n    var core = self.pwaRouteCursorMapCore;\n    var feature = payload && payload.route;\n    if (!core || !feature || index === null || index === undefined) return null;\n    var props = feature.properties || {};\n    var coordinates = (feature.geometry && feature.geometry.coordinates) || [];\n    if (core.sampleCount(props.slope)) {\n      return core.cursorPoint(props.slope, index, coordinates);\n    }\n    var legs = Array.isArray(props.legs) ? props.legs : [];\n    var last = legs.length ? legs[legs.length - 1] : null;\n    if (!last || !Number.isInteger(last.to)) return null;\n    var midpoints = MIDPOINTS.get(feature);\n    if (!midpoints) {\n      // Every share's midpoint at once, as map.js's bindRouteCursor does:\n      // shareMidpoints walks the whole line, and a drag asks per move.\n      midpoints = core.shareMidpoints(coordinates, last.to + 1);\n      MIDPOINTS.set(feature, midpoints);\n    }\n    var middle = midpoints[index];\n    if (!middle) return null;\n    return {\n      type: 'Feature',\n      geometry: { type: 'Point', coordinates: middle },\n      properties: { index: index },\n    };\n  }\n\n  /**\n   * The cursor source's data for a feature, or the empty collection.\n   *\n   * @param {?Object} point\n   * @returns {Object}\n   */\n  function cursorSourceData(point) {\n    return { type: 'FeatureCollection', features: point ? [point] : [] };\n  }\n\n  /**\n   * Register the meeting-point icon, reusing the map page's start dot.\n   *\n   * The start dot rather than a bespoke glyph: a filled disc is already\n   * this project's \"a point on a route\" symbol, and inventing a second one\n   * for a point that IS on the route would say the two are different kinds\n   * of thing. The casing colour paints it, so it reads against both a pale\n   * basemap and the line it sits on.\n   *\n   * @param {Object} map A MapLibre map.\n   * @returns {void}\n   */\n  function ensureMeetingIcon(map) {\n    if (!self.pwaRouteMarkersCore || map.hasImage(MEETING_ICON)) return;\n    var core = self.pwaRouteMarkersCore;\n    // 0xc0, 0x26, 0xd3 \u2014 the route line's channels. The core owns the\n    // pixels and takes the colour in, which is the split it documents.\n    //\n    // The core's return value is passed STRAIGHT to addImage, exactly as\n    // map.js's ensureRouteMarkerImages does. `startDotPixels` already\n    // returns `{width, height, data}`; re-wrapping it in a second object\n    // put the whole image where MapLibre expects the raw pixel buffer and\n    // threw \"mismatched image size\", which killed the meeting marker (and\n    // everything after it in installLayers) on every trip page.\n    map.addImage(MEETING_ICON, core.startDotPixels(0xc0, 0x26, 0xd3), {\n      pixelRatio: core.PIXEL_RATIO,\n    });\n  }\n\n  /**\n   * Install the route and the meeting marker.\n   *\n   * SNOW-1212: the route is the map page's own drawing\n   * (`route_drawing_core.js`): its legs below z14, slope classes from z14,\n   * the numbered transitions, the start dot and the finish flag. One track\n   * reads the same on the trip page as on the map. This page has nothing\n   * to put between the route's layers, so it hands the drawing the whole\n   * install.\n   *\n   * Idempotent, guarded on the route source, so a style reload cannot\n   * duplicate layers. The meeting marker goes on last, over the route it\n   * usually sits on.\n   *\n   * @param {Object} map A MapLibre map.\n   * @param {?Object} payload\n   * @returns {void}\n   */\n  function installLayers(map, payload) {\n    if (map.getSource(ROUTE_PREFIX)) return;\n    var drawing = self.pwaRouteDrawingCore;\n    if (drawing) {\n      drawing.install(map, routeSourceData(payload), { prefix: ROUTE_PREFIX });\n    }\n\n    // SNOW-1216: the profile's point. Under the meeting marker, which is\n    // the plan and must never be hidden by a reader scrubbing past it.\n    // Filled in the colour of the ground under it (the segment's class,\n    // as on the map page) inside a white ring, at every zoom: this map\n    // draws no cursor segment, so the dot never gives way to one.\n    map.addSource(CURSOR_SOURCE, {\n      type: 'geojson',\n      data: cursorSourceData(cursorFeature(payload, cursorIndex)),\n    });\n    map.addLayer({\n      id: CURSOR_SOURCE,\n      type: 'circle',\n      source: CURSOR_SOURCE,\n      paint: {\n        'circle-color': ['coalesce', ['get', 'colour'], ROUTE_LINE_COLOUR],\n        'circle-radius': 6,\n        'circle-stroke-color': CURSOR_HALO,\n        'circle-stroke-width': 2,\n      },\n    });\n    installMeetingMarker(map, 'trip-meeting', 'trip-meeting-point', meetingSourceData(payload));\n  }\n\n  /**\n   * Add the meeting marker: its icon, its source and its symbol layer.\n   *\n   * SNOW-1571: shared with the GPX Explorer's review on a trip's page\n   * (static/js/explorer.js), which pins the same point with the same\n   * marker over its own drawing of the line. Guarded on the source, so a\n   * second style load cannot add it twice.\n   *\n   * @param {Object} map A MapLibre map.\n   * @param {string} sourceId The marker's source id.\n   * @param {string} layerId The marker's layer id.\n   * @param {Object} data A Point FeatureCollection (`meetingSourceData`).\n   * @returns {void}\n   */\n  function installMeetingMarker(map, sourceId, layerId, data) {\n    if (map.getSource(sourceId)) return;\n    ensureMeetingIcon(map);\n    map.addSource(sourceId, { type: 'geojson', data: data });\n    map.addLayer({\n      id: layerId,\n      type: 'symbol',\n      source: sourceId,\n      layout: {\n        'icon-image': MEETING_ICON,\n        // The whole point of this marker is that it is visible; MapLibre's\n        // default collision would drop it where it sits on the line's own\n        // start.\n        'icon-allow-overlap': true,\n        'icon-ignore-placement': true,\n        'icon-anchor': 'center',\n      },\n    });\n  }\n\n  /**\n   * The source ids this page adds itself.\n   *\n   * Subtracted from `queryRenderedFeatures()` so what remains is the\n   * basemap's own drawing \u2014 see `basemapDrewNothing` below.\n   *\n   * EVERY SOURCE THIS MODULE INSTALLS HAS TO BE LISTED. `drewNothing`\n   * answers false the moment it sees a source that is not here, so an\n   * omission does not degrade the check \u2014 it disables it, and silently:\n   * the blank-basemap notice and its switch-to-the-standard-map escape\n   * hatch would simply stop appearing, on exactly the trips that have the\n   * omitted source. Since SNOW-1212 the route's five sources are the\n   * shared drawing's, so they are read off it rather than listed here.\n   */\n  var OUR_SOURCE_IDS = (function () {\n    var drawing = self.pwaRouteDrawingCore;\n    var ids = drawing ? drawing.sourceIds(ROUTE_PREFIX) : { route: ROUTE_PREFIX };\n    return Object.keys(ids)\n      .map(function (key) { return ids[key]; })\n      .concat(['trip-meeting', CURSOR_SOURCE]);\n  })();\n\n  /**\n   * Read the {key: url} basemap catalogue the page emitted.\n   *\n   * Defensive for the reason `readPayload` is: a missing or unparseable\n   * element means this is not the page this module was written for, and\n   * `resolveBasemap` answers with the site default for a null catalogue,\n   * which is the pre-SNOW-829 behaviour rather than a failure.\n   *\n   * @param {Document} [doc] Injectable for tests.\n   * @returns {?Object} The catalogue, or null.\n   */\n  function readBasemaps(doc) {\n    var d = doc || (typeof document !== 'undefined' ? document : null);\n    if (!d) return null;\n    var el = d.getElementById('trip-basemaps');\n    if (!el) return null;\n    try {\n      var parsed = JSON.parse(el.textContent || 'null');\n      return parsed && typeof parsed === 'object' ? parsed : null;\n    } catch (err) {\n      return null;\n    }\n  }\n\n  /**\n   * Resolve which basemap this reader gets on this page.\n   *\n   * SNOW-829. `localStorage` is scoped per ORIGIN, so the key the map\n   * page's picker writes is readable here \u2014 a reader who chose swisstopo\n   * keeps it on the page where the route is actually being read. Read ONCE\n   * at boot: `snowdesk:basemap-changed` is dispatched by `map.js` after a\n   * swap on the map page, and there is no picker here to fire it.\n   *\n   * The storage read is wrapped because a browser set to block site data\n   * throws on access rather than answering null.\n   *\n   * @param {Element} container The map container, carrying the default key.\n   * @param {Document} [doc] Injectable for tests.\n   * @returns {?Object} `{key, url}`, or null when nothing resolves.\n   */\n  function resolveBasemapFor(container, doc) {\n    var core = self.pwaBasemapStyleCore;\n    if (!core) return null;\n    var stored = null;\n    try {\n      stored = localStorage.getItem(core.STORAGE_KEY);\n    } catch (err) {\n      stored = null;\n    }\n    return core.resolveBasemap(\n      stored,\n      readBasemaps(doc),\n      container.getAttribute('data-default-basemap-key') || '',\n    );\n  }\n\n  /**\n   * Reveal the blank-canvas notice, and wire its one way out.\n   *\n   * The national basemaps cover one country each and render blank outside\n   * it. On the map page a reader can see the picker and fix it; here they\n   * cannot, so the page says what happened and offers the swap. NOT a\n   * picker \u2014 one escape from a broken state, the same family as the\n   * `map-failed` message.\n   *\n   * The notice stays hidden when the page did not render one, so a caller\n   * needs no guard of its own.\n   *\n   * @param {Object} map The MapLibre map.\n   * @param {Element} container The map container, carrying the default key.\n   * @param {Document} doc The document.\n   * @returns {void}\n   */\n  function revealBlankNotice(map, container, doc) {\n    var notice = doc.getElementById('trip-basemap-blank');\n    if (!notice) return;\n    var core = self.pwaBasemapStyleCore;\n    var catalogue = readBasemaps(doc);\n    var defaultKey = container.getAttribute('data-default-basemap-key') || '';\n    var fallback = core && core.resolveBasemap(null, catalogue, defaultKey);\n    var button = notice.querySelector('[data-blank-switch]');\n    if (button && fallback) {\n      button.addEventListener('click', function () {\n        notice.hidden = true;\n        // The layers go with the style; `style.load` reinstalls them, which\n        // is why that handler is idempotent.\n        map.setStyle(fallback.url);\n      });\n    } else if (button) {\n      // Nothing to switch TO. Saying what happened still beats a silent\n      // blank canvas, so the notice is shown without its control.\n      button.hidden = true;\n    }\n    notice.hidden = false;\n  }\n\n  /**\n   * Ask the canvas whether the basemap painted anything, once it is idle.\n   *\n   * `idle` and not `load`: before every tile has rendered, \"nothing drawn\"\n   * is indistinguishable from \"not drawn YET\", which is the one wrong\n   * answer available. It binds once and unbinds on the first firing \u2014\n   * panning to a genuinely empty corner of a basemap that does cover this\n   * area is not the condition this reports.\n   *\n   * Skipped entirely when the reader is on the site default: that style is\n   * global, so a blank canvas under it is a network failure, which\n   * `map-failed` and MapLibre's own error path already speak for.\n   *\n   * @param {Object} map The MapLibre map.\n   * @param {Element} container The map container.\n   * @param {?Object} basemap The resolved `{key, url}`.\n   * @param {Document} doc The document.\n   * @returns {void}\n   */\n  function watchForBlankBasemap(map, container, basemap, doc) {\n    var core = self.pwaBasemapStyleCore;\n    var defaultKey = container.getAttribute('data-default-basemap-key') || '';\n    if (!core || !basemap || basemap.key === defaultKey) return;\n    var onIdle = function () {\n      map.off('idle', onIdle);\n      var drawn;\n      try {\n        drawn = map.queryRenderedFeatures();\n      } catch (err) {\n        return;\n      }\n      if (core.drewNothing(drawn, OUR_SOURCE_IDS)) {\n        revealBlankNotice(map, container, doc);\n      }\n    };\n    map.on('idle', onIdle);\n  }\n\n  /**\n   * Boot the trip map, once, if this page has one.\n   *\n   * @returns {void}\n   */\n  async function init() {\n    var doc = document;\n    var container = doc.querySelector('[data-trip-map]');\n    if (!container) return;\n\n    var payload = readPayload(doc);\n\n    if (typeof maplibregl === 'undefined') {\n      container.textContent = STRINGS['map-failed'];\n      return;\n    }\n\n    // SNOW-829: the READER's basemap, not the site default. `resolveStyle`\n    // answers with the URL for a native style and a Promise of a rewritten\n    // style object for an ESRI one (basemap.at), so it is awaited before\n    // the constructor rather than swapped in afterwards \u2014 a style set after\n    // construction paints the default first and then flashes.\n    var basemap = resolveBasemapFor(container, doc);\n    var style = basemap ? basemap.url : '';\n    if (basemap && self.pwaBasemapStyleCore) {\n      try {\n        style = await self.pwaBasemapStyleCore.resolveStyle(\n          basemap.key,\n          basemap.url,\n        );\n      } catch (err) {\n        style = basemap.url;\n      }\n    }\n\n    var camera = fitBoundsFor(payload && payload.bounds);\n    var map = new maplibregl.Map({\n      container: container,\n      style: style,\n      // `bounds` + `fitBoundsOptions` rather than center/zoom: the\n      // snapshot knows exactly what has to be on screen, and a centre plus\n      // a guessed zoom would frame a 2 km valley tour and a 40 km traverse\n      // identically. map.js's constructor makes the same choice.\n      bounds: camera || undefined,\n      fitBoundsOptions: { padding: FIT_PADDING },\n      attributionControl: { compact: true },\n      // SNOW-1212: a READING surface in a scrolling page. A one-finger\n      // drag (or a plain wheel) scrolls the page past the map, and two\n      // fingers (or ctrl + wheel) move it \u2014 MapLibre's cooperative\n      // gestures, which show the reader how. The meeting picker is the\n      // opposite case, a control, and stays fully interactive.\n      cooperativeGestures: true,\n    });\n    // SNOW-1212: +/\u2212 for a reader who cannot pinch, or who would rather\n    // not learn the two-finger rule to zoom in on one stretch. No compass:\n    // the map never rotates, so there is nothing for it to reset.\n    map.addControl(new maplibregl.NavigationControl({ showCompass: false }), 'top-right');\n\n    // Bound to the constructor's return rather than to a `load` handler:\n    // `load` never fires when the basemap style fails to fetch, and a trip\n    // page that showed no route because a third-party CDN was slow would\n    // be a page about nothing. `style.load` fires for the real style AND\n    // for a style swapped in later, so the idempotent install is what\n    // makes a second firing harmless.\n    map.on('style.load', function () {\n      installLayers(map, payload);\n    });\n\n    // SNOW-1216: the profile's point, drawn on the line, and brought into\n    // view when it would land off the canvas.\n    doc.addEventListener('trip:route-cursor', function (event) {\n      var detail = /** @type {CustomEvent} */ (event).detail || {};\n      cursorIndex = typeof detail.index === 'number' ? detail.index : null;\n      var point = cursorFeature(payload, cursorIndex);\n      var source = map.getSource(CURSOR_SOURCE);\n      if (source) source.setData(cursorSourceData(point));\n      if (point && !map.getBounds().contains(point.geometry.coordinates)) {\n        map.panTo(point.geometry.coordinates);\n      }\n    });\n\n    // SNOW-829: and notice if that basemap drew nothing here.\n    watchForBlankBasemap(map, container, basemap, doc);\n  }\n\n  self.pwaTripMapCore = Object.freeze({\n    readPayload: readPayload,\n    fitBoundsFor: fitBoundsFor,\n    routeSourceData: routeSourceData,\n    meetingSourceData: meetingSourceData,\n    // SNOW-1216. The index-to-place conversion, exported for its test:\n    // a wrong answer is a dot on the wrong bit of the line, which nothing\n    // else would notice.\n    cursorFeature: cursorFeature,\n    // Exported for its test rather than for a second caller. It is the one\n    // function here that hands MapLibre a structure MapLibre validates at\n    // runtime, and getting that structure wrong threw inside installLayers\n    // and took the meeting marker out with it \u2014 a failure no assertion\n    // about the payload arithmetic could ever have seen.\n    ensureMeetingIcon: ensureMeetingIcon,\n    // SNOW-1571. The meeting marker, for the GPX Explorer's review on a\n    // trip's page, which draws its own map of the same line.\n    installMeetingMarker: installMeetingMarker,\n    // SNOW-1019 / SNOW-1212. Exported for its test: the one place that\n    // can show this map draws the route as the map does, and that the\n    // fall-line arrows stay off it.\n    installLayers: installLayers,\n    // SNOW-829. The catalogue read and the resolution built on it. The\n    // arithmetic itself lives in `basemap_style_core.js` and is tested\n    // there; these two are exported because they are what decides which\n    // style the constructor is handed, and getting that wrong is a blank\n    // map rather than a thrown error.\n    readBasemaps: readBasemaps,\n    resolveBasemapFor: resolveBasemapFor,\n  });\n\n  if (typeof document !== 'undefined') {\n    if (document.readyState === 'loading') {\n      document.addEventList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,oBAAqB,SAAUoD,EAAO,CACzD,IAAIC,EAAqCD,EAAO,QAAU,CAAC,EAC3DvD,EAAc,OAAOwD,EAAO,OAAU,SAAWA,EAAO,MAAQ,KAChE,IAAI9B,EAAQT,EAAcN,EAASX,CAAW,EAC1CyD,EAAS7B,EAAI,UAAU/B,CAAa,EACpC4D,GAAQA,EAAO,QAAQhC,EAAiBC,CAAK,CAAC,EAC9CA,GAAS,CAACE,EAAI,UAAU,EAAE,SAASF,EAAM,SAAS,WAAW,GAC/DE,EAAI,MAAMF,EAAM,SAAS,WAAW,CAExC,CAAC,EAGDsB,EAAqBpB,EAAKY,EAAWS,EAAS9C,CAAG,EACnD,CAEA,KAAK,eAAiB,OAAO,OAAO,CAClC,YAAaD,EACb,aAAcK,EACd,gBAAiBG,EACjB,kBAAmBK,EAInB,cAAeE,EAMf,kBAAmBU,EAGnB,qBAAsBI,EAItB,cAAeF,EAMf,aAAcS,EACd,kBAAmBC,CACrB,CAAC,EAEG,OAAO,SAAa,MAClB,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoBa,CAAI,EAElDA,EAAK,EAGX,GAAG",
  "names": ["ROUTE_PREFIX", "FIT_PADDING", "MEETING_ICON", "CURSOR_SOURCE", "ROUTE_LINE_COLOUR", "CURSOR_HALO", "cursorIndex", "STRINGS", "readPayload", "doc", "d", "el", "parsed", "fitBoundsFor", "bounds", "i", "routeSourceData", "payload", "feature", "coordinates", "usable", "meetingSourceData", "MIDPOINTS", "cursorFeature", "index", "core", "props", "legs", "last", "midpoints", "middle", "cursorSourceData", "point", "ensureMeetingIcon", "map", "installLayers", "drawing", "installMeetingMarker", "sourceId", "layerId", "data", "OUR_SOURCE_IDS", "ids", "key", "readBasemaps", "resolveBasemapFor", "container", "stored", "revealBlankNotice", "notice", "catalogue", "defaultKey", "fallback", "button", "watchForBlankBasemap", "basemap", "onIdle", "drawn", "init", "style", "camera", "event", "detail", "source"]
}
