Skip to content

Commit

Permalink
Set default visibility to true on injected data
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Oct 1, 2019
1 parent 7d62eb5 commit 778c3f2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ 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 } from '../../common/constants';
import {
MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER,
SOURCE_DATA_ID_ORIGIN
} from '../../common/constants';
import uuid from 'uuid/v4';
import { copyPersistentState } from '../reducers/util';
import { i18n } from '@kbn/i18n';
Expand Down
49 changes: 38 additions & 11 deletions x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,21 @@ export class VectorLayer extends AbstractLayer {
return true;
}

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

This comment has been minimized.

Copy link
@nreese

nreese Oct 2, 2019

Contributor

no need for else statement. Can just return null. Could move this to the top since is the anit-flow

if (!featureCollection) {
return null;
}

// set visibility prop to true
return null;
}
}

getCustomIconAndTooltipContent() {
const sourceDataRequest = this.getSourceDataRequest();
const featureCollection = sourceDataRequest ? sourceDataRequest.getData() : null;
const featureCollection = this._getSourceFeatureCollection();

const noResultsIcon = (
<EuiIcon
Expand All @@ -145,9 +157,10 @@ export class VectorLayer extends AbstractLayer {
if (!featureCollection || featureCollection.features.length === 0) {
return {
icon: noResultsIcon,
tooltipContent: i18n.translate('xpack.maps.vectorLayer.noResultsFoundTooltip', {
defaultMessage: `No results found.`
})
tooltipContent: i18n.translate(
'xpack.maps.vectorLayer.noResultsFoundTooltip', {
defaultMessage: `No results found.`
})
};
}

Expand All @@ -162,7 +175,7 @@ export class VectorLayer extends AbstractLayer {
};
}


const sourceDataRequest = this.getSourceDataRequest();
const { tooltipContent, areResultsTrimmed } = this._source.getSourceTooltipContent(sourceDataRequest);
return {
icon: this._style.getIcon(),
Expand Down Expand Up @@ -464,7 +477,17 @@ export class VectorLayer extends AbstractLayer {
}
}

async _syncSource({ startLoading, stopLoading, onLoadError, registerCancelCallback, dataFilters }) {
async _syncSource({
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`);

Expand All @@ -481,8 +504,8 @@ export class VectorLayer extends AbstractLayer {
try {
startLoading(SOURCE_DATA_ID_ORIGIN, requestToken, searchFilters);
const layerName = await this.getDisplayName();
const { data: featureCollection, meta } = this._source.isPushedData()
? { data: this.getPushedData(), meta: {} }
const { data: featureCollection, meta } = this._source.isInjectedData()
? { data: this.getInjectedData(), meta: {} }
: await this._source.getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback.bind(null, requestToken));
this._assignIdsToFeatures(featureCollection);
stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, featureCollection, meta);
Expand Down Expand Up @@ -543,8 +566,12 @@ export class VectorLayer extends AbstractLayer {
}

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

_syncFeatureCollectionWithMb(mbMap) {
Expand Down

0 comments on commit 778c3f2

Please sign in to comment.