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] Add back removed logic copying feature properties for injected data #49400

Merged
merged 5 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('kibana.yml configured with map.tilemap.url', () => {
expect(layers).toEqual([{
alpha: 1,
__dataRequests: [],
__injectedData: null,
id: layers[0].id,
applyGlobalQuery: true,
label: null,
Expand Down Expand Up @@ -87,7 +86,6 @@ describe('EMS is enabled', () => {
expect(layers).toEqual([{
alpha: 1,
__dataRequests: [],
__injectedData: null,
id: layers[0].id,
applyGlobalQuery: true,
label: null,
Expand Down
11 changes: 0 additions & 11 deletions x-pack/legacy/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { EuiIcon, EuiLoadingSpinner } from '@elastic/eui';
import turf from 'turf';
import turfBooleanContains from '@turf/boolean-contains';
import { DataRequest } from './util/data_request';
import { InjectedData } from './util/injected_data';
import {
MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER,
SOURCE_DATA_ID_ORIGIN
Expand All @@ -32,11 +31,6 @@ export class AbstractLayer {
} else {
this._dataRequests = [];
}
if (this._descriptor.__injectedData) {
this._injectedData = new InjectedData(this._descriptor.__injectedData);
} else {
this._injectedData = null;
}
}

static getBoundDataForSource(mbMap, sourceId) {
Expand All @@ -48,7 +42,6 @@ export class AbstractLayer {
const layerDescriptor = { ...options };

layerDescriptor.__dataRequests = _.get(options, '__dataRequests', []);
layerDescriptor.__injectedData = _.get(options, '__injectedData', null);
layerDescriptor.id = _.get(options, 'id', uuid());
layerDescriptor.label = options.label && options.label.length > 0 ? options.label : null;
layerDescriptor.minZoom = _.get(options, 'minZoom', 0);
Expand Down Expand Up @@ -287,10 +280,6 @@ export class AbstractLayer {
return this._dataRequests.find(dataRequest => dataRequest.getDataId() === id);
}

getInjectedData() {
return this._injectedData ? this._injectedData.getData() : null;
}

isLayerLoading() {
return this._dataRequests.some(dataRequest => dataRequest.isLoading());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,26 @@ export class GeojsonFileSource extends AbstractVectorSource {
applyGlobalQuery: DEFAULT_APPLY_GLOBAL_QUERY
}

static createDescriptor(name) {
static createDescriptor(geoJson, name) {
// Wrap feature as feature collection if needed
let featureCollection;
if (geoJson.type === 'FeatureCollection') {
Copy link
Contributor

@nreese nreese Oct 29, 2019

Choose a reason for hiding this comment

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

Need to check that geoJson is not null here and else if statement

featureCollection = geoJson;
} else if (geoJson.type === 'Feature') {
featureCollection = {
type: 'FeatureCollection',
features: [geoJson]
};
} else { // Missing or incorrect type
featureCollection = {
type: 'FeatureCollection',
features: []
};
}

return {
type: GeojsonFileSource.type,
__featureCollection: featureCollection,
name
};
}
Expand Down Expand Up @@ -85,16 +102,9 @@ export class GeojsonFileSource extends AbstractVectorSource {
onPreviewSource(null);
return;
}
const sourceDescriptor = GeojsonFileSource.createDescriptor(name);
const sourceDescriptor = GeojsonFileSource.createDescriptor(geojsonFile, name);
const source = new GeojsonFileSource(sourceDescriptor, inspectorAdapters);
const featureCollection = (geojsonFile.type === 'Feature')
? {
type: 'FeatureCollection',
features: [{ ...geojsonFile }]
}
: geojsonFile;

onPreviewSource(source, { __injectedData: featureCollection });
onPreviewSource(source);
};
};

Expand Down Expand Up @@ -125,6 +135,22 @@ export class GeojsonFileSource extends AbstractVectorSource {
);
}

async getGeoJsonWithMeta() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a safety check here to check on the existence of __featureCollection. This source could be created by a client who's passing in a descriptor without the __featureCollection property, especially now we have embeddables (e.g. consider an embeddable-client just injecting data with a GeoJsonSource and misconfigurin the descriptor). We don't want this call to throw.

You could also enforce that there's always an empty featureCollection for the __featureCollection property in the GeoJsonFileSource#constructor .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could also enforce that there's always an empty featureCollection for the __featureCollection property in the GeoJsonFileSource#constructor .

I like that. Done!

const copiedPropsFeatures = this._descriptor.__featureCollection.features
.map(feature => ({
type: 'Feature',
geometry: feature.geometry,
properties: feature.properties ? { ...feature.properties } : {}
}));
return {
data: {
type: 'FeatureCollection',
features: copiedPropsFeatures
},
meta: {}
};
}

async getDisplayName() {
return this._descriptor.name;
}
Expand All @@ -136,8 +162,4 @@ export class GeojsonFileSource extends AbstractVectorSource {
shouldBeIndexed() {
return GeojsonFileSource.isIndexingSource;
}

isInjectedData() {
return true;
}
}
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/maps/public/layers/sources/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ export class AbstractSource {
return AbstractSource.isIndexingSource;
}

isInjectedData() {
return false;
}

supportsElasticsearchFilters() {
return false;
}
Expand Down
21 changes: 0 additions & 21 deletions x-pack/legacy/plugins/maps/public/layers/util/injected_data.js

This file was deleted.

29 changes: 2 additions & 27 deletions x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,6 @@ export class VectorLayer extends AbstractLayer {
return true;
}

getInjectedData() {
const featureCollection = super.getInjectedData();
if (!featureCollection) {
return null;
}
// Set default visible property on data
featureCollection.features.forEach(
feature => _.set(feature, `properties.${FEATURE_VISIBLE_PROPERTY_NAME}`, true)
);
return featureCollection;
}

getCustomIconAndTooltipContent() {
const featureCollection = this._getSourceFeatureCollection();

Expand Down Expand Up @@ -510,16 +498,7 @@ export class VectorLayer extends AbstractLayer {
startLoading, stopLoading, onLoadError, registerCancelCallback, dataFilters
}) {

if (this._source.isInjectedData()) {
const featureCollection = this.getInjectedData();
return {
refreshed: false,
featureCollection
};
}

const requestToken = Symbol(`layer-source-refresh:${ this.getId()} - source`);

const searchFilters = this._getSearchFilters(dataFilters);
const canSkip = await this._canSkipSourceUpdate(this._source, SOURCE_DATA_ID_ORIGIN, searchFilters);
if (canSkip) {
Expand Down Expand Up @@ -594,12 +573,8 @@ export class VectorLayer extends AbstractLayer {
}

_getSourceFeatureCollection() {
if (this._source.isInjectedData()) {
return this.getInjectedData();
} else {
const sourceDataRequest = this.getSourceDataRequest();
return sourceDataRequest ? sourceDataRequest.getData() : null;
}
const sourceDataRequest = this.getSourceDataRequest();
return sourceDataRequest ? sourceDataRequest.getData() : null;
}

_syncFeatureCollectionWithMb(mbMap) {
Expand Down