Skip to content

Commit

Permalink
docs: Use Popup in Maplibre/Mapbox getting started example (#8956)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Jun 20, 2024
1 parent 0af27a1 commit 537f80b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
24 changes: 15 additions & 9 deletions examples/get-started/react/mapbox/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, {useState} from 'react';
import {createRoot} from 'react-dom/client';
import {Map, NavigationControl, useControl} from 'react-map-gl';
import {Map, NavigationControl, Popup, useControl} from 'react-map-gl';
import {GeoJsonLayer, ArcLayer} from 'deck.gl';
import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
Expand Down Expand Up @@ -28,12 +28,7 @@ function DeckGLOverlay(props) {
}

function Root() {
const onClick = info => {
if (info.object) {
// eslint-disable-next-line
alert(`${info.object.properties.name} (${info.object.properties.abbrev})`);
}
};
const [selected, setSelected] = useState(null);

const layers = [
new GeoJsonLayer({
Expand All @@ -48,7 +43,7 @@ function Root() {
// Interactive props
pickable: true,
autoHighlight: true,
onClick
onClick: info => setSelected(info.object)
// beforeId: 'waterway-label' // In interleaved mode render the layer under map labels
}),
new ArcLayer({
Expand All @@ -70,6 +65,17 @@ function Root() {
mapStyle={MAP_STYLE}
mapboxAccessToken={MAPBOX_TOKEN}
>
{selected && (
<Popup
key={selected.properties.name}
anchor="bottom"
style={{zIndex: 10}} /* position above deck.gl canvas */
longitude={selected.geometry.coordinates[0]}
latitude={selected.geometry.coordinates[1]}
>
{selected.properties.name} ({selected.properties.abbrev})
</Popup>
)}
<DeckGLOverlay layers={layers} /* interleaved*/ />
<NavigationControl position="top-left" />
</Map>
Expand Down
24 changes: 15 additions & 9 deletions examples/get-started/react/maplibre/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, {useState} from 'react';
import {createRoot} from 'react-dom/client';
import {Map, NavigationControl, useControl} from 'react-map-gl/maplibre';
import {Map, NavigationControl, Popup, useControl} from 'react-map-gl/maplibre';
import {GeoJsonLayer, ArcLayer} from 'deck.gl';
import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox';
import 'maplibre-gl/dist/maplibre-gl.css';
Expand All @@ -25,12 +25,7 @@ function DeckGLOverlay(props) {
}

function Root() {
const onClick = info => {
if (info.object) {
// eslint-disable-next-line
alert(`${info.object.properties.name} (${info.object.properties.abbrev})`);
}
};
const [selected, setSelected] = useState(null);

const layers = [
new GeoJsonLayer({
Expand All @@ -45,7 +40,7 @@ function Root() {
// Interactive props
pickable: true,
autoHighlight: true,
onClick
onClick: info => setSelected(info.object)
// beforeId: 'watername_ocean' // In interleaved mode, render the layer under map labels
}),
new ArcLayer({
Expand All @@ -63,6 +58,17 @@ function Root() {

return (
<Map initialViewState={INITIAL_VIEW_STATE} mapStyle={MAP_STYLE}>
{selected && (
<Popup
key={selected.properties.name}
anchor="bottom"
style={{zIndex: 10}} /* position above deck.gl canvas */
longitude={selected.geometry.coordinates[0]}
latitude={selected.geometry.coordinates[1]}
>
{selected.properties.name} ({selected.properties.abbrev})
</Popup>
)}
<DeckGLOverlay layers={layers} /* interleaved*/ />
<NavigationControl position="top-left" />
</Map>
Expand Down

0 comments on commit 537f80b

Please sign in to comment.