forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] labels for polygons and lines (elastic#86191)
* [Maps] labels for polygons and lines * remove x-pack yarn.lock * add labels to choropleth map wizard * clean up comment * add mvt tile support * only add centroids if there may be lines or polygons * tslint * tslint * do not add centroid to too many features polygon * update get_tile expect statements * move turf dependencies from devDependencies to dependencies * update jest snapshot and functional test expects * fix functional test expect * another functional test expect update * functional test updates * expect * pew pew source expect updates * update joins expect * update mapbox style expects * update join visibility expects for geocentroids * update join visibility expects for geocentroids * another functional test expect update * review feedback * update yarn.lock * tslint Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
cf45a92
commit 2fba041
Showing
19 changed files
with
1,098 additions
and
38 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
282 changes: 282 additions & 0 deletions
282
x-pack/plugins/maps/common/get_centroid_features.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,282 @@ | ||
/* | ||
* 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 { Feature, FeatureCollection } from 'geojson'; | ||
import { getCentroidFeatures } from './get_centroid_features'; | ||
|
||
test('should not create centroid feature for point and multipoint', () => { | ||
const pointFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [30, 10], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const multiPointFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'MultiPoint', | ||
coordinates: [ | ||
[10, 40], | ||
[40, 30], | ||
[20, 20], | ||
[30, 10], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [pointFeature, multiPointFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(0); | ||
}); | ||
|
||
test('should not create centroid for too many features polygon', () => { | ||
const polygonFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Polygon', | ||
coordinates: [ | ||
[ | ||
[35, 10], | ||
[45, 45], | ||
[15, 40], | ||
[10, 20], | ||
[35, 10], | ||
], | ||
], | ||
}, | ||
properties: { | ||
__kbn_too_many_features__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [polygonFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(0); | ||
}); | ||
|
||
test('should create centroid feature for line (even number of points)', () => { | ||
const lineFeature: Feature = { | ||
type: 'Feature', | ||
id: 'myfeature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [lineFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(1); | ||
expect(centroidFeatures[0]).toEqual({ | ||
type: 'Feature', | ||
id: 'myfeature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [103.50003808007737, 0.5000190382261022], | ||
}, | ||
properties: { | ||
__kbn_is_centroid_feature__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should create centroid feature for line (odd number of points)', () => { | ||
const lineFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [lineFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(1); | ||
expect(centroidFeatures[0]).toEqual({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [103.0, 1.0], | ||
}, | ||
properties: { | ||
__kbn_is_centroid_feature__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should create centroid feature for multi line', () => { | ||
const multiLineFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'MultiLineString', | ||
coordinates: [ | ||
[ | ||
[10, 10], | ||
[20, 20], | ||
[10, 40], | ||
], | ||
[ | ||
[40, 40], | ||
[30, 30], | ||
[40, 20], | ||
[30, 10], | ||
], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [multiLineFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(1); | ||
expect(centroidFeatures[0]).toEqual({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [35.56701982106548, 24.717594944805672], | ||
}, | ||
properties: { | ||
__kbn_is_centroid_feature__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should create centroid feature for polygon', () => { | ||
const polygonFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Polygon', | ||
coordinates: [ | ||
[ | ||
[35, 10], | ||
[45, 45], | ||
[15, 40], | ||
[10, 20], | ||
[35, 10], | ||
], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [polygonFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(1); | ||
expect(centroidFeatures[0]).toEqual({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [27.526881720430108, 28.70967741935484], | ||
}, | ||
properties: { | ||
__kbn_is_centroid_feature__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should create centroid feature for multi polygon', () => { | ||
const multiPolygonFeature: Feature = { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'MultiPolygon', | ||
coordinates: [ | ||
[ | ||
[ | ||
[30, 20], | ||
[45, 40], | ||
[10, 40], | ||
[30, 20], | ||
], | ||
], | ||
[ | ||
[ | ||
[15, 5], | ||
[40, 10], | ||
[10, 20], | ||
[5, 10], | ||
[15, 5], | ||
], | ||
], | ||
], | ||
}, | ||
properties: { | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}; | ||
const featureCollection: FeatureCollection = { | ||
type: 'FeatureCollection', | ||
features: [multiPolygonFeature], | ||
}; | ||
const centroidFeatures = getCentroidFeatures(featureCollection); | ||
expect(centroidFeatures.length).toBe(1); | ||
expect(centroidFeatures[0]).toEqual({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [28.333333333333332, 33.333333333333336], | ||
}, | ||
properties: { | ||
__kbn_is_centroid_feature__: true, | ||
prop0: 'value0', | ||
prop1: 0.0, | ||
}, | ||
}); | ||
}); |
Oops, something went wrong.