0.0.6 • Published 3 years ago

three-mini-map v0.0.6

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

Three-Mini-Map

Library to display maps using three.js.

  • Generate 3d geometry from elevation tiles.
  • Smooth connexion between tiles.
  • Choose a map provider who deliver (EPSG:3857) WMTS tiles and add textures to tiles.

Live demo

Installation

if you want to use this library in your three project.

npm install three-mini-map

Examples are located in the examples folder. Each example has defined his own package.json but npm install is not needed. Just execute this command in the root directory. (examples share the same workspace )

If you want to test a Basic Hello World, check the examples/default

git clone https://github.com/lhapaipai/three-mini-map.git
npm install
cd examples/default
npm run dev

Usage

import MiniMapManager from "mini-map-manager";

const miniMapManager = new MiniMapManager();

miniMapManager
  .getMap({
    textureSource: "osm",
    textureZoom: 15,
    center: [6.4751, 46.1024],
    radius: 4,
  })
  .then((map) => {
    let scene = new THREE.Scene();
    scene.add(map);
  });

API

MiniMapManager class

const miniMapManager = new MiniMapManager(options);

Define custom configuration in the options object.

KeyDescriptionDefault Value
elevationSource (string)map elevation provider."terrarium"
elevationSource (obj)custom elevation provider-
zScaleFactoryour elevation data is multiplied to this factor1.6
tileUnitsthe dimension of each tile in Three1.0
debugshow debug infos in your console.false
dryRunshow tiles to load if you want to download them and then work locallyfalse
basementHeightheight of the base (in three coords) on which to place the map0.05

if you want to provide your own elevation provider you can specify configuration in the elevationSource key.

new MiniMapManager({
  elevationSource: {
    url: (z, x, y) =>
      `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`,
    size: 256,
    maxZoom: 15,
  },
});

miniMapManager instance methods

miniMapManager.getMap(mapOptions).then((map) => {
  // map is a THREE.Group instance
});

Define custom configuration in the mapOptions object.

KeyDescriptionDefault Value
textureSource (str)map provider used to texture the tile."osm"
textureSource (obj)custom map provider-
tileSegmentsnb of segments used per texture tile to build the geometry. must be a power of 2 (16, 32, 64, 128, 256)32
textureZoomzoom used to retrieve textures15
centerarray containing position of the map [lng, lat]6.4751, 46.1024
radiusdistance in kilometers used to compute the bbox of your map.1
materialan object with the name and options to apply to each tile. set map to false if you don't want texture (or if you want to preview relief data before download big texture data.)
withTexturewether or not we add map texture (from textureSource) to the materialtrue

if you want to provide your own map provider you can specify configuration in the textureSource key.

miniMapManager.getMap({
  textureSource: {
    url: (z, x, y, token) =>
      `https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/${z}/${x}/${y}?access_token=${token}`,
    size: 256,
    token: "YOUR_TOKEN",
  },
  material: {
    name: "MeshLambertMaterial",
    options: {
      wireframe: false,
    },
  },
});

Issues

I load two times the Three Library...

because all Three.js update are minor version change from major version 0. If you do not install the same version of three as three-mini-map in your project your app will load twice three.js

  • Check the version of Three.js installed by three-mini-map and install the same in your project. or
  • Import MiniMapManager from the sources
import MiniMapManager from "three-mini-map/src/MiniMapManager";
0.0.6

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago