Code Monkey home page Code Monkey logo

mapbox-3dtiles's Introduction

mapbox-3dtiles

3D Tiles implementation using Mapbox GL JS custom layers

See https://geodan.github.io/mapbox-3dtiles/ for a working demo.

Screenshot

This is a proof-of-concept implementation of a 3D Tiles viewer as a Mapbox GL JS custom layer. WebGL rendering is implemented using three.js. Only Web Mercator (EPSG:3857) tilesets are supported, as this is the projection mapbox uses. Earth-centered eart-fixed tilesets are explicitly not supported. Tilesets used for testing were generated using pg2b3dm, using a PostGIS database with EPSG:3857 geometries.

This is by no means a complete implementation of the 3D Tile specification. Currently the following features are supported:

  • Geometric error based tile loading
  • Replacement and additive refinement
  • Only Box bounding volumes are supported
  • Tile transforms
  • External tilesets
  • Tile types:
    • Batched 3D Model (b3dm)
    • Point Cloud (pnts): basic implementation

The following features are not supported at this time:

  • Any coordinate system other than EPSG:3857
  • Region and sphere bounding volumes
  • Viewer request volumes
  • Instanced 3D Model (i3dm) tiles
  • Composite (cmpt) tiles
  • 3D Tile Styles

Instructions

In a directory on your webserver run the folowing commands:

git clone https://github.com/Geodan/mapbox-3dtiles.git
cd mapbox-3dtiles
npm install
cd ./ahn
tar zxvf ahn_points.tar.gz
cd ../rotterdam
tar zxvf rotterdam_3dtiles_small.tar.gz

Next, copy file "apikeys.js.example" to "apikeys.js" and add your mapbox token. Point your browser to the directory in question and you should see a basic viewer with 3d tiles content.

Creating tilesets

Tilesets can be created using pg2b3dm, using a PostGIS database table as source. The PostGIS table should contain 3D geometries in EPSG:3857 projection.

Example query creating extruded 3D buildings in EPSG:3857:

DROP TABLE IF EXISTS <schema>.<output_table>;
CREATE TABLE <schema>.<output_table> AS (
	WITH extent AS (
		SELECT ST_MakeEnvelope(<minx>, <miny>, <maxx>, <maxy>, <input_srid>) geom
	),
	footprints AS (
		SELECT a.id AS id, a.height, a.geom
		FROM <schema>.<input_table> a, extent b
		WHERE ST_Intersects(a.geom, b.geom)
	)
	SELECT id, ST_Force3D(ST_Extrude(ST_Transform(ST_MakeValid(geom), 3857), 0, 0, height)) AS geom
	FROM footprints
);
DELETE FROM <schema>.<output_table> WHERE geom IS NULL; -- cleanup
DELETE FROM <schema>.<output_table> WHERE ST_GeometryType(geom) NOT LIKE 'ST_PolyhedralSurface'; -- cleanup

Creating tileset using pg2b3dm:

pg2b3dm -h <my_host> -U <my_user> -d <my_database> -p <my_port> -c <geom_column> -t <my_schema.my_table>

For more information, see the pg2b3dm documentation.

Creating tileset from point cloud:

Pointcloud data is not yet supported by pg2b3dm and needs to be exporterd with an earlier tool called py3dtiles

py3dtiles convert --srs_in <srs_in> --srs_out 3857 --out <tileset_name> pointcloud.las

For more information, see the py3dtiles documentation.

mapbox-3dtiles's People

Contributors

tomvantilburg avatar anneb avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.