Skip to content

Commit

Permalink
Fix custom raster developer example (#142664)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpeihl authored Oct 4, 2022
1 parent 7f3541c commit fc8407d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import _ from 'lodash';
import { ReactElement } from 'react';
import { calculateBounds } from '@kbn/data-plugin/common';
import { FieldFormatter, MIN_ZOOM, MAX_ZOOM } from '@kbn/maps-plugin/common';
Expand All @@ -16,15 +17,18 @@ import type {
Timeslice,
} from '@kbn/maps-plugin/common/descriptor_types';
import type {
DataRequest,
IField,
ImmutableSourceProperty,
ITMSSource,
IRasterSource,
SourceEditorArgs,
} from '@kbn/maps-plugin/public';
import { RasterTileSourceData } from '@kbn/maps-plugin/public/classes/sources/raster_source';
import { RasterTileSource } from 'maplibre-gl';

type CustomRasterSourceDescriptor = AbstractSourceDescriptor;

export class CustomRasterSource implements ITMSSource {
export class CustomRasterSource implements IRasterSource {
static type = 'CUSTOM_RASTER';

readonly _descriptor: CustomRasterSourceDescriptor;
Expand All @@ -39,6 +43,25 @@ export class CustomRasterSource implements ITMSSource {
this._descriptor = sourceDescriptor;
}

async canSkipSourceUpdate(
dataRequest: DataRequest,
nextRequestMeta: DataRequestMeta
): Promise<boolean> {
const prevMeta = dataRequest.getMeta();
if (!prevMeta) {
return Promise.resolve(false);
}

return Promise.resolve(_.isEqual(prevMeta.timeslice, nextRequestMeta.timeslice));
}

isSourceStale(mbSource: RasterTileSource, sourceData: RasterTileSourceData): boolean {
if (!sourceData.url) {
return false;
}
return mbSource.tiles?.[0] !== sourceData.url;
}

cloneDescriptor(): CustomRasterSourceDescriptor {
return {
type: this._descriptor.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ export class KibanaTilemapSource extends AbstractSource {
},
];
}

isSourceStale(mbSource, sourceData) {
if (!sourceData.url) {
return false;
}
return mbSource.tiles?.[0] !== sourceData.url;
}

async canSkipSourceUpdate() {
return false;
}

async getUrlTemplate() {
const tilemap = getKibanaTileMap();
if (!tilemap.url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export class WMSSource extends AbstractSource {
styles,
};
}

isSourceStale(mbSource, sourceData) {
if (!sourceData.url) {
return false;
}
return mbSource.tiles?.[0] !== sourceData.url;
}

async canSkipSourceUpdate() {
return false;
}

async getImmutableProperties() {
return [
{ label: getDataSourceLabel(), value: sourceTitle },
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/maps/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type { MapEmbeddable, MapEmbeddableInput, MapEmbeddableOutput } from './e
export type { EMSTermJoinConfig, SampleValuesConfig } from './ems_autosuggest';

export type { ITMSSource } from './classes/sources/tms_source';
export type { IRasterSource } from './classes/sources/raster_source';

export type {
GetFeatureActionsArgs,
Expand Down

0 comments on commit fc8407d

Please sign in to comment.