-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] EMS baselayer should load cleanly (#88531)
- Loading branch information
1 parent
90f2abd
commit 66c0cc2
Showing
7 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/maps/public/classes/layers/vector_tile_layer/vector_tile_layer.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ITileLayerArguments, TileLayer } from '../tile_layer/tile_layer'; | ||
|
||
export class VectorTileLayer extends TileLayer { | ||
static type: string; | ||
constructor(args: ITileLayerArguments); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/maps/public/classes/layers/vector_tile_layer/vector_tile_layer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ITileLayerArguments } from '../tile_layer/tile_layer'; | ||
import { SOURCE_TYPES } from '../../../../common/constants'; | ||
import { MapFilters, XYZTMSSourceDescriptor } from '../../../../common/descriptor_types'; | ||
import { ITMSSource, AbstractTMSSource } from '../../sources/tms_source'; | ||
import { ILayer } from '../layer'; | ||
import { VectorTileLayer } from './vector_tile_layer'; | ||
import { DataRequestContext } from '../../../actions'; | ||
|
||
const sourceDescriptor: XYZTMSSourceDescriptor = { | ||
type: SOURCE_TYPES.EMS_XYZ, | ||
urlTemplate: 'https://example.com/{x}/{y}/{z}.png', | ||
id: 'mockSourceId', | ||
}; | ||
|
||
class MockTileSource extends AbstractTMSSource implements ITMSSource { | ||
readonly _descriptor: XYZTMSSourceDescriptor; | ||
constructor(descriptor: XYZTMSSourceDescriptor) { | ||
super(descriptor, {}); | ||
this._descriptor = descriptor; | ||
} | ||
|
||
async getDisplayName(): Promise<string> { | ||
return this._descriptor.urlTemplate; | ||
} | ||
|
||
async getUrlTemplate(): Promise<string> { | ||
return 'template/{x}/{y}/{z}.png'; | ||
} | ||
|
||
getTileLayerId() { | ||
return this._descriptor.id; | ||
} | ||
|
||
getVectorStyleSheetAndSpriteMeta() { | ||
throw new Error('network error'); | ||
} | ||
} | ||
|
||
describe('VectorTileLayer', () => { | ||
it('should correctly inject tileLayerId in meta', async () => { | ||
const source = new MockTileSource(sourceDescriptor); | ||
|
||
const args: ITileLayerArguments = { | ||
source, | ||
layerDescriptor: { id: 'layerid', sourceDescriptor }, | ||
}; | ||
|
||
const layer: ILayer = new VectorTileLayer(args); | ||
|
||
let actualMeta; | ||
let actualErrorMessage; | ||
const mockContext = ({ | ||
startLoading: (requestId: string, token: string, meta: unknown) => { | ||
actualMeta = meta; | ||
}, | ||
onLoadError: (requestId: string, token: string, message: string) => { | ||
actualErrorMessage = message; | ||
}, | ||
dataFilters: ({ foo: 'bar' } as unknown) as MapFilters, | ||
} as unknown) as DataRequestContext; | ||
|
||
await layer.syncData(mockContext); | ||
|
||
expect(actualMeta).toStrictEqual({ tileLayerId: 'mockSourceId' }); | ||
expect(actualErrorMessage).toStrictEqual('network error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters