MMapTileDataSource

The MMapTileDataSource class is an object for loading tiles of raster and vector maps.
The class's main task is storing data about where to load the tiles from and how to render them.

Using an object

The class is mostly used to display tiles by a link:

const map = new MMap(element, {
  location: { center: [25.229762, 55.289311], zoom: 14},
  mode: 'vector'
});

map.addChild(
  new MMapTileDataSource({
    id: 'urlSource',
    raster: {
      type: 'tiles',
      // x and y are tile coordinates;
      // z is zoom;
      // scale is scaling for different DevicePixelRatio's.
      fetchTile: 'https://sitename.com/?x=x&y=y&z=z&scale=scale'
    }
  })
);

As an extended option, you can use an asynchronous function as the raster.fetchTile parameter that returns HTMLImageElement or HTMLCanvasElement:

const tileSize = 256;

async function fetchTile(tileX, tileY, tileZ) {
  const canvas = document.createElement('canvas');
  canvas.width = tileSize;
  canvas.height = tileSize;
  const ctx = canvas.getContext('2d');

  ctx.fillStyle = '#000000';
  ctx.fillText(`${tileX}:${tileY}:${tileZ}`, 10, 10);

  return {image: canvas};
}

map.addChild(
  new MMapTileDataSource({
    id: 'tileGeneratorSource',
    raster: {
      type: 'tiles',
      fetchTile: fetchTile,
      fetchHotspots: fetchHotspots,
      transparent: true,
      size: tileSize
    }
  })
);

Example

For example, you want to display tiles obtained from https://sitename.com on the map:

const {MMap, MMapTileDataSource, MMapLayer} = mappable;

// Initialize the map
const map = new MMap({...});

// Initialize the data source
const tileDataSource = new MMapTileDataSource({
  id: 'someSource',
  raster: {
    type: 'someType',
    fetchTile: 'https://sitename.com/?x=x&y=y&z=z&scale=scale'
  }
});

// Add the data source to the map
map.addChild(tileDataSource);

// Create a layer with the obtained data
const layer = new MMapLayer({
  zIndex: 1,
  source: 'someSource',
  type: 'someType'
});

// Add this layer to the map
map.addChild(layer);

Note

To link a data source with the layer, we use a text ID. Keep in mind that the data source ID is set in the id field, but passing it to the layer is done with the source field.

Constructor

new MMapTileDataSource(props)

Constructor parameters

Parameter

Type

Description

props

MMapTileDataSourceProps

Value of input props.

Inherited from

MMapEntity.constructor

Props

MMapTileDataSourceProps: Object

Parameters

Parameter

Type

Description

clampMapZoom?

boolean

Limit the minimum and maximum map zooms. The resulting map zoom range will match the zoom range of the map and all data sources with the clamp Map Zoom option enabled.

copyrights?

string[]

Copyright to the data sources.

id

string

Z-index of the layer.

raster?

RasterTileDataSourceDescription

Description of the source of raster data.

zoomRange?

ZoomRange

Minimum and maximum zoom for tiles.

Methods

update

update(changedProps): void

Method of updating object props.

Parameters

Parameter

Type

Description

changedProps

Partial<MMapTileDataSourceProps>

New props values.

Returns

void

Inherited from

MMapEntity.update