maplibre-gl-raster 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -114,6 +114,9 @@ The main control class implementing MapLibre's `IControl` interface.
114
114
  | `interleaved` | `boolean` | `true` | Render the deck.gl overlay interleaved with the basemap layers |
115
115
  | `defaultUrl` | `string` | `''` | Prefills the Add data URL input (not loaded until the user clicks Load) |
116
116
  | `autoLoad` | `boolean` | `false` | Load `defaultUrl` automatically when the control is added to the map |
117
+ | `sampleData` | `RasterSampleDataset[]` | - | Sample COGs offered as a "Load sample data" dropdown above the URL input; picking one fills the input (hidden when empty) |
118
+ | `sampleDataLabel` | `string` | `'Load sample data...'` | Placeholder shown in the sample-data dropdown |
119
+ | `closeOnOutsideClick` | `boolean` | `true` | Collapse the panel when clicking outside it; set `false` to close only via the header button |
117
120
  | `engine` | `RenderEngine` | `'maplibre-gl-raster'` | Initial rendering backend; switchable at runtime from the panel |
118
121
 
119
122
  #### Raster Methods
@@ -19091,6 +19091,68 @@ var AddDataSection = class {
19091
19091
  if (e.key === "Enter") submitUrl();
19092
19092
  });
19093
19093
  const urlRow = el("div", { className: "mlr-row" }, input, loadBtn);
19094
+ const samples = options.sampleData ?? [];
19095
+ let sampleRow;
19096
+ if (samples.length > 0) {
19097
+ const placeholder = options.sampleDataLabel ?? "Load sample data...";
19098
+ const triggerLabel = el("span", {
19099
+ className: "mlr-sample-trigger-label",
19100
+ text: placeholder
19101
+ });
19102
+ const trigger = el("button", {
19103
+ className: "mlr-sample-trigger",
19104
+ type: "button",
19105
+ ariaLabel: placeholder,
19106
+ attrs: {
19107
+ "aria-haspopup": "listbox",
19108
+ "aria-expanded": "false"
19109
+ }
19110
+ }, triggerLabel, el("span", {
19111
+ className: "mlr-sample-caret",
19112
+ text: "▾"
19113
+ }));
19114
+ const menu = el("div", {
19115
+ className: "mlr-sample-menu",
19116
+ attrs: { role: "listbox" }
19117
+ });
19118
+ menu.hidden = true;
19119
+ let menuOpen = false;
19120
+ const setMenuOpen = (open) => {
19121
+ menuOpen = open;
19122
+ menu.hidden = !open;
19123
+ trigger.setAttribute("aria-expanded", String(open));
19124
+ trigger.classList.toggle("open", open);
19125
+ if (open) menu.firstElementChild?.focus();
19126
+ };
19127
+ for (const sample of samples) {
19128
+ const option = el("button", {
19129
+ className: "mlr-sample-option",
19130
+ type: "button",
19131
+ text: sample.label,
19132
+ title: sample.url,
19133
+ attrs: { role: "option" }
19134
+ });
19135
+ option.addEventListener("click", () => {
19136
+ setMenuOpen(false);
19137
+ trigger.focus();
19138
+ input.value = sample.url;
19139
+ loadBtn.disabled = input.value.trim().length === 0;
19140
+ });
19141
+ menu.appendChild(option);
19142
+ }
19143
+ trigger.addEventListener("click", () => setMenuOpen(!menuOpen));
19144
+ sampleRow = el("div", { className: "mlr-sample-row" }, trigger, menu);
19145
+ sampleRow.addEventListener("keydown", (e) => {
19146
+ if (e.key === "Escape" && menuOpen) {
19147
+ setMenuOpen(false);
19148
+ trigger.focus();
19149
+ }
19150
+ });
19151
+ sampleRow.addEventListener("focusout", (e) => {
19152
+ const next = e.relatedTarget;
19153
+ if (!next || !sampleRow.contains(next)) setMenuOpen(false);
19154
+ });
19155
+ }
19094
19156
  const fileInput = el("input", {
19095
19157
  type: "file",
19096
19158
  ariaLabel: "raster-file",
@@ -19133,7 +19195,7 @@ var AddDataSection = class {
19133
19195
  this.el = el("div", { className: "mlr-section mlr-add-data" }, el("div", {
19134
19196
  className: "mlr-section-title",
19135
19197
  text: "Add data"
19136
- }), urlRow, dropZone, beforeIdInput);
19198
+ }), ...sampleRow ? [sampleRow] : [], urlRow, dropZone, beforeIdInput);
19137
19199
  }
19138
19200
  };
19139
19201
  //#endregion
@@ -20085,6 +20147,8 @@ var PanelUI = class {
20085
20147
  this._engine = engine;
20086
20148
  const addData = new AddDataSection({
20087
20149
  initialUrl: options?.defaultUrl,
20150
+ sampleData: options?.sampleData,
20151
+ sampleDataLabel: options?.sampleDataLabel,
20088
20152
  onAddUrl: (url, beforeId) => {
20089
20153
  this._manager.addRaster(url, { beforeId }).catch(() => {});
20090
20154
  },
@@ -20362,6 +20426,9 @@ var DEFAULT_OPTIONS = {
20362
20426
  interleaved: true,
20363
20427
  defaultUrl: "",
20364
20428
  autoLoad: false,
20429
+ sampleData: [],
20430
+ sampleDataLabel: "Load sample data...",
20431
+ closeOnOutsideClick: true,
20365
20432
  engine: "maplibre-gl-raster",
20366
20433
  epsgResolver: createResilientEpsgResolver()
20367
20434
  };
@@ -20449,6 +20516,8 @@ var RasterControl = class {
20449
20516
  const autoLoading = this._options.autoLoad && !!this._options.defaultUrl;
20450
20517
  if (content) this._panelUI = new PanelUI(content, this._layerManager, {
20451
20518
  defaultUrl: autoLoading ? "" : this._options.defaultUrl,
20519
+ sampleData: this._options.sampleData,
20520
+ sampleDataLabel: this._options.sampleDataLabel,
20452
20521
  inspect: {
20453
20522
  onToggle: () => this._inspector?.toggle(),
20454
20523
  isActive: () => this._inspector?.enabled ?? false
@@ -20967,13 +21036,15 @@ var RasterControl = class {
20967
21036
  * Setup event listeners for panel positioning and click-outside behavior.
20968
21037
  */
20969
21038
  _setupEventListeners() {
20970
- this._clickOutsideHandler = (e) => {
20971
- const target = e.target;
20972
- if (!target.isConnected) return;
20973
- if (this._inspector?.enabled) return;
20974
- if (this._container && this._panel && !this._container.contains(target) && !this._panel.contains(target)) this.collapse();
20975
- };
20976
- document.addEventListener("click", this._clickOutsideHandler);
21039
+ if (this._options.closeOnOutsideClick !== false) {
21040
+ this._clickOutsideHandler = (e) => {
21041
+ const target = e.target;
21042
+ if (!target.isConnected) return;
21043
+ if (this._inspector?.enabled) return;
21044
+ if (this._container && this._panel && !this._container.contains(target) && !this._panel.contains(target)) this.collapse();
21045
+ };
21046
+ document.addEventListener("click", this._clickOutsideHandler);
21047
+ }
20977
21048
  this._resizeHandler = () => {
20978
21049
  if (!this._state.collapsed) this._updatePanelPosition();
20979
21050
  };
@@ -21046,4 +21117,4 @@ var RasterControl = class {
21046
21117
  //#endregion
21047
21118
  export { MAX_SAMPLE_TILES as C, createResilientEpsgResolver as D, readBandNames as E, statsForBand as S, percentileFromHistogram as T, COLORMAP_OPTIONS as _, isKnownColormap as a, colormaps_default as b, clamp as c, formatNumericValue as d, generateId as f, COLORMAP_NAMES as g, COLORMAP_DISPLAY_NAMES as h, PALETTE_COLORMAP as i, classNames as l, loadGeoTIFF as m, Colorbar as n, loadColormapSprite as o, throttle as p, readPixelValues as r, sampleColormapStops as s, RasterControl as t, debounce as u, COLORMAP_ROW_COUNT as v, computeAutoStats as w, autoRangeFor as x, colormapDisplayName as y };
21048
21119
 
21049
- //# sourceMappingURL=RasterControl-CGsK4CN7.js.map
21120
+ //# sourceMappingURL=RasterControl-CjnDWQDU.js.map