Published
Edited
May 1, 2021
2 forks
Insert cell
Insert cell
container = html `<div style="height:${height}px"></div>`
Insert cell
height = 700
Insert cell
tmp = 'something'
Insert cell
polygon_data = [
{
'name': 'something',
'coordinates': [[0,1], [1,1], [2,2]]
}
]
Insert cell
scatter_data = [{'name': 'one', 'x': 0, 'y': 1},
{'name': 'two', 'x': 2, 'y': 2}]
Insert cell
// image = FileAttachment("image_string.txt").text()
Insert cell
// image
Insert cell
// blue square image
image = '"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAHUlEQVR4nGNkYPjPQC5gIlvnqOZRzaOaRzVTRTMAIJ4BJ6WiocQAAAAASUVORK5CYII="'
Insert cell
image_proc = image.slice(1,-1)
Insert cell
// image.slice(1,-1)
Insert cell
{
const polygon_layer = new deck.PolygonLayer({
id: 'polygon_layer',
data: polygon_data,
getFillColor: [250, 0, 0, 50],
getLineColor: [250, 0, 0, 50],
getLineWidth: d => 0.1,
getPolygon: d => d.coordinates,
stroked: true,
filled: true,
wireframe: true,
pickable: true,
// opacity: rescue_opacity
});

const scatter_layer = new deck.ScatterplotLayer({
id: 'scatter_layer',
data: scatter_data,
getPosition: d => {

return [d.x, d.y]
},
getFillColor: [0, 0, 250, 150],
getRadius: radius,
pickable: true,
// autoHighlight: true,
highlightColor: d => [50, 50, 50],
radiusMinPixels: radius_min_pixels,
updateTriggers: {
// getFillColor: select_meta,
// getPosition: map_type
},
})

const bitmap_layer = new deck.BitmapLayer({
id: 'bitmap_layer',
bounds:image_bounds,
image:image_proc
});
deckgl.setProps({layers: [bitmap_layer, polygon_layer, scatter_layer]});
// deckgl.setProps({layers: [bitmap_layer]});
}
Insert cell
deck = require.alias({
// optional dependencies
h3: {},
s2Geometry: {}
})('deck.gl@8.3.7/dist.min.js')
Insert cell
// image_bounds = [[0, -image_size], [0, 0], [image_size, 0], [image_size, -image_size]]

// [[left, bottom], [left, top], [right, top], [right, bottom]]
image_bounds = [[0, -image_size], [0, 0], [image_size, 0], [image_size, -image_size]]
Insert cell
image_size = 10
Insert cell
radius = 1
Insert cell
radius_min_pixels = 0.5
Insert cell
center_x = 0
Insert cell
center_y = 0
Insert cell
INITIAL_VIEW_STATE = ({
target: [center_x, center_y, 0],
zoom: zoom,
minZoom:min_zoom
})
Insert cell
min_zoom = -1.5
Insert cell
zoom = 0
Insert cell
deckgl = {
// // reference for below https://observablehq.com/@tomvantilburg/deckgl-mapbox-and-3d-tiles
// // This is an Observable hack: clear previously generated content
container.innerHTML = '';
const view = new deck.OrthographicView({id: 'ortho'})
return new deck.DeckGL({
container,
views:[view],
initialViewState:INITIAL_VIEW_STATE,
controller: true,
getTooltip: ({object}) => {
return object && ` ${object.name}
`},
});
}
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.
Learn more