Notebooks 2.0 is here.
Read the preview announcement
Platform
Resources
Pricing
Sign in
Get started
Nicolas Fernandez
Workspace
Fork
Published
By
Nicolas Fernandez
Edited
Feb 23, 2021
Fork of
Deck.gl Moon TileLayer Example
•
1 fork
Insert cell
Insert cell
Insert cell
show_moon
=
true
Insert cell
ROOT_URL
=
original_url
// ROOT_URL = ''
// ROOT_URL = new_url
Insert cell
Insert cell
{
// console.log('defining layer!')
const
autoHighlight
=
true
const
moonLayer
=
new
deck
.
TileLayer
(
{
pickable
:
autoHighlight
,
tileSize
:
dimensions
.
tileSize
,
autoHighlight
,
highlightColor
:
[
60
,
60
,
60
,
100
]
,
minZoom
:
-
7
,
maxZoom
:
0
,
coordinateSystem
:
deck
.
COORDINATE_SYSTEM
.
CARTESIAN
,
extent
:
[
0
,
0
,
dimensions
.
width
,
dimensions
.
height
]
,
getTileData
:
getTileData
,
onViewportLoad
:
getMetaData
,
renderSubLayers
:
renderSubLayers
}
)
;
var
layers
=
[
]
if
(
show_moon
===
true
)
{
layers
=
[
moonLayer
]
}
else
{
layers
=
[
]
}
deckgl
.
setProps
(
{
layers
:
layers
}
)
;
}
Insert cell
deckgl
=
{
// This is an Observable hack: clear previously generated content
// reference: https://observablehq.com/@tomvantilburg/deckgl-mapbox-and-3d-tiles
container
.
innerHTML
=
''
;
const
view
=
new
deck
.
OrthographicView
(
{
id
:
'ortho'
}
)
return
new
deck
.
DeckGL
(
{
container
,
views
:
[
view
]
,
initialViewState
:
INITIAL_VIEW_STATE
,
controller
:
true
,
}
)
;
}
Insert cell
Insert cell
inst_height
=
850
Insert cell
dimensions
=
(
{
'height'
:
24000
,
'width'
:
24000
,
'tileSize'
:
512
}
)
Insert cell
original_url
=
'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/image-tiles/moon.image'
Insert cell
new_url
=
'https://raw.githubusercontent.com/cornhundred/deck.gl-data/master/website/image-tiles/moon.image'
Insert cell
INITIAL_VIEW_STATE
=
(
{
target
:
[
13000
,
13000
,
0
]
,
zoom
:
-
5
}
)
Insert cell
Insert cell
getTileData
=
(
{
x
,
y
,
z
}
)
=>
{
// console.log('getTileData', x, y, z)
var
full_url
=
`${
ROOT_URL
}/moon.image_files/${
15
+
z
}/${
x
}_${
y
}.jpeg`
console
.
log
(
'full url'
,
full_url
)
return
loaders
.
load
(
full_url
)
;
}
Insert cell
renderSubLayers
=
props
=>
{
const
{
bbox
:
{
left
,
bottom
,
right
,
top
}
}
=
props
.
tile
;
const
{
width
,
height
}
=
dimensions
;
return
new
deck
.
BitmapLayer
(
props
,
{
data
:
null
,
image
:
props
.
data
,
bounds
:
[
clamp
(
left
,
0
,
width
)
,
clamp
(
bottom
,
0
,
height
)
,
clamp
(
right
,
0
,
width
)
,
clamp
(
top
,
0
,
height
)
]
}
)
;
}
Insert cell
getMetaData
=
async
(
)
=>
{
// console.log('getMetaData')
const
dziSource
=
`${
ROOT_URL
}/moon.image.dzi`
;
const
response
=
await
fetch
(
dziSource
)
;
const
xmlText
=
await
response
.
text
(
)
;
const
dziXML
=
new
DOMParser
(
)
.
parseFromString
(
xmlText
,
'text/xml'
)
;
if
(
Number
(
dziXML
.
getElementsByTagName
(
'Image'
)
[
0
]
.
attributes
.
Overlap
.
value
)
!==
0
)
{
// eslint-disable-next-line no-undef, no-console
console
.
warn
(
'Overlap parameter is nonzero and should be 0'
)
;
}
// may set dimensions here using mutable
// console.log(Number(dziXML.getElementsByTagName('Size')[0].attributes.Height.value))
// // trying to bring in getMetaData function
// var dimensions = {}
// dimensions.height = Number(dziXML.getElementsByTagName('Size')[0].attributes.Height.value),
// dimensions.width = Number(dziXML.getElementsByTagName('Size')[0].attributes.Width.value),
// dimensions.tileSize = Number(dziXML.getElementsByTagName('Image')[0].attributes.TileSize.value)
}
;
Insert cell
Insert cell
// deck = require.alias({
// // optional dependencies
// h3: {},
// s2Geometry: {}
// })('deck.gl@8.3.7/dist.min.js')
deck
=
require
.
alias
(
{
// optional dependencies
h3
:
{
}
,
s2Geometry
:
{
}
}
)
(
'deck.gl@8.4.6/dist.min.js'
)
Insert cell
// https://observablehq.com/@jamesleesaunders/calculating-vector-rotations
mathGl
=
require
(
'https://bundle.run/math.gl@2.3.3'
)
Insert cell
clamp
=
mathGl
.
clamp
Insert cell
// // via https://observablehq.com/@tomvantilburg/deckgl-mapbox-and-3d-tiles
// loaders = require('@loaders.gl/3d-tiles@2.2.8/dist/dist.js')
Insert cell
loaders
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
container
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
show_moon
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ROOT_URL
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
deckgl
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
inst_height
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dimensions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
original_url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
new_url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
INITIAL_VIEW_STATE
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getTileData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
renderSubLayers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getMetaData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
deck
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mathGl
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
clamp
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML