-
Notifications
You must be signed in to change notification settings - Fork 105
/
OpenStreetMapsProvider.ts
49 lines (43 loc) · 988 Bytes
/
OpenStreetMapsProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {MapProvider} from './MapProvider';
/**
* Open street maps tile server.
*
* Works with any service that uses a address/zoom/x/y.format URL for tile access.
*/
export class OpenStreetMapsProvider extends MapProvider
{
/**
* Map server address.
*
* By default the open OSM tile server is used.
*/
public address: string;
/**
* Map image tile format.
*/
public format: string;
public constructor(address: string = 'https://a.tile.openstreetmap.org/')
{
super();
this.address = address;
this.format = 'png';
this.maxZoom = 19;
}
public fetchTile(zoom: number, x: number, y: number): Promise<any>
{
return new Promise<HTMLImageElement>((resolve, reject) =>
{
const image = document.createElement('img');
image.onload = function()
{
resolve(image);
};
image.onerror = function()
{
reject();
};
image.crossOrigin = 'Anonymous';
image.src = this.address + zoom + '/' + x + '/' + y + '.' + this.format;
});
}
}