-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable download button and show tooltip at low zoom levels. [#37 #59] #63
Changes from all commits
42be39d
e25db9e
daffea8
703b922
ff5babf
fdaf9f7
55cb3ce
0ec7dc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
import "maplibre-gl/dist/maplibre-gl.css"; | ||
import * as pmtiles from "pmtiles"; | ||
import maplibregl from "maplibre-gl"; | ||
|
||
import { useState, useEffect, useCallback, useRef } from "react"; | ||
import { Layer, GeolocateControl } from "react-map-gl/maplibre"; | ||
import InspectorPanel from "./InspectorPanel"; | ||
|
@@ -133,7 +134,7 @@ ThemeTypeLayer.propTypes = { | |
extrusion: PropTypes.bool, | ||
}; | ||
|
||
export default function Map({ mode }) { | ||
export default function Map({ mode, setZoom }) { | ||
const mapRef = useRef(); | ||
const [cursor, setCursor] = useState("auto"); | ||
const [mapEntity, setMapEntity] = useState({}); | ||
|
@@ -144,6 +145,7 @@ export default function Map({ mode }) { | |
useEffect(() => { | ||
const protocol = new pmtiles.Protocol(); | ||
maplibregl.addProtocol("pmtiles", protocol.tile); | ||
|
||
return () => { | ||
maplibregl.removeProtocol("pmtiles"); | ||
}; | ||
|
@@ -173,6 +175,10 @@ export default function Map({ mode }) { | |
} | ||
}, []); | ||
|
||
const handleZoom = (event) => { | ||
setZoom(event.target.getZoom()); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={`map ${mode}`}> | ||
|
@@ -185,6 +191,7 @@ export default function Map({ mode }) { | |
onClick={onClick} | ||
cursor={cursor} | ||
hash={true} | ||
onZoom={handleZoom} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zoom state is dependent on map's zoom state. |
||
mapStyle={MAP_STYLE} | ||
interactiveLayerIds={interactiveLayerIds} | ||
initialViewState={INITIAL_VIEW_STATE} | ||
|
@@ -318,6 +325,7 @@ export default function Map({ mode }) { | |
{Object.keys(mapEntity).length > 0 && ( | ||
<InspectorPanel entity={mapEntity} /> | ||
)} | ||
|
||
<ThemeSelector visibleThemes={setVisibleThemes}></ThemeSelector> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,20 @@ import { | |
import downloadIcon from "/download.svg"; | ||
import RefreshIcon from "../icons/icon-refresh.svg?react"; | ||
import "./DownloadButton.css"; | ||
import Floater from "react-floater"; | ||
|
||
function DownloadButton() { | ||
const ZOOM_BOUND = 16; | ||
|
||
function DownloadButton({ mode, zoom, setZoom }) { | ||
const { myMap } = useMap(); | ||
|
||
const [loading, setLoading] = useState(false); | ||
const [showFloater, setShowFloater] = useState(false); | ||
|
||
useEffect(() => { | ||
if (myMap) { | ||
myMap.getBounds(); | ||
setZoom(myMap.getZoom()); | ||
} | ||
}, [myMap]); | ||
|
||
|
@@ -81,25 +86,74 @@ function DownloadButton() { | |
setLoading(false); | ||
}; | ||
|
||
const handleToggleTooltip = () => { | ||
if (zoom < ZOOM_BOUND) { | ||
setShowFloater(!showFloater); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="button--download"> | ||
<button | ||
className={`button button--primary ${loading ? "disabled" : ""}`} | ||
onClick={handleDownloadClick} | ||
> | ||
<div className="wrapper"> | ||
<div className="download-icon"> | ||
{!loading ? ( | ||
<img className={"dl-img"} src={downloadIcon} /> | ||
) : ( | ||
<RefreshIcon /> | ||
)} | ||
<div> | ||
<Floater | ||
styles={{ | ||
container: { | ||
borderRadius: "10px", | ||
padding: "10px", | ||
color: mode === "theme-dark" ? "white" : "black", | ||
fontSize: ".7rem", | ||
background: | ||
mode === "theme-dark" | ||
? "var(--ifm-navbar-background-color)" | ||
: "var(--ifm-color-secondary-light)", | ||
}, | ||
arrow: { | ||
color: | ||
mode === "theme-dark" | ||
? "var(--ifm-navbar-background-color)" | ||
: "var(--ifm-color-secondary-light)", | ||
}, | ||
}} | ||
content={ | ||
<div> | ||
The download button is disabled at zoom levels below {ZOOM_BOUND}. | ||
This is done to prevent downloading large amounts of data. To | ||
reenable the button, zoom further in. If you wish to download a | ||
larger area of data points, consider using our python installer, | ||
found at{" "} | ||
<a | ||
href={"https://github.com/OvertureMaps/overturemaps-py"} | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
our git repository | ||
</a> | ||
. | ||
</div> | ||
<div className="download-text"> | ||
{loading ? "Downloading..." : "Download Visible"} | ||
} | ||
open={showFloater} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Floater is "controlled", and only is shown when use is hovering over the 'button--download' div element. |
||
target={".button--download"} | ||
/> | ||
<div className="button--download" onMouseDown={handleToggleTooltip}> | ||
<button | ||
className={`button button--primary ${ | ||
loading || zoom < ZOOM_BOUND ? "disabled" : "" | ||
}`} | ||
onClick={handleDownloadClick} | ||
> | ||
<div className="wrapper"> | ||
<div className="download-icon"> | ||
{!loading ? ( | ||
<img className={"dl-img"} src={downloadIcon} /> | ||
) : ( | ||
<RefreshIcon /> | ||
)} | ||
</div> | ||
<div className="download-text"> | ||
{loading ? "Downloading..." : "Download Visible"} | ||
</div> | ||
</div> | ||
</div> | ||
</button> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new zoom hook, used to update the download button state