File tree Expand file tree Collapse file tree
packages/builder-web-core/widgets-native/html-iframe-googlemaps Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { URLSearchParams } from "url" ;
21import { HtmlIframe } from "../html-iframe" ;
32import type { IIframeProps } from "../html-iframe" ;
43import type { IWHStyleWidget } from "@reflect-ui/core" ;
@@ -30,19 +29,18 @@ export class HtmlIframeGoogleMaps extends HtmlIframe {
3029
3130function 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 ( "&" ) ;
You can’t perform that action at this time.
0 commit comments