@deck.gl/widgets 9.2.8 → 9.2.10
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/dist/dist.dev.js +119 -121
- package/dist/geocoder-widget.d.ts +4 -1
- package/dist/geocoder-widget.d.ts.map +1 -1
- package/dist/geocoder-widget.js +50 -24
- package/dist/geocoder-widget.js.map +1 -1
- package/dist/index.cjs +89 -66
- package/dist/index.cjs.map +2 -2
- package/dist/lib/components/dropdown-menu.d.ts +7 -2
- package/dist/lib/components/dropdown-menu.d.ts.map +1 -1
- package/dist/lib/components/dropdown-menu.js +19 -34
- package/dist/lib/components/dropdown-menu.js.map +1 -1
- package/dist/stylesheet.css +154 -16
- package/dist/themes.d.ts +30 -0
- package/dist/themes.d.ts.map +1 -1
- package/dist/themes.js +28 -4
- package/dist/themes.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +2 -2
- package/src/geocoder-widget.tsx +58 -36
- package/src/lib/components/dropdown-menu.tsx +44 -56
- package/src/stylesheet.css +154 -16
- package/src/themes.ts +34 -4
package/dist/dist.dev.js
CHANGED
|
@@ -1144,6 +1144,15 @@ var __exports__ = (() => {
|
|
|
1144
1144
|
}
|
|
1145
1145
|
|
|
1146
1146
|
// src/lib/components/dropdown-menu.tsx
|
|
1147
|
+
function getMenuItemValue(item) {
|
|
1148
|
+
return typeof item === "string" ? item : item.value;
|
|
1149
|
+
}
|
|
1150
|
+
function getMenuItemLabel(item) {
|
|
1151
|
+
return typeof item === "string" ? item : item.label;
|
|
1152
|
+
}
|
|
1153
|
+
function getMenuItemIcon(item) {
|
|
1154
|
+
return typeof item === "string" ? void 0 : item.icon;
|
|
1155
|
+
}
|
|
1147
1156
|
var DropdownMenu = (props) => {
|
|
1148
1157
|
const [isOpen, setIsOpen] = h2(false);
|
|
1149
1158
|
const dropdownRef = A2(null);
|
|
@@ -1159,74 +1168,37 @@ var __exports__ = (() => {
|
|
|
1159
1168
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
1160
1169
|
};
|
|
1161
1170
|
}, []);
|
|
1162
|
-
const handleSelect = (
|
|
1163
|
-
props.onSelect(
|
|
1171
|
+
const handleSelect = (item) => {
|
|
1172
|
+
props.onSelect(getMenuItemValue(item));
|
|
1164
1173
|
setIsOpen(false);
|
|
1165
1174
|
};
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
style: {
|
|
1182
|
-
width: "30px",
|
|
1183
|
-
height: "30px",
|
|
1184
|
-
display: "flex",
|
|
1185
|
-
alignItems: "center",
|
|
1186
|
-
justifyContent: "center",
|
|
1187
|
-
border: "1px solid #ccc",
|
|
1188
|
-
borderRadius: "4px",
|
|
1189
|
-
background: "#fff",
|
|
1190
|
-
cursor: "pointer",
|
|
1191
|
-
padding: 0
|
|
1192
|
-
},
|
|
1193
|
-
children: "\u25BC"
|
|
1194
|
-
}
|
|
1195
|
-
),
|
|
1196
|
-
isOpen && /* @__PURE__ */ u2(
|
|
1197
|
-
"ul",
|
|
1198
|
-
{
|
|
1199
|
-
style: {
|
|
1200
|
-
position: "absolute",
|
|
1201
|
-
top: "100%",
|
|
1202
|
-
right: "100%",
|
|
1203
|
-
background: "#fff",
|
|
1204
|
-
border: "1px solid #ccc",
|
|
1205
|
-
borderRadius: "4px",
|
|
1206
|
-
listStyle: "none",
|
|
1207
|
-
padding: "4px 0",
|
|
1208
|
-
margin: 0,
|
|
1209
|
-
zIndex: 1e3,
|
|
1210
|
-
minWidth: "200px"
|
|
1211
|
-
},
|
|
1212
|
-
children: props.menuItems.map((item) => /* @__PURE__ */ u2(
|
|
1213
|
-
"li",
|
|
1175
|
+
if (props.menuItems.length === 0) {
|
|
1176
|
+
return null;
|
|
1177
|
+
}
|
|
1178
|
+
return /* @__PURE__ */ u2("div", { className: "deck-widget-dropdown-container", ref: dropdownRef, style: props.style, children: [
|
|
1179
|
+
/* @__PURE__ */ u2("button", { className: "deck-widget-dropdown-button", onClick: toggleDropdown, children: /* @__PURE__ */ u2("span", { className: `deck-widget-dropdown-icon ${isOpen ? "open" : ""}` }) }),
|
|
1180
|
+
isOpen && /* @__PURE__ */ u2("ul", { className: "deck-widget-dropdown-menu", children: props.menuItems.map((item) => {
|
|
1181
|
+
const icon = getMenuItemIcon(item);
|
|
1182
|
+
return /* @__PURE__ */ u2(
|
|
1183
|
+
"li",
|
|
1184
|
+
{
|
|
1185
|
+
className: "deck-widget-dropdown-item",
|
|
1186
|
+
onClick: () => handleSelect(item),
|
|
1187
|
+
children: [
|
|
1188
|
+
icon && /* @__PURE__ */ u2(
|
|
1189
|
+
"span",
|
|
1214
1190
|
{
|
|
1215
|
-
|
|
1216
|
-
style: {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
)
|
|
1227
|
-
]
|
|
1228
|
-
}
|
|
1229
|
-
);
|
|
1191
|
+
className: "deck-widget-dropdown-item-icon",
|
|
1192
|
+
style: { maskImage: `url("${icon}")`, WebkitMaskImage: `url("${icon}")` }
|
|
1193
|
+
}
|
|
1194
|
+
),
|
|
1195
|
+
getMenuItemLabel(item)
|
|
1196
|
+
]
|
|
1197
|
+
},
|
|
1198
|
+
getMenuItemValue(item)
|
|
1199
|
+
);
|
|
1200
|
+
}) })
|
|
1201
|
+
] });
|
|
1230
1202
|
};
|
|
1231
1203
|
|
|
1232
1204
|
// src/lib/geocode/geocoder-history.ts
|
|
@@ -1419,6 +1391,12 @@ var __exports__ = (() => {
|
|
|
1419
1391
|
|
|
1420
1392
|
// src/geocoder-widget.tsx
|
|
1421
1393
|
var CURRENT_LOCATION2 = "current";
|
|
1394
|
+
var LOCATION_ICON = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960'%3E%3Cpath d='M480-480q33 0 56.5-23.5T560-560q0-33-23.5-56.5T480-640q-33 0-56.5 23.5T400-560q0 33 23.5 56.5T480-480Zm0 294q122-112 181-203.5T720-552q0-109-69.5-178.5T480-800q-101 0-170.5 69.5T240-552q0 71 59 162.5T480-186Zm0 106Q319-217 239.5-334.5T160-552q0-150 96.5-239T480-880q127 0 223.5 89T800-552q0 100-79.5 217.5T480-80Z'/%3E%3C/svg%3E`;
|
|
1395
|
+
var CURRENT_LOCATION_ITEM = {
|
|
1396
|
+
label: "Current location",
|
|
1397
|
+
value: CURRENT_LOCATION2,
|
|
1398
|
+
icon: LOCATION_ICON
|
|
1399
|
+
};
|
|
1422
1400
|
var GeocoderWidget = class extends import_core7.Widget {
|
|
1423
1401
|
constructor(props = {}) {
|
|
1424
1402
|
super(props);
|
|
@@ -1427,6 +1405,7 @@ var __exports__ = (() => {
|
|
|
1427
1405
|
this.geocodeHistory = new GeocoderHistory({});
|
|
1428
1406
|
this.addressText = "";
|
|
1429
1407
|
this.geocoder = CoordinatesGeocoder;
|
|
1408
|
+
this.isGettingLocation = false;
|
|
1430
1409
|
this.setInput = (text) => {
|
|
1431
1410
|
this.addressText = text;
|
|
1432
1411
|
};
|
|
@@ -1435,23 +1414,48 @@ var __exports__ = (() => {
|
|
|
1435
1414
|
this.handleSubmit();
|
|
1436
1415
|
}
|
|
1437
1416
|
};
|
|
1438
|
-
this.handleSelect = (
|
|
1439
|
-
|
|
1440
|
-
|
|
1417
|
+
this.handleSelect = (value) => {
|
|
1418
|
+
if (value === CURRENT_LOCATION2) {
|
|
1419
|
+
this.getCurrentLocation();
|
|
1420
|
+
} else {
|
|
1421
|
+
this.setInput(value);
|
|
1422
|
+
this.handleSubmit();
|
|
1423
|
+
}
|
|
1441
1424
|
};
|
|
1442
1425
|
/** Sync wrapper for async geocode() */
|
|
1443
1426
|
this.handleSubmit = () => {
|
|
1444
1427
|
this.geocode(this.addressText);
|
|
1445
1428
|
};
|
|
1429
|
+
/** Get current location via browser geolocation API */
|
|
1430
|
+
this.getCurrentLocation = async () => {
|
|
1431
|
+
this.isGettingLocation = true;
|
|
1432
|
+
if (this.rootElement) {
|
|
1433
|
+
this.updateHTML();
|
|
1434
|
+
}
|
|
1435
|
+
try {
|
|
1436
|
+
const coordinates = await CurrentLocationGeocoder.geocode();
|
|
1437
|
+
if (coordinates) {
|
|
1438
|
+
this.setViewState(coordinates);
|
|
1439
|
+
}
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
this.geocodeHistory.errorText = error instanceof Error ? error.message : "Location error";
|
|
1442
|
+
} finally {
|
|
1443
|
+
this.isGettingLocation = false;
|
|
1444
|
+
if (this.rootElement) {
|
|
1445
|
+
this.updateHTML();
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1446
1449
|
/** Perform geocoding */
|
|
1447
1450
|
this.geocode = async (address) => {
|
|
1448
|
-
const useGeolocation = this.props._geolocation && address === CURRENT_LOCATION2;
|
|
1449
|
-
const geocoder = useGeolocation ? CurrentLocationGeocoder : this.geocoder;
|
|
1450
1451
|
const coordinates = await this.geocodeHistory.geocode(
|
|
1451
|
-
geocoder,
|
|
1452
|
+
this.geocoder,
|
|
1452
1453
|
this.addressText,
|
|
1453
1454
|
this.props.apiKey
|
|
1454
1455
|
);
|
|
1456
|
+
if (this.rootElement) {
|
|
1457
|
+
this.updateHTML();
|
|
1458
|
+
}
|
|
1455
1459
|
if (coordinates) {
|
|
1456
1460
|
this.setViewState(coordinates);
|
|
1457
1461
|
}
|
|
@@ -1469,53 +1473,23 @@ var __exports__ = (() => {
|
|
|
1469
1473
|
super.setProps(props);
|
|
1470
1474
|
}
|
|
1471
1475
|
onRenderHTML(rootElement) {
|
|
1472
|
-
const menuItems = this.props._geolocation ? [
|
|
1476
|
+
const menuItems = this.props._geolocation ? [CURRENT_LOCATION_ITEM, ...this.geocodeHistory.addressHistory] : [...this.geocodeHistory.addressHistory];
|
|
1473
1477
|
B(
|
|
1474
|
-
/* @__PURE__ */ u2(
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
type: "text",
|
|
1490
|
-
placeholder: this.geocoder.placeholderLocation ?? "Enter address or location",
|
|
1491
|
-
value: this.geocodeHistory.addressText,
|
|
1492
|
-
onInput: (e3) => this.setInput(e3.target?.value || ""),
|
|
1493
|
-
onKeyPress: this.handleKeyPress,
|
|
1494
|
-
style: {
|
|
1495
|
-
flex: "1 1 auto",
|
|
1496
|
-
minWidth: "200px",
|
|
1497
|
-
margin: 0,
|
|
1498
|
-
padding: "8px",
|
|
1499
|
-
boxSizing: "border-box"
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
),
|
|
1503
|
-
/* @__PURE__ */ u2(
|
|
1504
|
-
DropdownMenu,
|
|
1505
|
-
{
|
|
1506
|
-
menuItems,
|
|
1507
|
-
onSelect: this.handleSelect,
|
|
1508
|
-
style: {
|
|
1509
|
-
margin: 2,
|
|
1510
|
-
padding: "4px 2px",
|
|
1511
|
-
boxSizing: "border-box"
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
),
|
|
1515
|
-
this.geocodeHistory.errorText && /* @__PURE__ */ u2("div", { className: "error", children: this.geocodeHistory.errorText })
|
|
1516
|
-
]
|
|
1517
|
-
}
|
|
1518
|
-
),
|
|
1478
|
+
/* @__PURE__ */ u2("div", { className: "deck-widget-geocoder", children: [
|
|
1479
|
+
/* @__PURE__ */ u2(
|
|
1480
|
+
"input",
|
|
1481
|
+
{
|
|
1482
|
+
className: "deck-widget-geocoder-input",
|
|
1483
|
+
type: "text",
|
|
1484
|
+
placeholder: this.isGettingLocation ? "Finding your location..." : this.geocoder.placeholderLocation ?? "Enter address or location",
|
|
1485
|
+
value: this.geocodeHistory.addressText,
|
|
1486
|
+
onInput: (e3) => this.setInput(e3.target?.value || ""),
|
|
1487
|
+
onKeyPress: this.handleKeyPress
|
|
1488
|
+
}
|
|
1489
|
+
),
|
|
1490
|
+
/* @__PURE__ */ u2(DropdownMenu, { menuItems, onSelect: this.handleSelect }),
|
|
1491
|
+
this.geocodeHistory.errorText && /* @__PURE__ */ u2("div", { className: "deck-widget-geocoder-error", children: this.geocodeHistory.errorText })
|
|
1492
|
+
] }),
|
|
1519
1493
|
rootElement
|
|
1520
1494
|
);
|
|
1521
1495
|
}
|
|
@@ -2386,7 +2360,13 @@ var __exports__ = (() => {
|
|
|
2386
2360
|
"--button-text": "rgb(24, 24, 26, 1)",
|
|
2387
2361
|
"--icon-compass-north-color": "rgb(240, 92, 68)",
|
|
2388
2362
|
"--icon-compass-south-color": "rgb(204, 204, 204)",
|
|
2389
|
-
"--menu-gap": "4px"
|
|
2363
|
+
"--menu-gap": "4px",
|
|
2364
|
+
"--menu-background": "#fff",
|
|
2365
|
+
"--menu-backdrop-filter": "unset",
|
|
2366
|
+
"--menu-border": "unset",
|
|
2367
|
+
"--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25)",
|
|
2368
|
+
"--menu-text": "rgb(24, 24, 26, 1)",
|
|
2369
|
+
"--menu-item-hover": "rgba(0, 0, 0, 0.08)"
|
|
2390
2370
|
};
|
|
2391
2371
|
var DarkTheme = {
|
|
2392
2372
|
"--widget-margin": "12px",
|
|
@@ -2402,7 +2382,13 @@ var __exports__ = (() => {
|
|
|
2402
2382
|
"--button-text": "rgb(215, 214, 229, 1)",
|
|
2403
2383
|
"--icon-compass-north-color": "rgb(240, 92, 68)",
|
|
2404
2384
|
"--icon-compass-south-color": "rgb(200, 199, 209)",
|
|
2405
|
-
"--menu-gap": "4px"
|
|
2385
|
+
"--menu-gap": "4px",
|
|
2386
|
+
"--menu-background": "rgba(18, 18, 20, 1)",
|
|
2387
|
+
"--menu-backdrop-filter": "unset",
|
|
2388
|
+
"--menu-border": "unset",
|
|
2389
|
+
"--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25)",
|
|
2390
|
+
"--menu-text": "rgb(215, 214, 229, 1)",
|
|
2391
|
+
"--menu-item-hover": "rgba(255, 255, 255, 0.1)"
|
|
2406
2392
|
};
|
|
2407
2393
|
var LightGlassTheme = {
|
|
2408
2394
|
"--widget-margin": "12px",
|
|
@@ -2418,7 +2404,13 @@ var __exports__ = (() => {
|
|
|
2418
2404
|
"--button-text": "rgb(24, 24, 26, 1)",
|
|
2419
2405
|
"--icon-compass-north-color": "rgb(240, 92, 68)",
|
|
2420
2406
|
"--icon-compass-south-color": "rgb(204, 204, 204)",
|
|
2421
|
-
"--menu-gap": "4px"
|
|
2407
|
+
"--menu-gap": "4px",
|
|
2408
|
+
"--menu-background": "rgba(255, 255, 255, 0.6)",
|
|
2409
|
+
"--menu-backdrop-filter": "blur(4px)",
|
|
2410
|
+
"--menu-border": "1px solid rgba(255, 255, 255, 0.6)",
|
|
2411
|
+
"--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25), 0px 0px 8px 0px rgba(0, 0, 0, 0.1) inset",
|
|
2412
|
+
"--menu-text": "rgb(24, 24, 26, 1)",
|
|
2413
|
+
"--menu-item-hover": "rgba(0, 0, 0, 0.08)"
|
|
2422
2414
|
};
|
|
2423
2415
|
var DarkGlassTheme = {
|
|
2424
2416
|
"--widget-margin": "12px",
|
|
@@ -2434,7 +2426,13 @@ var __exports__ = (() => {
|
|
|
2434
2426
|
"--button-text": "rgb(215, 214, 229, 1)",
|
|
2435
2427
|
"--icon-compass-north-color": "rgb(240, 92, 68)",
|
|
2436
2428
|
"--icon-compass-south-color": "rgb(200, 199, 209)",
|
|
2437
|
-
"--menu-gap": "4px"
|
|
2429
|
+
"--menu-gap": "4px",
|
|
2430
|
+
"--menu-background": "rgba(18, 18, 20, 0.75)",
|
|
2431
|
+
"--menu-backdrop-filter": "blur(4px)",
|
|
2432
|
+
"--menu-border": "1px solid rgba(18, 18, 20, 0.75)",
|
|
2433
|
+
"--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25), 0px 0px 8px 0px rgba(0, 0, 0, 0.1) inset",
|
|
2434
|
+
"--menu-text": "rgb(215, 214, 229, 1)",
|
|
2435
|
+
"--menu-item-hover": "rgba(255, 255, 255, 0.1)"
|
|
2438
2436
|
};
|
|
2439
2437
|
|
|
2440
2438
|
// src/theme-widget.tsx
|
|
@@ -34,14 +34,17 @@ export declare class GeocoderWidget extends Widget<GeocoderWidgetProps> {
|
|
|
34
34
|
geocodeHistory: GeocoderHistory;
|
|
35
35
|
addressText: string;
|
|
36
36
|
geocoder: Geocoder;
|
|
37
|
+
isGettingLocation: boolean;
|
|
37
38
|
constructor(props?: GeocoderWidgetProps);
|
|
38
39
|
setProps(props: Partial<GeocoderWidgetProps>): void;
|
|
39
40
|
onRenderHTML(rootElement: HTMLElement): void;
|
|
40
41
|
setInput: (text: string) => void;
|
|
41
42
|
handleKeyPress: (e: any) => void;
|
|
42
|
-
handleSelect: (
|
|
43
|
+
handleSelect: (value: string) => void;
|
|
43
44
|
/** Sync wrapper for async geocode() */
|
|
44
45
|
handleSubmit: () => void;
|
|
46
|
+
/** Get current location via browser geolocation API */
|
|
47
|
+
getCurrentLocation: () => Promise<void>;
|
|
45
48
|
/** Perform geocoding */
|
|
46
49
|
geocode: (address: string) => Promise<void>;
|
|
47
50
|
setViewState(viewState: ViewState): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geocoder-widget.d.ts","sourceRoot":"","sources":["../src/geocoder-widget.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,EAAC,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAC,MAAM,eAAe,CA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SAAS,SAA0B;IACnC,SAAS,EAAE,eAAe,CAAc;IAExC,cAAc,kBAA2B;IACzC,WAAW,EAAE,MAAM,CAAM;IACzB,QAAQ,EAAE,QAAQ,CAAuB;IACzC,iBAAiB,EAAE,OAAO,CAAS;gBAEvB,KAAK,GAAE,mBAAwB;IAK3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI;IAUnD,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IA4B5C,QAAQ,SAAU,MAAM,UAEtB;IAEF,cAAc,mBAIZ;IAEF,YAAY,UAAW,MAAM,UAS3B;IAEF,uCAAuC;IACvC,YAAY,aAGV;IAEF,uDAAuD;IACvD,kBAAkB,sBAmBhB;IAEF,wBAAwB;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAazC;IAGF,YAAY,CAAC,SAAS,EAAE,SAAS;IAiBjC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ;IAInC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAM;CAC1C"}
|
package/dist/geocoder-widget.js
CHANGED
|
@@ -9,6 +9,13 @@ import { DropdownMenu } from "./lib/components/dropdown-menu.js";
|
|
|
9
9
|
import { GeocoderHistory } from "./lib/geocode/geocoder-history.js";
|
|
10
10
|
import { GoogleGeocoder, MapboxGeocoder, OpenCageGeocoder, CoordinatesGeocoder, CurrentLocationGeocoder } from "./lib/geocode/geocoders.js";
|
|
11
11
|
const CURRENT_LOCATION = 'current';
|
|
12
|
+
// Location pin icon (from Google Material Symbols)
|
|
13
|
+
const LOCATION_ICON = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960'%3E%3Cpath d='M480-480q33 0 56.5-23.5T560-560q0-33-23.5-56.5T480-640q-33 0-56.5 23.5T400-560q0 33 23.5 56.5T480-480Zm0 294q122-112 181-203.5T720-552q0-109-69.5-178.5T480-800q-101 0-170.5 69.5T240-552q0 71 59 162.5T480-186Zm0 106Q319-217 239.5-334.5T160-552q0-150 96.5-239T480-880q127 0 223.5 89T800-552q0 100-79.5 217.5T480-80Z'/%3E%3C/svg%3E`;
|
|
14
|
+
const CURRENT_LOCATION_ITEM = {
|
|
15
|
+
label: 'Current location',
|
|
16
|
+
value: CURRENT_LOCATION,
|
|
17
|
+
icon: LOCATION_ICON
|
|
18
|
+
};
|
|
12
19
|
/**
|
|
13
20
|
* A widget that display a text box that lets user type in a location
|
|
14
21
|
* and a button that moves the view to that location.
|
|
@@ -22,6 +29,7 @@ export class GeocoderWidget extends Widget {
|
|
|
22
29
|
this.geocodeHistory = new GeocoderHistory({});
|
|
23
30
|
this.addressText = '';
|
|
24
31
|
this.geocoder = CoordinatesGeocoder;
|
|
32
|
+
this.isGettingLocation = false;
|
|
25
33
|
this.setInput = (text) => {
|
|
26
34
|
this.addressText = text;
|
|
27
35
|
};
|
|
@@ -30,20 +38,51 @@ export class GeocoderWidget extends Widget {
|
|
|
30
38
|
this.handleSubmit();
|
|
31
39
|
}
|
|
32
40
|
};
|
|
33
|
-
this.handleSelect = (
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
this.handleSelect = (value) => {
|
|
42
|
+
if (value === CURRENT_LOCATION) {
|
|
43
|
+
// Don't put "current" in the text field, just trigger geolocation
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
45
|
+
this.getCurrentLocation();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.setInput(value);
|
|
49
|
+
this.handleSubmit();
|
|
50
|
+
}
|
|
36
51
|
};
|
|
37
52
|
/** Sync wrapper for async geocode() */
|
|
38
53
|
this.handleSubmit = () => {
|
|
39
54
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
40
55
|
this.geocode(this.addressText);
|
|
41
56
|
};
|
|
57
|
+
/** Get current location via browser geolocation API */
|
|
58
|
+
this.getCurrentLocation = async () => {
|
|
59
|
+
this.isGettingLocation = true;
|
|
60
|
+
if (this.rootElement) {
|
|
61
|
+
this.updateHTML();
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const coordinates = await CurrentLocationGeocoder.geocode();
|
|
65
|
+
if (coordinates) {
|
|
66
|
+
this.setViewState(coordinates);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.geocodeHistory.errorText = error instanceof Error ? error.message : 'Location error';
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
this.isGettingLocation = false;
|
|
74
|
+
if (this.rootElement) {
|
|
75
|
+
this.updateHTML();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
42
79
|
/** Perform geocoding */
|
|
43
80
|
this.geocode = async (address) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
81
|
+
const coordinates = await this.geocodeHistory.geocode(this.geocoder, this.addressText, this.props.apiKey);
|
|
82
|
+
// Re-render to show updated history or error (guard against torn-down widget)
|
|
83
|
+
if (this.rootElement) {
|
|
84
|
+
this.updateHTML();
|
|
85
|
+
}
|
|
47
86
|
if (coordinates) {
|
|
48
87
|
this.setViewState(coordinates);
|
|
49
88
|
}
|
|
@@ -62,26 +101,13 @@ export class GeocoderWidget extends Widget {
|
|
|
62
101
|
}
|
|
63
102
|
onRenderHTML(rootElement) {
|
|
64
103
|
const menuItems = this.props._geolocation
|
|
65
|
-
? [
|
|
104
|
+
? [CURRENT_LOCATION_ITEM, ...this.geocodeHistory.addressHistory]
|
|
66
105
|
: [...this.geocodeHistory.addressHistory];
|
|
67
|
-
render(_jsxs("div", { className: "deck-widget-geocoder",
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
alignItems: 'center',
|
|
71
|
-
flexWrap: 'wrap' // Allows wrapping on smaller screens
|
|
72
|
-
}, children: [_jsx("input", { type: "text", placeholder: this.geocoder.placeholderLocation ?? 'Enter address or location', value: this.geocodeHistory.addressText,
|
|
106
|
+
render(_jsxs("div", { className: "deck-widget-geocoder", children: [_jsx("input", { className: "deck-widget-geocoder-input", type: "text", placeholder: this.isGettingLocation
|
|
107
|
+
? 'Finding your location...'
|
|
108
|
+
: (this.geocoder.placeholderLocation ?? 'Enter address or location'), value: this.geocodeHistory.addressText,
|
|
73
109
|
// @ts-expect-error event type
|
|
74
|
-
onInput: e => this.setInput(e.target?.value || ''), onKeyPress: this.handleKeyPress,
|
|
75
|
-
flex: '1 1 auto',
|
|
76
|
-
minWidth: '200px',
|
|
77
|
-
margin: 0,
|
|
78
|
-
padding: '8px',
|
|
79
|
-
boxSizing: 'border-box'
|
|
80
|
-
} }), _jsx(DropdownMenu, { menuItems: menuItems, onSelect: this.handleSelect, style: {
|
|
81
|
-
margin: 2,
|
|
82
|
-
padding: '4px 2px',
|
|
83
|
-
boxSizing: 'border-box'
|
|
84
|
-
} }), this.geocodeHistory.errorText && (_jsx("div", { className: "error", children: this.geocodeHistory.errorText }))] }), rootElement);
|
|
110
|
+
onInput: e => this.setInput(e.target?.value || ''), onKeyPress: this.handleKeyPress }), _jsx(DropdownMenu, { menuItems: menuItems, onSelect: this.handleSelect }), this.geocodeHistory.errorText && (_jsx("div", { className: "deck-widget-geocoder-error", children: this.geocodeHistory.errorText }))] }), rootElement);
|
|
85
111
|
}
|
|
86
112
|
// TODO - MOVE TO WIDGETIMPL?
|
|
87
113
|
setViewState(viewState) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geocoder-widget.js","sourceRoot":"","sources":["../src/geocoder-widget.tsx"],"names":[],"mappings":";AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,OAAO,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACpE,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,YAAY,
|
|
1
|
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