-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
335 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script lang="ts"> | ||
import { MapLibre, PMTilesProtocol } from 'svelte-maplibre-gl'; | ||
import type { LayerSpecification } from 'maplibre-gl'; | ||
// Get the layers spec from the OSM style | ||
let layers: LayerSpecification[] = $state.raw([]); | ||
$effect(() => { | ||
fetch('https://tile.openstreetmap.jp/styles/openmaptiles/style.json') | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
layers = data['layers'].filter( | ||
(layer: LayerSpecification) => !('source' in layer) || layer.source === 'openmaptiles' | ||
); | ||
}); | ||
}); | ||
</script> | ||
|
||
<!-- Add pmtiles:// Protocol --> | ||
<PMTilesProtocol /> | ||
|
||
<!-- Use custom protocols --> | ||
<MapLibre | ||
class="h-[55vh] min-h-[200px]" | ||
zoom={3} | ||
center={[138.0, 36.5]} | ||
style={{ | ||
version: 8, | ||
glyphs: 'https://tile.openstreetmap.jp/fonts/{fontstack}/{range}.pbf', | ||
sprite: 'https://tile.openstreetmap.jp/styles/openmaptiles/sprite', | ||
sources: { | ||
openmaptiles: { | ||
type: 'vector', | ||
url: 'pmtiles://https://tile.openstreetmap.jp/static/planet.pmtiles', | ||
attribution: '© OpenMapTiles © OpenStreetMap contributors' | ||
} | ||
}, | ||
layers | ||
}} | ||
></MapLibre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: PMTiles Protocol | ||
description: Uses the PMTiles plugin and protocol to present a map. | ||
--- | ||
|
||
<script lang="ts"> | ||
import Demo from "./PMTiles.svelte"; | ||
import demoRaw from "./PMTiles.svelte?raw"; | ||
import CodeBlock from "../../CodeBlock.svelte"; | ||
</script> | ||
|
||
<Demo /> | ||
|
||
<CodeBlock content={demoRaw} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script lang="ts"> | ||
import { MapLibre, CustomLayer } from 'svelte-maplibre-gl'; | ||
import maplibregl from 'maplibre-gl'; | ||
import * as THREE from 'three'; | ||
import { Matrix4, Vector3 } from 'three'; | ||
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; | ||
let map: maplibregl.Map | undefined = $state.raw(); | ||
const modelOrigin: [number, number] = [148.9819, -35.39847]; | ||
const modelAltitude = 0; | ||
const modelRotate = [Math.PI / 2, 0, 0]; | ||
const modelAsMercatorCoordinate = maplibregl.MercatorCoordinate.fromLngLat(modelOrigin, modelAltitude); | ||
class CustomLayerImpl implements Omit<maplibregl.CustomLayerInterface, 'id' | 'type'> { | ||
camera = new THREE.Camera(); | ||
scene = new THREE.Scene(); | ||
renderer: THREE.WebGLRenderer | null = null; | ||
renderingMode = '3d' as const; | ||
onAdd(map: maplibregl.Map, gl: WebGL2RenderingContext) { | ||
// create two three.js lights | ||
const directionalLight1 = new THREE.DirectionalLight(0xffffff); | ||
directionalLight1.position.set(0, -70, 100).normalize(); | ||
this.scene.add(directionalLight1); | ||
const directionalLight2 = new THREE.DirectionalLight(0xffffff); | ||
directionalLight2.position.set(0, 70, 100).normalize(); | ||
this.scene.add(directionalLight2); | ||
// load a glTF model | ||
const loader = new GLTFLoader(); | ||
loader.load('https://maplibre.org/maplibre-gl-js/docs/assets/34M_17/34M_17.gltf', (gltf) => { | ||
this.scene.add(gltf.scene); | ||
}); | ||
// use the MapLibre GL JS map canvas for three.js | ||
this.renderer = new THREE.WebGLRenderer({ | ||
canvas: map!.getCanvas(), | ||
context: gl, | ||
antialias: true | ||
}); | ||
this.renderer.autoClear = false; | ||
} | ||
render(_gl: WebGL2RenderingContext | WebGLRenderingContext, options: maplibregl.CustomRenderMethodInput) { | ||
const scale = modelAsMercatorCoordinate.meterInMercatorCoordinateUnits(); | ||
const world = new Matrix4().fromArray(options.defaultProjectionData.mainMatrix); | ||
const local = new Matrix4() | ||
.makeTranslation(modelAsMercatorCoordinate.x, modelAsMercatorCoordinate.y, modelAsMercatorCoordinate.z) | ||
.scale(new Vector3(scale, -scale, scale)) | ||
.multiply(new Matrix4().makeRotationX(modelRotate[0])) | ||
.multiply(new Matrix4().makeRotationY(modelRotate[1])) | ||
.multiply(new Matrix4().makeRotationZ(modelRotate[2])); | ||
this.camera.projectionMatrix = world.multiply(local); | ||
this.renderer!.resetState(); | ||
this.renderer!.render(this.scene, this.camera); | ||
map!.triggerRepaint(); | ||
} | ||
} | ||
const customLayerImpl = new CustomLayerImpl(); | ||
</script> | ||
|
||
<MapLibre | ||
bind:map | ||
class="h-[55vh] min-h-[300px]" | ||
style="https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json" | ||
zoom={18} | ||
pitch={60} | ||
center={[148.9819, -35.3981]} | ||
antialias | ||
> | ||
<CustomLayer implementation={customLayerImpl} /> | ||
</MapLibre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: 3D model with three.js | ||
description: Use a custom style layer with three.js to add a 3D model to the map. | ||
original: https://maplibre.org/maplibre-gl-js/docs/examples/add-3d-model/ | ||
--- | ||
|
||
<script lang="ts"> | ||
import Demo from "./CustomLayer.svelte"; | ||
import demoRaw from "./CustomLayer.svelte?raw"; | ||
import CodeBlock from "../../CodeBlock.svelte"; | ||
</script> | ||
|
||
<Demo /> | ||
|
||
<CodeBlock content={demoRaw} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters