Skip to content

Commit 98abd25

Browse files
rm urlsearchparams use for non browser node env
1 parent 369884b commit 98abd25

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

  • packages/builder-web-core/widgets-native/html-iframe-googlemaps

packages/builder-web-core/widgets-native/html-iframe-googlemaps/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { URLSearchParams } from "url";
21
import { HtmlIframe } from "../html-iframe";
32
import type { IIframeProps } from "../html-iframe";
43
import type { IWHStyleWidget } from "@reflect-ui/core";
@@ -30,19 +29,18 @@ export class HtmlIframeGoogleMaps extends HtmlIframe {
3029

3130
function gmapurl(q: string, apikey?: string): string {
3231
// build query param
33-
const query = new URLSearchParams();
34-
query.set("q", q);
32+
const query = {};
33+
query["q"] = q;
3534
if (apikey) {
36-
query.set("key", apikey);
37-
// build url
38-
const url = new URL("https://www.google.com/maps/embed/v1/place");
39-
url.search = query.toString();
40-
41-
return url.toString();
35+
query["key"] = apikey;
36+
return `https://www.google.com/maps/embed/v1/place?${buildq(query)}`;
4237
} else {
43-
query.set("output", "embed");
44-
const url = new URL("https://maps.google.com/maps");
45-
url.search = query.toString();
46-
return url.toString();
38+
query["output"] = "embed";
39+
return `https://maps.google.com/maps?${buildq(query)}`;
4740
}
4841
}
42+
43+
const buildq = (q: object): string =>
44+
Object.keys(q)
45+
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(q[k])}`)
46+
.join("&");

0 commit comments

Comments
 (0)