Skip to content

Commit

Permalink
[maps] allow feature editing with vector tile scaling (#123409)
Browse files Browse the repository at this point in the history
* [maps] allow feature editing with vector tile scaling

* eslint

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
nreese and kibanamachine authored Feb 1, 2022
1 parent fd82fea commit 111b830
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import { syncGeojsonSourceData } from './geojson_source_data';
import { JoinState, performInnerJoins } from './perform_inner_joins';
import { buildVectorRequestMeta } from '../../build_vector_request_meta';

export const SUPPORTS_FEATURE_EDITING_REQUEST_ID = 'SUPPORTS_FEATURE_EDITING_REQUEST_ID';

export class GeoJsonVectorLayer extends AbstractVectorLayer {
static createDescriptor(
options: Partial<VectorLayerDescriptor>,
Expand All @@ -65,12 +63,6 @@ export class GeoJsonVectorLayer extends AbstractVectorLayer {
return layerDescriptor;
}

supportsFeatureEditing(): boolean {
const dataRequest = this.getDataRequest(SUPPORTS_FEATURE_EDITING_REQUEST_ID);
const data = dataRequest?.getData() as { supportsFeatureEditing: boolean } | undefined;
return data ? data.supportsFeatureEditing : false;
}

async getBounds(syncContext: DataRequestContext) {
const isStaticLayer = !this.getSource().isBoundsAware();
return isStaticLayer || this.hasJoins()
Expand Down Expand Up @@ -380,33 +372,6 @@ export class GeoJsonVectorLayer extends AbstractVectorLayer {
});
}

async _syncSupportsFeatureEditing({
syncContext,
source,
}: {
syncContext: DataRequestContext;
source: IVectorSource;
}) {
if (syncContext.dataFilters.isReadOnly) {
return;
}
const { startLoading, stopLoading, onLoadError } = syncContext;
const dataRequestId = SUPPORTS_FEATURE_EDITING_REQUEST_ID;
const requestToken = Symbol(`layer-${this.getId()}-${dataRequestId}`);
const prevDataRequest = this.getDataRequest(dataRequestId);
if (prevDataRequest) {
return;
}
try {
startLoading(dataRequestId, requestToken);
const supportsFeatureEditing = await source.supportsFeatureEditing();
stopLoading(dataRequestId, requestToken, { supportsFeatureEditing });
} catch (error) {
onLoadError(dataRequestId, requestToken, error.message);
throw error;
}
}

_getSourceFeatureCollection() {
const sourceDataRequest = this.getSourceDataRequest();
return sourceDataRequest ? (sourceDataRequest.getData() as FeatureCollection) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,47 @@ describe('syncMvtSourceData', () => {
sinon.assert.notCalled(syncContext.stopLoading);
});

test('Should re-sync with forceRefreshDueToDrawing when there are no changes in source state or search state', async () => {
const syncContext = {
...new MockSyncContext({ dataFilters: {} }),
forceRefreshDueToDrawing: true,
};
const prevRequestMeta = {
...syncContext.dataFilters,
applyGlobalQuery: true,
applyGlobalTime: true,
applyForceRefresh: true,
fieldNames: [],
sourceMeta: {},
isForceRefresh: false,
};

await syncMvtSourceData({
layerId: 'layer1',
prevDataRequest: {
getMeta: () => {
return prevRequestMeta;
},
getData: () => {
return {
tileMinZoom: 4,
tileMaxZoom: 14,
tileSourceLayer: 'aggs',
tileUrl: 'https://example.com/{x}/{y}/{z}.pbf?token=12345',
refreshToken: '12345',
};
},
} as unknown as DataRequest,
requestMeta: { ...prevRequestMeta },
source: mockSource,
syncContext,
});
// @ts-expect-error
sinon.assert.calledOnce(syncContext.startLoading);
// @ts-expect-error
sinon.assert.calledOnce(syncContext.stopLoading);
});

test('Should re-sync when there are changes to search state', async () => {
const syncContext = new MockSyncContext({ dataFilters: {} });
const prevRequestMeta = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export async function syncMvtSourceData({
return true;
},
});
const canSkip = noChangesInSourceState && noChangesInSearchState;
const canSkip =
!syncContext.forceRefreshDueToDrawing && noChangesInSourceState && noChangesInSearchState;

if (canSkip) {
return;
Expand All @@ -63,7 +64,9 @@ export async function syncMvtSourceData({
syncContext.startLoading(SOURCE_DATA_REQUEST_ID, requestToken, requestMeta);
try {
const refreshToken =
!prevData || (requestMeta.isForceRefresh && requestMeta.applyForceRefresh)
!prevData ||
syncContext.forceRefreshDueToDrawing ||
(requestMeta.isForceRefresh && requestMeta.applyForceRefresh)
? uuid()
: prevData.refreshToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export class MvtVectorLayer extends AbstractVectorLayer {
}
await this._syncSourceStyleMeta(syncContext, this.getSource(), this.getCurrentStyle());
await this._syncSourceFormatters(syncContext, this.getSource(), this.getCurrentStyle());
await this._syncSupportsFeatureEditing({ syncContext, source: this.getSource() });

await syncMvtSourceData({
layerId: this.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import { buildVectorRequestMeta } from '../build_vector_request_meta';
import { getJoinAggKey } from '../../../../common/get_agg_key';
import { syncBoundsData } from './bounds_data';

const SUPPORTS_FEATURE_EDITING_REQUEST_ID = 'SUPPORTS_FEATURE_EDITING_REQUEST_ID';

export function isVectorLayer(layer: ILayer) {
return (layer as IVectorLayer).canShowTooltip !== undefined;
}
Expand Down Expand Up @@ -242,7 +244,9 @@ export class AbstractVectorLayer extends AbstractLayer implements IVectorLayer {
}

supportsFeatureEditing(): boolean {
return false;
const dataRequest = this.getDataRequest(SUPPORTS_FEATURE_EDITING_REQUEST_ID);
const data = dataRequest?.getData() as { supportsFeatureEditing: boolean } | undefined;
return data ? data.supportsFeatureEditing : false;
}

hasJoins() {
Expand Down Expand Up @@ -522,6 +526,33 @@ export class AbstractVectorLayer extends AbstractLayer implements IVectorLayer {
}
}

async _syncSupportsFeatureEditing({
syncContext,
source,
}: {
syncContext: DataRequestContext;
source: IVectorSource;
}) {
if (syncContext.dataFilters.isReadOnly) {
return;
}
const { startLoading, stopLoading, onLoadError } = syncContext;
const dataRequestId = SUPPORTS_FEATURE_EDITING_REQUEST_ID;
const requestToken = Symbol(`layer-${this.getId()}-${dataRequestId}`);
const prevDataRequest = this.getDataRequest(dataRequestId);
if (prevDataRequest) {
return;
}
try {
startLoading(dataRequestId, requestToken);
const supportsFeatureEditing = await source.supportsFeatureEditing();
stopLoading(dataRequestId, requestToken, { supportsFeatureEditing });
} catch (error) {
onLoadError(dataRequestId, requestToken, error.message);
throw error;
}
}

_setMbPointsProperties(
mbMap: MbMap,
mvtSourceLayer?: string,
Expand Down

0 comments on commit 111b830

Please sign in to comment.