Skip to content

Commit

Permalink
[Maps] convert TileLayer and VectorTileLayer to TS (#117745)
Browse files Browse the repository at this point in the history
* [Maps] convert TileLayer and VectorTileLayer to TS

* commit using @elastic.co

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Nov 9, 2021
1 parent 7e4ae48 commit 7d90bad
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 102 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/classes/layers/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class AbstractLayer implements ILayer {
return null;
}

isBasemap(): boolean {
isBasemap(order: number): boolean {
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,41 @@
* 2.0.
*/

import { AbstractLayer } from '../layer';
import type { Map as MbMap } from '@kbn/mapbox-gl';
import _ from 'lodash';
import { AbstractLayer } from '../layer';
import { SOURCE_DATA_REQUEST_ID, LAYER_TYPE, LAYER_STYLE_TYPE } from '../../../../common/constants';
import { LayerDescriptor } from '../../../../common/descriptor_types';
import { TileStyle } from '../../styles/tile/tile_style';
import { ITMSSource } from '../../sources/tms_source';
import { DataRequestContext } from '../../../actions';

export interface ITileLayerArguments {
source: ITMSSource;
layerDescriptor: LayerDescriptor;
}

// TODO - rename to RasterTileLayer
export class TileLayer extends AbstractLayer {
static createDescriptor(options, mapColors) {
const tileLayerDescriptor = super.createDescriptor(options, mapColors);
static createDescriptor(options: Partial<LayerDescriptor>) {
const tileLayerDescriptor = super.createDescriptor(options);
tileLayerDescriptor.type = LAYER_TYPE.TILE;
tileLayerDescriptor.alpha = _.get(options, 'alpha', 1);
tileLayerDescriptor.style = { type: LAYER_STYLE_TYPE.TILE };
return tileLayerDescriptor;
}

constructor({ source, layerDescriptor }) {
private readonly _style: TileStyle;

constructor({ source, layerDescriptor }: ITileLayerArguments) {
super({ source, layerDescriptor });
this._style = new TileStyle();
}

getSource(): ITMSSource {
return super.getSource() as ITMSSource;
}

getStyleForEditing() {
return this._style;
}
Expand All @@ -36,10 +52,10 @@ export class TileLayer extends AbstractLayer {
return this._style;
}

async syncData({ startLoading, stopLoading, onLoadError, dataFilters }) {
async syncData({ startLoading, stopLoading, onLoadError, dataFilters }: DataRequestContext) {
const sourceDataRequest = this.getSourceDataRequest();
if (sourceDataRequest) {
//data is immmutable
// data is immmutable
return;
}
const requestToken = Symbol(`layer-source-refresh:${this.getId()} - source`);
Expand All @@ -60,28 +76,28 @@ export class TileLayer extends AbstractLayer {
return [this._getMbLayerId()];
}

ownsMbLayerId(mbLayerId) {
ownsMbLayerId(mbLayerId: string) {
return this._getMbLayerId() === mbLayerId;
}

ownsMbSourceId(mbSourceId) {
ownsMbSourceId(mbSourceId: string) {
return this.getId() === mbSourceId;
}

syncLayerWithMB(mbMap) {
syncLayerWithMB(mbMap: MbMap) {
const source = mbMap.getSource(this.getId());
const mbLayerId = this._getMbLayerId();

if (!source) {
const sourceDataRequest = this.getSourceDataRequest();
if (!sourceDataRequest) {
//this is possible if the layer was invisible at startup.
//the actions will not perform any data=syncing as an optimization when a layer is invisible
//when turning the layer back into visible, it's possible the url has not been resovled yet.
// this is possible if the layer was invisible at startup.
// the actions will not perform any data=syncing as an optimization when a layer is invisible
// when turning the layer back into visible, it's possible the url has not been resovled yet.
return;
}

const tmsSourceData = sourceDataRequest.getData();
const tmsSourceData = sourceDataRequest.getData() as { url?: string };
if (!tmsSourceData || !tmsSourceData.url) {
return;
}
Expand All @@ -106,17 +122,17 @@ export class TileLayer extends AbstractLayer {
this._setTileLayerProperties(mbMap, mbLayerId);
}

_setTileLayerProperties(mbMap, mbLayerId) {
_setTileLayerProperties(mbMap: MbMap, mbLayerId: string) {
this.syncVisibilityWithMb(mbMap, mbLayerId);
mbMap.setLayerZoomRange(mbLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
mbMap.setLayerZoomRange(mbLayerId, this.getMinZoom(), this.getMaxZoom());
mbMap.setPaintProperty(mbLayerId, 'raster-opacity', this.getAlpha());
}

getLayerTypeIconName() {
return 'grid';
}

isBasemap(order) {
isBasemap(order: number) {
return order === 0;
}
}

This file was deleted.

Loading

0 comments on commit 7d90bad

Please sign in to comment.