Skip to content

Commit

Permalink
fix: set the parcel coordinates for the browser (#255)
Browse files Browse the repository at this point in the history
* fix: set the parcel coordinates for the browser before flying to a parcel

* fix: center the claim selection on click

* fix: center parcels from modal navigation and on click
  • Loading branch information
tnrdd committed Oct 7, 2022
1 parent c2f80e4 commit 4c7b2cf
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
16 changes: 14 additions & 2 deletions components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const GW_MAX_LAT = 22;
export const GW_MAX_LON = 23;
const ZOOM_QUERY_LEVEL = 8;
const QUERY_DIM = 1000;
export const LON_OFFSET = 0.00062;
export const LAT_OFFSET = 0.0001;

export enum STATE {
VIEWING = 0,
Expand Down Expand Up @@ -555,6 +557,11 @@ function Map(props: MapProps) {
switch (interactionState) {
case STATE.VIEWING:
if (_checkParcelClick()) {
setViewport({
...viewport,
longitude: event.lngLat.lng + LON_OFFSET,
latitude: event.lngLat.lat + LAT_OFFSET,
});
return;
}

Expand All @@ -563,8 +570,8 @@ function Map(props: MapProps) {
setInteractionState(STATE.CLAIM_SELECTING);

flyToLocation({
longitude: event.lngLat.lng,
latitude: event.lngLat.lat,
longitude: event.lngLat.lng + LON_OFFSET,
latitude: event.lngLat.lat + LAT_OFFSET,
zoom: ZOOM_GRID_LEVEL + 1,
duration: 500,
});
Expand Down Expand Up @@ -646,6 +653,11 @@ function Map(props: MapProps) {
zoom: ZOOM_GRID_LEVEL + 1,
duration: 500,
});

setSelectedParcelCoords({
x: portfolioParcelCoords.lon - LON_OFFSET,
y: portfolioParcelCoords.lat - LAT_OFFSET,
});
}
}, [portfolioParcelCoords]);

Expand Down
62 changes: 56 additions & 6 deletions components/profile/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ import {
import { getETHBalance } from "../../lib/getBalance";
import { truncateStr, truncateEth } from "../../lib/truncate";
import { calculateBufferNeeded, calculateAuctionValue } from "../../lib/utils";
import { STATE, GeoPoint } from "../Map";
import { STATE, GeoPoint, LON_OFFSET, LAT_OFFSET } from "../Map";

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(advancedFormat);

export const LON_OFFSET = 0.00085;
export const LAT_OFFSET = 0.0002;

type ProfileModalProps = {
accountTokenSnapshot: AccountTokenSnapshot;
account: string;
Expand Down Expand Up @@ -89,6 +86,11 @@ interface PortfolioTotal {
buffer: BigNumber;
}

interface GeoWebCoordinate {
pointTL: GeoPoint;
pointBR: GeoPoint;
}

enum SuperTokenAction {
WRAP,
UNWRAP,
Expand Down Expand Up @@ -133,6 +135,10 @@ const portfolioQuery = gql`
lon
lat
}
pointBR {
lon
lat
}
}
}
}
Expand Down Expand Up @@ -371,6 +377,26 @@ function ProfileModal(props: ProfileModalProps) {
? parcelContent.name
: `Parcel ${parcelId}`;

const topLeftLon = findMinPoint(
coords,
"pointTL",
"lon"
);
const bottomRightLon = findMaxPoint(
coords,
"pointBR",
"lon"
);
const topLeftLat = findMaxPoint(
coords,
"pointTL",
"lat"
);
const bottomRightLat = findMinPoint(
coords,
"pointBR",
"lat"
);
_portfolio.push({
parcelId: parcelId,
status: status,
Expand All @@ -381,8 +407,8 @@ function ProfileModal(props: ProfileModalProps) {
buffer: buffer,
action: action,
coords: {
lon: Number(coords[0].pointTL.lon) + LON_OFFSET,
lat: Number(coords[0].pointTL.lat) + LAT_OFFSET,
lon: (topLeftLon + bottomRightLon) / 2 + LON_OFFSET,
lat: (topLeftLat + bottomRightLat) / 2 + LAT_OFFSET,
},
});
});
Expand Down Expand Up @@ -565,6 +591,30 @@ function ProfileModal(props: ProfileModalProps) {
}
};

const findMinPoint = (
coords: GeoWebCoordinate[],
field: keyof GeoWebCoordinate,
unit: keyof GeoPoint
): number => {
return Math.min(
...coords.map((obj) => {
return Number(obj[field][unit]);
})
);
};

const findMaxPoint = (
coords: GeoWebCoordinate[],
field: keyof GeoWebCoordinate,
unit: keyof GeoPoint
): number => {
return Math.max(
...coords.map((obj) => {
return Number(obj[field][unit]);
})
);
};

const calcTotal = (portfolio: Parcel[], field: keyof Parcel): BigNumber =>
portfolio
.map((parcel) => parcel[field] as BigNumber)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit 4c7b2cf

Please sign in to comment.