Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] Fit only on visible features #42020

Merged
merged 2 commits into from Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Expand Up @@ -196,7 +196,12 @@ export class VectorLayer extends AbstractLayer {
if (!featureCollection) {
return null;
}
const bbox = turf.bbox(featureCollection);

const visibleFeatures = featureCollection.features.filter(feature => feature.properties[FEATURE_VISIBLE_PROPERTY_NAME]);
const bbox = turf.bbox({
type: 'FeatureCollection',
features: visibleFeatures
});
return {
min_lon: bbox[0],
min_lat: bbox[1],
Expand All @@ -206,11 +211,14 @@ export class VectorLayer extends AbstractLayer {
}

async getBounds(dataFilters) {
if (this._source.isBoundsAware()) {
const searchFilters = this._getSearchFilters(dataFilters);
return await this._source.getBoundsForFilters(searchFilters);

const isStaticLayer = !this._source.isBoundsAware() || !this._source.isFilterByMapBounds();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now will only ignore visibility of features for sources that are bounds aware (ie. we can actually query for the entire bounds), and which are filtered based on extent.

E.g. Fit will take into account visibility for an es-doc source layer with all data in the view

if (isStaticLayer) {
return this._getBoundsBasedOnData();
}
return this._getBoundsBasedOnData();

const searchFilters = this._getSearchFilters(dataFilters);
return await this._source.getBoundsForFilters(searchFilters);
}

async getLeftJoinFields() {
Expand Down