Notebooks 2.0 is here.
Read the preview announcement
Platform
Resources
Pricing
Sign in
Get started
Ryan Murphy
Doing stuff
Workspace
Fork
Public
By
Ryan Murphy
Edited
Mar 3, 2023
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
location
=
{
if
(
prompt
)
{
try
{
return
await
getLocation
(
)
;
}
catch
(
error
)
{
console
.
error
(
error
)
;
return
null
;
}
}
else
{
return
null
;
}
}
Insert cell
function
getLocation
(
)
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
navigator
.
geolocation
.
getCurrentPosition
(
(
{
coords
:
{
longitude
,
latitude
}
}
)
=>
resolve
(
[
longitude
,
latitude
]
)
,
reject
)
;
}
)
;
}
Insert cell
async
function
findPolygon
(
rect
)
{
const
source
=
geojson
.
deserialize
(
url
,
rect
)
;
// intentionally not caring about multiple matches
// makes sense for this dataset, but may not always!
for
await
(
const
feature
of
source
)
{
if
(
d3
.
geoContains
(
feature
,
[
rect
.
minX
,
rect
.
minY
]
)
)
{
return
feature
;
}
}
return
null
;
}
Insert cell
geojson
=
import
(
"https://esm.sh/flatgeobuf@3.24.1/lib/mjs/geojson.js?bundle"
)
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
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prompt
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Edit
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
feature
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
map
Edit
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
location
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getLocation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
findPolygon
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
geojson
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML