-
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] Implement fields and bounds retrieval on GeoJsonFileSource (#8…
- Loading branch information
1 parent
1f644e4
commit 0076384
Showing
7 changed files
with
240 additions
and
23 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
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/maps/public/classes/fields/geojson_file_field.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,43 @@ | ||
/* | ||
* 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 { FIELD_ORIGIN } from '../../../common/constants'; | ||
import { IField, AbstractField } from './field'; | ||
import { IVectorSource } from '../sources/vector_source'; | ||
import { GeoJsonFileSource } from '../sources/geojson_file_source'; | ||
|
||
export class GeoJsonFileField extends AbstractField implements IField { | ||
private readonly _source: GeoJsonFileSource; | ||
private readonly _dataType: string; | ||
|
||
constructor({ | ||
fieldName, | ||
source, | ||
origin, | ||
dataType, | ||
}: { | ||
fieldName: string; | ||
source: GeoJsonFileSource; | ||
origin: FIELD_ORIGIN; | ||
dataType: string; | ||
}) { | ||
super({ fieldName, origin }); | ||
this._source = source; | ||
this._dataType = dataType; | ||
} | ||
|
||
getSource(): IVectorSource { | ||
return this._source; | ||
} | ||
|
||
async getLabel(): Promise<string> { | ||
return this.getName(); | ||
} | ||
|
||
async getDataType(): Promise<string> { | ||
return this._dataType; | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file.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,105 @@ | ||
/* | ||
* 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 { GeoJsonFileSource } from './geojson_file_source'; | ||
import { BoundsFilters } from '../vector_source'; | ||
import { FIELD_ORIGIN } from '../../../../common/constants'; | ||
|
||
describe('GeoJsonFileSource', () => { | ||
describe('getName', () => { | ||
it('should get default display name', async () => { | ||
const geojsonFileSource = new GeoJsonFileSource({}); | ||
expect(await geojsonFileSource.getDisplayName()).toBe('Features'); | ||
}); | ||
}); | ||
describe('getBounds', () => { | ||
it('should get null bounds', async () => { | ||
const geojsonFileSource = new GeoJsonFileSource({}); | ||
expect( | ||
await geojsonFileSource.getBoundsForFilters(({} as unknown) as BoundsFilters, () => {}) | ||
).toEqual(null); | ||
}); | ||
|
||
it('should get bounds from feature collection', async () => { | ||
const geojsonFileSource = new GeoJsonFileSource({ | ||
__featureCollection: { | ||
type: 'FeatureCollection', | ||
features: [ | ||
{ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [0, 1], | ||
}, | ||
properties: {}, | ||
}, | ||
{ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [2, 3], | ||
}, | ||
properties: {}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
expect(geojsonFileSource.isBoundsAware()).toBe(true); | ||
expect( | ||
await geojsonFileSource.getBoundsForFilters(({} as unknown) as BoundsFilters, () => {}) | ||
).toEqual({ | ||
maxLat: 3, | ||
maxLon: 2, | ||
minLat: 1, | ||
minLon: 0, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getFields', () => { | ||
it('should get fields from config', async () => { | ||
const geojsonFileSource = new GeoJsonFileSource({ | ||
__fields: [ | ||
{ | ||
type: 'string', | ||
name: 'foo', | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'bar', | ||
}, | ||
], | ||
}); | ||
|
||
const fields = await geojsonFileSource.getFields(); | ||
|
||
const actualFields = fields.map(async (field) => { | ||
return { | ||
dataType: await field.getDataType(), | ||
origin: field.getOrigin(), | ||
name: field.getName(), | ||
source: field.getSource(), | ||
}; | ||
}); | ||
|
||
expect(await Promise.all(actualFields)).toEqual([ | ||
{ | ||
dataType: 'string', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
source: geojsonFileSource, | ||
name: 'foo', | ||
}, | ||
{ | ||
dataType: 'number', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
source: geojsonFileSource, | ||
name: 'bar', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
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