Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Oct 8, 2023
1 parent 647b456 commit 37697d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions modules/mvt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type {TileJSON} from './lib/parse-tilejson';
export type {TileJSONLoaderOptions} from './tilejson-loader';
export {TileJSONLoader} from './tilejson-loader';

export {MVTSource} from './mvt-source';

// GeoJSONTiler

export type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MVTLoader, MVTLoaderOptions, TileJSONLoader, TileJSON} from '@loaders.gl

import {TileLoadParameters} from '@loaders.gl/loader-utils';

export type MVTTilesSourceProps = DataSourceProps & {
export type MVTSourceProps = DataSourceProps & {
url: string;
attributions?: string[];
};
Expand All @@ -17,13 +17,13 @@ export type MVTTilesSourceProps = DataSourceProps & {
* A PMTiles data source
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
*/
export class MVTTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
props: MVTTilesSourceProps;
export class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {
props: MVTSourceProps;
url: string;
schema: 'tms' | 'xyz' = 'tms';
metadata: Promise<TileJSON | null>;

constructor(props: MVTTilesSourceProps) {
constructor(props: MVTSourceProps) {
super(props);
this.props = props;
this.url = resolvePath(props.url);
Expand All @@ -33,12 +33,12 @@ export class MVTTilesSource extends DataSource implements ImageTileSource, Vecto

// @ts-ignore - Metadata type misalignment
async getMetadata(): Promise<TileJSON | null> {
const metadataUrl = this.getMetadataUrl();
const metadataUrl = this.getMetadataUrl();
const response = await this.fetch(metadataUrl);
if (!response.ok) {
return null;
}
const tileJSON = await response.text()
const tileJSON = await response.text();
const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;
// metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];
return metadata;
Expand Down
2 changes: 1 addition & 1 deletion modules/mvt/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './mvt-loader.spec';

import './tilejson-loader.spec';

import './mvt-tiles-source.spec';
import './mvt-source.spec';

// geojson-vt
import './lib/geojson-tiler';
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import test from 'tape-promise/tape';
import {isBrowser} from '@loaders.gl/core';

import {TILESETS} from './data/tilesets';
import {MVTTilesSource} from '@loaders.gl/mvt';
import {MVTSource} from '@loaders.gl/mvt';

test('MVTTilesSource#urls', async (t) => {
test('MVTSource#urls', async (t) => {
if (!isBrowser) {
t.comment('MVTTilesSource currently only supported in browser');
t.comment('MVTSource currently only supported in browser');
t.end();
return;
}
for (const tilesetUrl of TILESETS) {
const source = new MVTTilesSource({url: tilesetUrl});
const source = new MVTSource({url: tilesetUrl});
t.ok(source);
const metadata = await source.getMetadata();
t.ok(metadata);
Expand All @@ -22,14 +22,14 @@ test('MVTTilesSource#urls', async (t) => {
t.end();
});

test('MVTTilesSource#Blobs', async (t) => {
test('MVTSource#Blobs', async (t) => {
if (!isBrowser) {
t.comment('MVTTilesSource currently only supported in browser');
t.comment('MVTSource currently only supported in browser');
t.end();
return;
}
for (const tilesetUrl of TILESETS) {
const source = new MVTTilesSource({url: tilesetUrl});
const source = new MVTSource({url: tilesetUrl});
t.ok(source);
const metadata = await source.getMetadata();
t.ok(metadata);
Expand Down

0 comments on commit 37697d3

Please sign in to comment.