Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
if (xmlHttp.responseText) {
try {
resolve(JSON.parse(xmlHttp.responseText));
} catch (er) {
reject(er);
}
}
}
};
xmlHttp.open('GET', fixUrlStr(url), true); // true for asynchronous
xmlHttp.send();
});
}
export function prepareWebMapOptions(
mapAdapter: MapAdapter,
options: NgwMapOptions
) {
const kits: StarterKit[] = [new QmsKit()];
if (!options.connector && options.baseUrl) {
options.connector = new NgwConnector({
baseUrl: options.baseUrl,
auth: options.auth
});
} else if (options.connector) {
options.baseUrl = options.connector.options.baseUrl;
}
const opt: NgwMapOptions = deepmerge(OPTIONS, options);
if (opt.connector) {
kits.push(
new NgwKit({
connector: opt.connector,
auth: opt.auth,
identification: opt.identification
})
);
}
return {
mapAdapter,
starterKits: kits,
runtimeParams: options.runtimeParams
};
}
constructor(mapAdapter: MapAdapter, options: NgwMapOptions & O) {
super(prepareWebMapOptions(mapAdapter, options));
if (options.connector) {
this.connector = options.connector;
}
this.options = deepmerge(OPTIONS, options);
this._createWebMap().then(() => {
const container = this.getContainer();
if (container) {
container.classList.add('ngw-map-container');
}
this._addControls();
});
}
async create(options?: MapOptions): Promise {
if (!this.getEventStatus('create')) {
this.options = deepmerge(OPTIONS || {}, options);
await this._setInitMapState(this.mapState);
await this._setupMap();
this._emitStatusEvent('create', this);
}
return this;
}
constructor(appOptions: AppOptions) {
this.mapAdapter = appOptions.mapAdapter;
this._starterKits = appOptions.starterKits || [];
if (appOptions.mapOptions) {
this.options = deepmerge(OPTIONS || {}, appOptions.mapOptions);
}
if (appOptions.runtimeParams) {
this.runtimeParams = appOptions.runtimeParams;
}
this._addEventsListeners();
if (appOptions.create) {
this.create(this.options);
}
}
private _updateItemsParams(item: TreeGroup | TreeLayer, webMap: WebMap, data: ResourceItem) {
if (item) {
if (item.item_type === 'group' || item.item_type === 'root') {
if (item.children) {
item.children = item.children.map(x => this._updateItemsParams(x, webMap, data));
}
if (item.item_type === 'root') {
item.display_name = data.resource.display_name;
}
} else if (item.item_type === 'layer') {
const url = fixUrlStr(this.options.baseUrl + '/api/component/render/image');
const resourceId = item.layer_style_id;
item.url = url;
item.resourceId = resourceId;
item.updateWmsParams = params => updateWmsParams(params, resourceId);
item = {
...item,
...getLayerAdapterOptions(
{
adapter: item.layer_adapter.toUpperCase() as NgwLayerAdapterType,
resourceId
},
webMap,
this.options.baseUrl
)
};
}