Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored library to support custom web workers #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stuarta0
Copy link
Contributor

@stuarta0 stuarta0 commented Dec 3, 2021

Added example with Mapzen Terrarium decoder.

I've integrated this into my commercial project and it works well. In short:

  • I separated the code that has the special import string for rollup's web worker handling into it's own mapbox-terrain-provider.ts. This means external code can reference the other *.ts files without needing custom config to handle the "web-worker:..." import string.
  • I simplified the export for the distributable, as I no longer need them. You're welcome to add them back in if required. Now it only exports the base MapboxTerrainProvider class.
  • I removed the git submodule for martini and instead added it as a dependency.

Usage is as follows:

import { MartiniTerrainProvider } from "lib/terrain-provider";
import { WorkerFarmTerrainDecoder } from "lib/worker/decoder";
import TerrariumWorker from "./mapzen.worker";

const terrainDecoder = new WorkerFarmTerrainDecoder({
  worker: new TerrariumWorker()
});

const terrainProvider = new MartiniTerrainProvider({
  resource: ...,
  decoder: terrainDecoder,
});

Where mapzen.worker.ts is the web worker code, using whichever bundler the consumer desires. In this case, webpack with worker-loader.

Added example with Mapzen Terrarium decoder
@davenquinn
Copy link
Owner

Hi Stuart, it looks like most of these changes are desirable and improve flexibility without overly complicating the API.

I will note that Martini is currently included as a submodule to support minimum triangle sizes at low zooms, a feature that was left out of the original library. There's an open pull request but I won't want to remove the internal dependency until that is integrated upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants