Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit a127a79

Browse files
committed
feat(LazyMapsAPILoader): support region & language
closes #102 closes #125
1 parent a3be298 commit a127a79

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/services/maps-api-loader/lazy-maps-api-loader.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ export class LazyMapsAPILoaderConfig {
3333
* Defines which Google Maps libraries should get loaded.
3434
*/
3535
libraries: string[] = [];
36+
37+
/**
38+
* The default bias for the map behavior is US.
39+
* If you wish to alter your application to serve different map tiles or bias the
40+
* application, you can overwrite the default behavior (US) by defining a `region`.
41+
* See https://developers.google.com/maps/documentation/javascript/basics#Region
42+
*/
43+
region: string = null;
44+
45+
/**
46+
* The Google Maps API uses the browser's preferred language when displaying
47+
* textual information. If you wish to overwrite this behavior and force the API
48+
* to use a given language, you can use this setting.
49+
* See https://developers.google.com/maps/documentation/javascript/basics#Language
50+
*/
51+
language: string = null;
3652
}
3753

3854
const DEFAULT_CONFIGURATION = new LazyMapsAPILoaderConfig();
@@ -90,6 +106,8 @@ export class LazyMapsAPILoader extends MapsAPILoader {
90106
const hostAndPath: string = this._config.hostAndPath || DEFAULT_CONFIGURATION.hostAndPath;
91107
const apiKey: string = this._config.apiKey || DEFAULT_CONFIGURATION.apiKey;
92108
const libraries: string[] = this._config.libraries || DEFAULT_CONFIGURATION.libraries;
109+
const region: string = this._config.region || DEFAULT_CONFIGURATION.region;
110+
const language: string = this._config.language || DEFAULT_CONFIGURATION.language;
93111
const queryParams: {[key: string]: string} = {
94112
v: this._config.apiVersion || DEFAULT_CONFIGURATION.apiKey,
95113
callback: callbackName
@@ -100,6 +118,12 @@ export class LazyMapsAPILoader extends MapsAPILoader {
100118
if (libraries != null && libraries.length > 0) {
101119
queryParams['libraries'] = libraries.join(',');
102120
}
121+
if (region != null && region.length > 0) {
122+
queryParams['region'] = region;
123+
}
124+
if (language != null && language.length > 0) {
125+
queryParams['language'] = language;
126+
}
103127
const params: string = Object.keys(queryParams)
104128
.map((k: string, i: number) => {
105129
let param = (i === 0) ? '?' : '&';

0 commit comments

Comments
 (0)