Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-chemla committed Jun 28, 2024
2 parents 4db8a2c + 68e86ab commit 5badb11
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
26 changes: 22 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ function App() {
// const [rightTimelineDate, setRightTimelineDate] = useState<Date>(
// subMonths(new Date(), 18)
// );

const [customPlanetApiKey, setCustomPlanetApiKey] = useLocalStorage(
"customPlanetApiKey",
""
);
const [useCustomApiKey, setUseCustomApiKey] = useLocalStorage(
"useCustomPlanetApiKey",
false
);
const [planetUrl, setPlanetUrl] = useState<string>(planetBasemapUrl(subMonths(new Date(), 1), false));
useEffect(() => {
setPlanetUrl(planetBasemapUrl(clickedMap == "left" ? leftTimelineDate : rightTimelineDate, useCustomApiKey, customPlanetApiKey));
}, [useCustomApiKey]);

const [leftTimelineDate, setLeftTimelineDate] = useLocalStorage(
"leftTimelineDate",
subMonths(new Date(), 1)
Expand Down Expand Up @@ -383,7 +397,7 @@ function App() {
<GeocoderControl
mapboxAccessToken={MAPBOX_TOKEN}
position="top-left"
flyTo={true}
flyTo={false}
mapRef={leftMapRef}
/>

Expand All @@ -395,7 +409,7 @@ function App() {
scheme="xyz"
type="raster"
// tiles={[]}
tiles={[planetBasemapUrl(leftTimelineDate)]}
tiles={[planetUrl]}
tileSize={256}
// key={"planetBasemap"}
key={leftTimelineDate.toString()}
Expand Down Expand Up @@ -461,8 +475,7 @@ function App() {
id="planetbasemap-source"
scheme="xyz"
type="raster"
tiles={[planetBasemapUrl(rightTimelineDate)]}
// tiles={[]}
tiles={[planetUrl]} // tiles={[]}
tileSize={256}
// key={"planetBasemap"}
key={rightTimelineDate.toString()}
Expand Down Expand Up @@ -508,6 +521,11 @@ function App() {
</div>
</div>
<ControlPanelDrawer
// Adding custom Planet API key input
useCustomApiKey={useCustomApiKey}
setUseCustomPlanetApiKey={setUseCustomApiKey}
customPlanetApiKey={customPlanetApiKey}
setCustomPlanetApiKey={setCustomPlanetApiKey}
// Adding blending mode opacity, and blending mode activation to pass downward
blendingActivation={blendingActivation}
setBlendingActivation={setBlendingActivation}
Expand Down
14 changes: 13 additions & 1 deletion src/control-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ const drawerWidth = '240px';
function ControlPanelDrawer(props: any) {
// const theme = useTheme();
const [open, setOpen] = useState(true);

const setUseCustomPlanetApiKey = props.setUseCustomPlanetApiKey;
const setCustomPlanetApiKey = props.setCustomPlanetApiKey;
const handleDrawerToggle = () => {
setOpen(!open);
};
Expand Down Expand Up @@ -244,6 +245,10 @@ function ControlPanelDrawer(props: any) {
// Additional
setLeftSelectedTms={props.setLeftSelectedTms}
setRightSelectedTms={props.setRightSelectedTms}
setUseCustomPlanetApiKey={setUseCustomPlanetApiKey}
setCustomPlanetApiKey={setCustomPlanetApiKey}
UseCustomPlanetApiKey={props.UseCustomPlanetApiKey}
customPlanetApiKey={props.customPlanetApiKey}
/>

</Drawer>
Expand All @@ -269,6 +274,9 @@ function ControlPanel(props:any) {
props.setTimelineDate(sliderValToDate(newValue, minDate));
};

const setUseCustomPlanetApiKey = props.setUseCustomPlanetApiKey;
const setCustomPlanetApiKey = props.setCustomPlanetApiKey;

// const [minDate, setMinDate] = useState<Date>(MIN_DATE);
// const [maxDate, setMaxDate] = useState<Date>(MAX_DATE);
const [minDate, setMinDate] = useLocalStorage("export_minDate", MIN_DATE);
Expand Down Expand Up @@ -639,6 +647,10 @@ function ControlPanel(props:any) {
setMaxFrameResolution={setMaxFrameResolution}
collectionDateActivated={collectionDateActivated}
setCollectionDateActivated={setCollectionDateActivated}
setCustomPlanetApiKey={setCustomPlanetApiKey}
setUseCustomPlanetApiKey={setUseCustomPlanetApiKey}
useCustomPlanetApiKey={props.useCustomPlanetApiKey}
customPlanetApiKey={props.customPlanetApiKey}
/>
</Stack>
</Stack>
Expand Down
28 changes: 28 additions & 0 deletions src/custom-planet-api-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useState } from 'react';
import TextField from '@mui/material/TextField';
import Checkbox from '@mui/material/Checkbox';

function CustomPlanetApiModal(props: any) {
const customPlanetApiKey = props.customPlanetApiKey;
const UseCustomPlanetApiKey = props.UseCustomPlanetApiKey;
const setCustomPlanetApiKey = props.setCustomPlanetApiKey;
const setUseCustomPlanetApiKey = props.setUseCustomPlanetApiKey;

const handleCheckboxChange = () => {
setUseCustomPlanetApiKey(!UseCustomPlanetApiKey);
};

const handleInputChange = (event) => {
setCustomPlanetApiKey(event.target.value);
};


return (
<div className='customApiModal'>
<Checkbox checked={UseCustomPlanetApiKey} onChange={handleCheckboxChange} />
<TextField value={customPlanetApiKey} onChange={handleInputChange} label="Planet Monthly Key" />
</div>
);
};

export default CustomPlanetApiModal;
2 changes: 1 addition & 1 deletion src/geocoder-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function GeocoderControl(
zoom: 15,
marker: false,
accessToken: props.mapboxAccessToken,
flyTo: { maxDuration: 1000 },
flyTo: { maxDuration: 0 },
});
// ctrl.on('loading', props.onLoading);
// ctrl.on('results', props.onResults);
Expand Down
7 changes: 7 additions & 0 deletions src/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import dayjs from "dayjs";
import { MIN_DATE, MAX_DATE } from "./utilities";
import CustomPlanetApiModal from "./custom-planet-api-modal";

const style = {
position: "absolute" as "absolute",
Expand All @@ -34,6 +35,8 @@ export default function SettingsModal(props: any) {
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const errorMessage = "start Date should be before end date!";
const setCustomPlanetApiKey = props.setCustomPlanetApiKey;
const setUseCustomPlanetApiKey = props.setUseCustomPlanetApiKey;

const handleCollectionDateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
props.setCollectionDateActivated( event.target.checked);
Expand Down Expand Up @@ -167,6 +170,10 @@ export default function SettingsModal(props: any) {
/>
}
/>
<CustomPlanetApiModal
setCustomPlanetApiKey={setCustomPlanetApiKey}
setUseCustomPlanetApiKey={setUseCustomPlanetApiKey}
/>
</Box>
</Modal>
</Fragment>
Expand Down
4 changes: 2 additions & 2 deletions src/utilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const formatDate = (date: Date) => format(date, "yyyy-MM");
// PlanetMonthly URLS
const PLANET_BASEMAP_API_KEY = import.meta.env.VITE_PLANET_BASEMAP_API_KEY;

const planetBasemapUrl = (date: Date) => {
const planetBasemapUrl = (date: Date, useCustom: Boolean, customApi?:string) => {
// basemap_date_str = "2019_01";
return `https://tiles.planet.com/basemaps/v1/planet-tiles/global_monthly_${format(
date,
"yyyy_MM"
)}_mosaic/gmap/{z}/{x}/{y}.png?api_key=${PLANET_BASEMAP_API_KEY}`;
)}_mosaic/gmap/{z}/{x}/{y}.png?api_key=${useCustom ? customApi : PLANET_BASEMAP_API_KEY}`;
};

// Set custom slider marks for each beginning of year
Expand Down

0 comments on commit 5badb11

Please sign in to comment.