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

Update SDK to v3 #14

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# MapTiler 3D Models Changelog

## 2.0.0
### Other
- Update with MapTiler SDK v3 (globe)

## 1.0.0
First release 🎉
First release 🎉
1 change: 0 additions & 1 deletion demos/.nojekyll

This file was deleted.

73 changes: 35 additions & 38 deletions demos/flight.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<!DOCTYPE html>
<html>

<head>
<title>MapTiler 3D</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.maptiler.com/maptiler-sdk-js/v2.3.0/maptiler-sdk.umd.min.js"></script>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v2.3.0/maptiler-sdk.css" rel="stylesheet" />
<script src="../build/maptiler-3d.umd.js"></script>

<script src="https://cdn.maptiler.com/maptiler-sdk-js/v3.0.0/maptiler-sdk.umd.min.js"></script>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v3.0.0/maptiler-sdk.css" rel="stylesheet" />
<script src="../build/maptiler-3d.umd.min.js"></script>

<style>
body {
margin: 0;
Expand All @@ -26,18 +29,15 @@
right: inherit;
left: 15px;
}

</style>
</head>

<body>


<div id="map"></div>

<script>

maptilersdk.config.apiKey = new URLSearchParams(location.search).get("key") ?? alert("Missing URL param with MapTiler API key ?key=XXXXX");
maptilersdk.config.apiKey =
new URLSearchParams(location.search).get("key") ??
alert("Missing URL param with MapTiler API key ?key=XXXXX");

const newYorkCity = [-73.98918779556983, 40.74072950731568];
const capeTown = [18.428021658130994, -33.913973526198134];
Expand All @@ -46,8 +46,7 @@
const ankara = [32.866609260522345, 39.959329480757354];

const map = new maptilersdk.Map({
container: document.getElementById('map'),
// hash: true,
container: document.getElementById("map"),
style: maptilersdk.MapStyle.STREETS.DARK,
zoom: 9,
center: paris,
Expand All @@ -56,6 +55,7 @@
terrain: false,
maptilerLogo: true,
terrainExaggeration: 0.001,
projectionControl: true,
});

(async () => {
Expand All @@ -69,29 +69,25 @@
"horizon-fog-blend": 0.1,
"sky-horizon-blend": 1.0,
"atmosphere-blend": 0.5,
})
});

const layer3D = new maptiler3d.Layer3D("custom-3D-layer");
map.addLayer(layer3D);

// Increasing the intensity of the ambient light
layer3D.setAmbientLight({intensity: 2});
// Increasing the intensity of the ambient light
layer3D.setAmbientLight({ intensity: 2 });

// Adding a point light
layer3D.addPointLight("point-light", {intensity: 30});
layer3D.addPointLight("point-light", { intensity: 30 });

const originalPlaneID = "plane";
await layer3D.addMeshFromURL(
originalPlaneID,
"models/plane_a340.glb",
{
lngLat: paris,
heading: 12,
scale: 5,
altitude: 5000,
altitudeReference: maptiler3d.AltitudeReference.MEAN_SEA_LEVEL,
}
);
await layer3D.addMeshFromURL(originalPlaneID, "models/plane_a340.glb", {
lngLat: paris,
heading: 12,
scale: 5,
altitude: 5000,
altitudeReference: maptiler3d.AltitudeReference.MEAN_SEA_LEVEL,
});

const guiObj = {
play: false,
Expand All @@ -101,17 +97,16 @@

const gui = new lil.GUI({ width: 500 });

gui.add( guiObj, 'tackFlight')
gui.add(guiObj, "tackFlight");

gui.add( guiObj, 'play')
.onChange((play) => {
gui.add(guiObj, "play").onChange((play) => {
if (play) {
playAnimation();
}
});

gui.add( guiObj, 'speed', 0, 0.001);
gui.add(guiObj, "speed", 0, 0.001);

let progress = 0;

function playAnimation() {
Expand All @@ -121,8 +116,12 @@
progress = 0;
}

const position = maptilersdk.math.haversineIntermediateWgs84(paris, ankara, progress);
layer3D.modifyMesh(originalPlaneID, {lngLat: position});
const position = maptilersdk.math.haversineIntermediateWgs84(
paris,
ankara,
progress
);
layer3D.modifyMesh(originalPlaneID, { lngLat: position });

if (guiObj.tackFlight) {
map.setCenter(position);
Expand All @@ -133,10 +132,8 @@
requestAnimationFrame(playAnimation);
}
}


})()

})();
</script>
</body>
</html>

</html>
47 changes: 47 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MapTiler 3D JS</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
</head>

<body>
<h1>MapTiler 3D JS Examples</h1>
<ul>
<li>
<a href="flight.html?key=">Flight</a>
</li>
<li>
<a href="mountains.html?key=">Mountains</a>
</li>
<li>
<a href="multi.html?key=">Multi</a>
</li>
<li>
<a href="plane.html?key=">Plane</a>
</li>
<li>
<a href="point_cad_model01.html?key=">Point Cloud - CAD-like view</a>
</li>
<li>
<a href="point_cloud_dundee.html?key=">Point Cloud - Dundee</a>
</li>
<li>
<a href="point_cloud_NMH.html?key=">Point Cloud - NMH</a>
</li>
<li>
<a href="point_cloud_shore.html?key=">Point Cloud - Shore</a>
</li>
</ul>

<script type="module">
document.querySelectorAll("a").forEach((a) => {
a.href += import.meta.env.VITE_API_KEY;
});
</script>
</body>

</html>
Binary file added demos/models/position-indicator--y-up.glb
Binary file not shown.
Binary file added demos/models/position-indicator--z-up.glb
Binary file not shown.
Loading
Loading