From 41fa2ef786750b1ce222e25a8f0aea3b0aee6a74 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 26 Sep 2019 11:19:29 -0600 Subject: [PATCH] merge conflicts (#46504) --- .../map/feature_geometry_filter_form.js | 8 +++--- .../map/feature_tooltip.js | 26 +++++++++++-------- .../map/feature_tooltip.test.js | 22 +++++----------- .../connected_components/map/mb/view.js | 17 +++++++++++- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_geometry_filter_form.js b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_geometry_filter_form.js index 4b26db917b39e..03ed8bb48eddd 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_geometry_filter_form.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_geometry_filter_form.js @@ -26,7 +26,7 @@ export class FeatureGeometryFilterForm extends Component { _createFilter = ({ geometryLabel, indexPatternId, geoFieldName, geoFieldType, relation }) => { const filter = createSpatialFilterWithGeometry({ - geometry: this.props.feature.geometry, + geometry: this.props.geometry, geometryLabel, indexPatternId, geoFieldName, @@ -69,10 +69,10 @@ export class FeatureGeometryFilterForm extends Component { defaultMessage: 'Create filter' })} geoFields={this.props.geoFields} - intitialGeometryLabel={this.props.feature.geometry.type.toLowerCase()} + intitialGeometryLabel={this.props.geometry.type.toLowerCase()} onSubmit={this._createFilter} - isFilterGeometryClosed={this.props.feature.geometry.type !== GEO_JSON_TYPE.LINE_STRING - && this.props.feature.geometry.type !== GEO_JSON_TYPE.MULTI_LINE_STRING} + isFilterGeometryClosed={this.props.geometry.type !== GEO_JSON_TYPE.LINE_STRING + && this.props.geometry.type !== GEO_JSON_TYPE.MULTI_LINE_STRING} /> ); } diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.js b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.js index 6546722f1d0ce..24650268a0d96 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.js @@ -159,7 +159,7 @@ export class FeatureTooltip extends React.Component { ); } - _renderActions(feature, geoFields) { + _renderActions(geoFields) { if (!this.props.isLocked || geoFields.length === 0) { return null; } @@ -270,22 +270,22 @@ export class FeatureTooltip extends React.Component { }); } - _filterGeoFields(feature) { - if (!feature) { + _filterGeoFields(featureGeometry) { + if (!featureGeometry) { return []; } // line geometry can only create filters for geo_shape fields. - if (feature.geometry.type === GEO_JSON_TYPE.LINE_STRING - || feature.geometry.type === GEO_JSON_TYPE.MULTI_LINE_STRING) { + if (featureGeometry.type === GEO_JSON_TYPE.LINE_STRING + || featureGeometry.type === GEO_JSON_TYPE.MULTI_LINE_STRING) { return this.props.geoFields.filter(({ geoFieldType }) => { return geoFieldType === ES_GEO_FIELD_TYPE.GEO_SHAPE; }); } // TODO support geo distance filters for points - if (feature.geometry.type === GEO_JSON_TYPE.POINT - || feature.geometry.type === GEO_JSON_TYPE.MULTI_POINT) { + if (featureGeometry.type === GEO_JSON_TYPE.POINT + || featureGeometry.type === GEO_JSON_TYPE.MULTI_POINT) { return []; } @@ -342,14 +342,18 @@ export class FeatureTooltip extends React.Component { render() { const filteredFeatures = this._filterFeatures(); const currentFeature = filteredFeatures[this.state.pageNumber]; - const filteredGeoFields = this._filterGeoFields(currentFeature); + const currentFeatureGeometry = this.props.loadFeatureGeometry({ + layerId: currentFeature.layerId, + featureId: currentFeature.id + }); + const filteredGeoFields = this._filterGeoFields(currentFeatureGeometry); - if (this.state.view === VIEWS.GEOMETRY_FILTER_VIEW) { + if (this.state.view === VIEWS.GEOMETRY_FILTER_VIEW && currentFeatureGeometry) { return ( {this._renderHeader()} {this._renderProperties(currentFeature)} - {this._renderActions(currentFeature, filteredGeoFields)} + {this._renderActions(filteredGeoFields)} {this._renderFooter(filteredFeatures)} ); diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.test.js b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.test.js index 9dc0d7165b1f0..626d3b360047e 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.test.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/feature_tooltip.test.js @@ -21,26 +21,14 @@ const MULTI_FEATURE_MULTI_LAYER = [ { id: 'feature1', layerId: 'layer1', - geometry: { - type: 'Point', - coordinates: [102.0, 0.5] - } }, { id: 'feature2', layerId: 'layer1', - geometry: { - type: 'Point', - coordinates: [102.0, 0.5] - } }, { id: 'feature1', layerId: 'layer2', - geometry: { - type: 'Point', - coordinates: [102.0, 0.5] - } } ]; @@ -48,15 +36,17 @@ const SINGLE_FEATURE = [ { id: 'feature1', layerId: 'layer1', - geometry: { - type: 'Point', - coordinates: [102.0, 0.5] - } } ]; const defaultProps = { loadFeatureProperties: () => { return []; }, + loadFeatureGeometry: () => { + return { + type: 'Point', + coordinates: [102.0, 0.5] + }; + }, findLayerById: (id) => { return new MockLayer(id); }, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js index 99100111f84f2..981cf2f41abe1 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js @@ -158,7 +158,6 @@ export class MBMapContainer extends React.Component { uniqueFeatures.push({ id: featureId, layerId: layerId, - geometry: mbFeature.geometry, }); } } @@ -497,6 +496,7 @@ export class MBMapContainer extends React.Component { addFilters={this.props.addFilters} geoFields={this.props.geoFields} reevaluateTooltipPosition={this._reevaluateTooltipPosition} + loadFeatureGeometry={this._loadFeatureGeometry} /> ), this._tooltipContainer); @@ -506,6 +506,21 @@ export class MBMapContainer extends React.Component { .addTo(this._mbMap); } + // Must load original geometry instead of using geometry from mapbox feature. + // Mapbox feature geometry is from vector tile and is not the same as the original geometry. + _loadFeatureGeometry = ({ layerId, featureId }) => { + const tooltipLayer = this._findLayerById(layerId); + if (!tooltipLayer) { + return null; + } + const targetFeature = tooltipLayer.getFeatureById(featureId); + if (!targetFeature) { + return null; + } + + return targetFeature.geometry; + }; + _loadFeatureProperties = async ({ layerId, featureId }) => { const tooltipLayer = this._findLayerById(layerId); if (!tooltipLayer) {