Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit b037052

Browse files
author
Cole J Calamos
committed
Fixed external URL
1 parent 04e2edc commit b037052

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ccalamos/gatsby-source-googlemaps-static",
33
"description": "Gatsby source plugin for Google Maps Static API",
4-
"version": "2.0.5",
4+
"version": "2.0.6",
55
"author": "Cole Calamos <cole@colejcalamos.com>",
66
"bugs": {
77
"url": "https://github.com/ccalamos/gatsby-source-googlemaps-static/issues"

src/sourceNodes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const processNodes = async (
3333
},
3434
};
3535
const node = Object.assign({}, datum, nodeMeta);
36-
console.log("HERE!");
3736
await createNode(node);
3837
};
3938

src/static-map.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class StaticMap
5151
this.mapType = options.mapType;
5252
this.mapID = options.mapID;
5353
this.query = options.query;
54-
this.url = this.generateMapUrl();
54+
this.url = this.getPublicSearchURL();
5555
this.file = new ImageFile(cache, this.getImageJSON());
5656
}
5757

@@ -89,9 +89,13 @@ class StaticMap
8989
return arr ? !arr.length : true;
9090
}
9191

92+
private isCords(): boolean {
93+
return !this.query && RegExp(/^[^a-zA-Z]+$/).test(this.center);
94+
}
95+
9296
private getImageJSON(): ImageFileOptions {
9397
return {
94-
baseUrl: this.url,
98+
baseUrl: this.generateMapUrl(),
9599
clientID: this.clientID ?? "",
96100
format: this.format,
97101
hasSecret: this.hasSecret ?? false,
@@ -120,11 +124,17 @@ class StaticMap
120124
private generateMapUrl(): string {
121125
return `https://www.google.com/maps/api/staticmap?${
122126
this.isImplicit() ? this.parseWayPoints() : ""
123-
}${
124-
this.center || this.query
125-
? `center=${encodeURIComponent(this.center ?? this.query)}`
126-
: ""
127-
}`;
127+
}${this.center ? `center=${encodeURIComponent(this.center)}` : ""}`;
128+
}
129+
130+
private getPublicSearchURL(): string {
131+
const URLBuilder: [dir: string, action: string] = this.isImplicit()
132+
? ["dir/", this.parseWayPoints()]
133+
: this.isCords()
134+
? ["@", `map_action=map&center=${encodeURIComponent(this.center)}`]
135+
: ["search/", encodeURIComponent(this.query ?? this.center)];
136+
137+
return `https://www.google.com/maps/${URLBuilder[0]}?api=1&${URLBuilder[1]}`;
128138
}
129139

130140
private parseWayPoints(): string {

0 commit comments

Comments
 (0)