Skip to content

Commit

Permalink
example(MVT): add example with official MapBox style file
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Jan 15, 2025
1 parent 3dc135e commit d1abe5a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Vector tiles": {
"vector_tile_raster_3d": "Raster on 3D map",
"vector_tile_raster_2d": "Raster on 2D map",
"vector_tile_mapbox_raster": "Mapbox Vector Tiles to raster",
"vector_tile_3d_mesh": "Vector tile to 3d objects",
"vector_tile_3d_mesh_mapbox": "Mapbox Vector tile to 3d objects",
"vector_tile_dragndrop": "Drag and drop a style"
Expand Down
91 changes: 91 additions & 0 deletions examples/vector_tile_mapbox_raster.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<html>
<head>
<title>Itowns - vector-tiles 2d </title>

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<link
rel="stylesheet"
type="text/css"
href="css/example.css"
/>
<link
rel="stylesheet"
type="text/css"
href="css/LoadingScreen.css"
/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
</head>
<body>
<div id="viewerDiv"></div>

<!-- Import iTowns source code -->
<script src="../dist/itowns.js"></script>
<script src="../dist/debug.js"></script>
<!-- Import iTowns LoadingScreen and GuiTools plugins -->
<script src="js/GUI/GuiTools.js"></script>
<script src="js/GUI/LoadingScreen.js"></script>

<script>
const typeView = 'Planar';
// const typeView = 'Globe';

// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
var viewerDiv = document.getElementById('viewerDiv');
let view;

if (typeView === 'Globe') {
const coord = new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712); // Paris
// const coord = new itowns.Coordinates("EPSG:4326", 60.599525, 56.834341); // Yekaterinburg
const placement = {
coord,
range: 950000,
};
view = new itowns.GlobeView(viewerDiv, placement);
} else if (typeView === 'Planar') {
// Define geographic extent: CRS, min/max X, min/max Y
var extent = new itowns.Extent(
'EPSG:3857',
-20037508.342789244, 20037508.342789244,
-20037508.342789255, 20037508.342789244);

// Instanciate PlanarView
view = new itowns.PlanarView(viewerDiv, extent, {
maxSubdivisionLevel: 20,
controls: {
// We do not want the user to zoom out too much
maxAltitude: 40000000,
// We want to keep the rotation disabled, to only have a view from the top
enableRotation: false,
// Don't zoom too much on smart zoom
smartTravelHeightMax: 100000,
},
});
}

const debugMenu = new GuiTools("menuDiv", view);
setupLoadingScreen(viewerDiv, view);

const source = new itowns.VectorTilesSource({
style: "mapbox://styles/mapbox/streets-v8",
accessToken:
"pk.eyJ1IjoiZnRvcm9tYW5vZmYiLCJhIjoiY2xrc2Zpa2o3MDQxNTNxcG5sczJyaTlncyJ9.5KFKdMLIiy-b_fAjSVhjCQ",
});

const layer = new itowns.ColorLayer("vector-map", {
source,
noTextureParentOutsideLimit: true,
addLabelLayer: true,
});

view.addLayer(layer).then(() => {
debugMenu.addLayerGUI.bind(debugMenu);
itowns.ColorLayersOrdering.moveLayerToIndex(view, "vector-map", 15);
});

debug.createTileDebugUI(debugMenu.gui, view);
</script>
</body>
</html>

0 comments on commit d1abe5a

Please sign in to comment.