Skip to content

Commit b4f9f9d

Browse files
committed
getMetaData async
1 parent 5334a4e commit b4f9f9d

File tree

6 files changed

+48
-67
lines changed

6 files changed

+48
-67
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "geo-three",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"type": "module",
55
"description": "geo-three is library for tile based geographic map layers in with three.js supporting selective loading/unloading of real-time generated 3D tiles",
66
"main": "build/Main.d.ts",
@@ -38,7 +38,7 @@
3838
"author": "Tentone",
3939
"license": "MIT",
4040
"peerDependencies": {
41-
"three": "^0.120.0"
41+
"three": ">0.120.0"
4242
},
4343
"devDependencies": {
4444
"@rollup/plugin-strip": "~2.1.0",

source/providers/BingMapsProvider.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export class BingMapsProvider extends MapProvider
5555
*/
5656
public subdomain: string = 't1';
5757

58+
/**
59+
* Metadata of the provider.
60+
*/
61+
public meta: any = null;
62+
5863
/**
5964
* @param apiKey - Bing API key.
6065
* @param type - Type provider.
@@ -99,16 +104,12 @@ export class BingMapsProvider extends MapProvider
99104
*
100105
* http://ecn.\{subdomain\}.tiles.virtualearth.net/tiles/r\{quadkey\}.jpeg?g=129&mkt=\{culture\}&shading=hill&stl=H
101106
*/
102-
public getMetaData(): void
107+
public async getMetaData(): Promise<void>
103108
{
104109
const address = BingMapsProvider.ADDRESS + '/REST/V1/Imagery/Metadata/RoadOnDemand?output=json&include=ImageryProviders&key=' + this.apiKey;
110+
const data = await XHRUtils.get(address);
105111

106-
XHRUtils.get(address, function(data)
107-
{
108-
const meta = JSON.parse(data);
109-
110-
// TODO <FILL METADATA>
111-
});
112+
this.meta = JSON.parse(data);
112113
}
113114

114115
/**

source/providers/MapBoxProvider.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,18 @@ export class MapBoxProvider extends MapProvider
111111
this.version = version;
112112
}
113113

114-
public getMetaData(): void
114+
public async getMetaData(): Promise<void>
115115
{
116116
const address = MapBoxProvider.ADDRESS + this.version + '/' + this.mapId + '.json?access_token=' + this.apiToken;
117117

118-
XHRUtils.get(address, (data: any): void =>
119-
{
120-
const meta = JSON.parse(data);
121-
122-
this.name = meta.name;
123-
this.minZoom = meta.minZoom;
124-
this.maxZoom = meta.maxZoom;
125-
this.bounds = meta.bounds;
126-
this.center = meta.center;
127-
});
118+
const data = await XHRUtils.get(address);
119+
120+
const meta = JSON.parse(data);
121+
this.name = meta.name;
122+
this.minZoom = meta.minZoom;
123+
this.maxZoom = meta.maxZoom;
124+
this.bounds = meta.bounds;
125+
this.center = meta.center;
128126
}
129127

130128
public fetchTile(zoom: number, x: number, y: number): Promise<any>

source/providers/MapProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ export abstract class MapProvider
5454
*
5555
* Usually map server have API method to retrieve TileJSON metadata.
5656
*/
57-
public getMetaData(): void {}
57+
public async getMetaData(): Promise<void> {}
5858
}

source/providers/OpenMapTilesProvider.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,18 @@ export class OpenMapTilesProvider extends MapProvider
4040
this.theme = theme;
4141
}
4242

43-
public getMetaData(): void
43+
public async getMetaData(): Promise<void>
4444
{
4545
const address = this.address + 'styles/' + this.theme + '.json';
4646

47-
XHRUtils.get(address, (data: any) =>
48-
{
49-
const meta = JSON.parse(data);
50-
this.name = meta.name;
51-
this.format = meta.format;
52-
this.minZoom = meta.minZoom;
53-
this.maxZoom = meta.maxZoom;
54-
this.bounds = meta.bounds;
55-
this.center = meta.center;
56-
});
47+
const data = await XHRUtils.get(address);
48+
const meta = JSON.parse(data);
49+
this.name = meta.name;
50+
this.format = meta.format;
51+
this.minZoom = meta.minZoom;
52+
this.maxZoom = meta.maxZoom;
53+
this.bounds = meta.bounds;
54+
this.center = meta.center;
5755
}
5856

5957
public fetchTile(zoom: number, x: number, y: number): Promise<any>

source/utils/XHRUtils.ts

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,21 @@ export class XHRUtils
1010
* @param onLoad - On load callback.
1111
* @param onError - On progress callback.
1212
*/
13-
public static get(url: string, onLoad?: Function, onError?: Function): XMLHttpRequest
13+
public static async get(url: string): Promise<any>
1414
{
15-
const xhr = new XMLHttpRequest();
16-
xhr.overrideMimeType('text/plain');
17-
xhr.open('GET', url, true);
15+
return new Promise(function(resolve, reject) {
16+
const xhr = new XMLHttpRequest();
17+
xhr.overrideMimeType('text/plain');
18+
xhr.open('GET', url, true);
1819

19-
if (onLoad !== undefined)
20-
{
2120
xhr.onload = function()
2221
{
23-
onLoad(xhr.response);
22+
resolve(xhr.response);
2423
};
25-
}
26-
27-
if (onError !== undefined)
28-
{
29-
// @ts-ignore
30-
xhr.onerror = onError;
31-
}
32-
33-
xhr.send(null);
3424

35-
return xhr;
25+
xhr.onerror = reject;
26+
xhr.send(null);
27+
});
3628
}
3729

3830
/**
@@ -42,29 +34,21 @@ export class XHRUtils
4234
* @param onLoad - On load callback.
4335
* @param onError - On progress callback.
4436
*/
45-
public static getRaw(url: string, onLoad?: Function, onError?: Function): XMLHttpRequest
37+
public static async getRaw(url: string): Promise<ArrayBuffer>
4638
{
47-
var xhr = new XMLHttpRequest();
48-
xhr.responseType = 'arraybuffer';
49-
xhr.open('GET', url, true);
39+
return new Promise(function(resolve, reject) {
40+
var xhr = new XMLHttpRequest();
41+
xhr.responseType = 'arraybuffer';
42+
xhr.open('GET', url, true);
5043

51-
if (onLoad !== undefined)
52-
{
53-
xhr.onload = function()
44+
xhr.onload = function()
5445
{
55-
onLoad(xhr.response);
46+
resolve(xhr.response);
5647
};
57-
}
5848

59-
if (onError !== undefined)
60-
{
61-
// @ts-ignore
62-
xhr.onerror = onError;
63-
}
64-
65-
xhr.send(null);
66-
67-
return xhr;
49+
xhr.onerror = reject;
50+
xhr.send(null);
51+
});
6852
}
6953

7054
/**

0 commit comments

Comments
 (0)