-
Notifications
You must be signed in to change notification settings - Fork 10
/
NgwKit.ts
124 lines (109 loc) · 2.92 KB
/
NgwKit.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* @module ngw-kit
*/
import NgwConnector from '@nextgis/ngw-connector';
import WebMap, { StarterKit, Type } from '@nextgis/webmap';
import {
getNgwResourceExtent,
sendIdentifyRequest,
pixelsInMeterWidth,
updateWmsParams,
getLayerAdapterOptions,
addNgwLayer,
extendWebMapLayerAdapter,
setScaleRatio
} from './utils/utils';
import {
getIdentifyGeoJson,
getIdentifyGeoJsonParams
} from './utils/identifyUtils';
import {
getNgwLayerItems,
getNgwLayerItem,
getNgwLayerFeatures,
getNgwLayerFeature,
createGeoJsonFeature
} from './utils/featureLayerUtils';
import { NgwKitOptions, WebMapAdapterOptions } from './interfaces';
import { WebMapLayerAdapter } from './WebMapLayerAdapter';
export class NgwKit implements StarterKit {
static utils = {
addNgwLayer,
getNgwResourceExtent,
sendIdentifyRequest,
pixelsInMeterWidth,
getNgwLayerFeature,
getNgwLayerFeatures,
getNgwLayerItems,
getNgwLayerItem,
getIdentifyGeoJson,
getIdentifyGeoJsonParams,
createGeoJsonFeature,
setScaleRatio
};
static updateWmsParams = updateWmsParams;
static getLayerAdapterOptions = getLayerAdapterOptions;
static addNgwLayer = addNgwLayer;
url: string;
connector: NgwConnector;
webMap?: WebMap;
constructor(public options: NgwKitOptions) {
if (this.options.connector) {
this.url = this.options.connector.options.baseUrl;
this.connector = this.options.connector;
} else {
if (this.options.baseUrl) {
this.url = this.options.baseUrl;
} else {
throw new Error('url is not defined');
}
this.connector = new NgwConnector({
baseUrl: this.url,
auth: this.options.auth
});
}
}
async onLoadSync(webMap: WebMap) {
if (this.options.resourceId && this.url) {
// TODO: resources from array
const resourceIds = [this.options.resourceId];
if (resourceIds.length) {
for (const r of resourceIds) {
const options: WebMapAdapterOptions = {
resourceId: r,
connector: this.connector,
baseUrl: this.url,
webMap
};
const layer = (await webMap.addLayer(WebMapLayerAdapter, {
visibility: true,
fit: true,
identification: this.options.identification,
pixelRadius: this.options.pixelRadius,
...options
})) as WebMapLayerAdapter;
return layer;
}
}
}
}
getLayerAdapters() {
return Promise.resolve([this._getLayerAdapter()]);
}
private _getLayerAdapter() {
return {
name: 'WEBMAP',
createAdapter: (webmap: WebMap) =>
Promise.resolve(this._createAdapter(webmap))
};
}
private _createAdapter(webMap: WebMap): Type<WebMapLayerAdapter> {
const connector = this.connector;
const baseUrl = this.url;
return extendWebMapLayerAdapter({
webMap,
connector,
baseUrl
});
}
}