Skip to content

Commit

Permalink
[migrate] replace Built-in Map model with OpenReactMap's
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Sep 1, 2023
1 parent 6cc32a3 commit 5566cfd
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 167 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"iterable-observer": "^1.0.0",
"koajax": "^0.8.6",
"lodash": "^4.17.21",
"mobx": "^6.10.1",
"mobx": "^6.10.2",
"mobx-i18n": "^0.4.1",
"mobx-react": "^9.0.1",
"mobx-restful": "^0.6.11",
"mobx-restful-table": "^1.1.2",
"open-react-map": "^0.6.1",
"open-react-map": "^0.6.3",
"react": "^17.0.2",
"react-bootstrap": "^2.8.0",
"react-dom": "^17.0.2",
Expand All @@ -28,7 +28,7 @@
"@parcel/transformer-less": "~2.9.3",
"@parcel/transformer-webmanifest": "~2.9.3",
"@types/lodash": "^4.14.197",
"@types/node": "^18.17.12",
"@types/node": "^18.17.13",
"@types/react": "^17.0.65",
"@types/react-dom": "^17.0.20",
"husky": "^8.0.3",
Expand Down
106 changes: 61 additions & 45 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions src/component/AutoMap.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
import { Loading } from 'idea-react';
import { observer } from 'mobx-react';
import { OpenReactMap, OpenReactMapProps } from 'open-react-map';
import {
AddressLocation,
OpenReactMap,
OpenReactMapModel,
OpenReactMapProps
} from 'open-react-map';
import { PureComponent } from 'react';

import mapStore, { AddressLocation, MapModel } from '../model/Map';

export interface AutoMapProps extends OpenReactMapProps {
onLoad?: (
coordinate: MapModel['currentCoord'],
coordinate: OpenReactMapModel['currentLocation'],
address: AddressLocation,
addressText: string
) => any;
}

@observer
export class AutoMap extends PureComponent<AutoMapProps> {
mapStore = new OpenReactMapModel();

async componentDidMount() {
await mapStore.getAddress(...(await mapStore.getCoord()));
const { mapStore } = this;

await mapStore.reverse(...(await mapStore.locate()));

this.props.onLoad?.(
mapStore.currentCoord,
mapStore.currentAddress,
mapStore.currentAddressText
mapStore.currentLocation,
mapStore.reversedAddress,
mapStore.reversedAddressText
);
}

render() {
const { currentCoord, currentAddressText } = mapStore;
const { currentLocation, reversedAddressText } = this.mapStore;

return currentCoord && currentAddressText ? (
return currentLocation && reversedAddressText ? (
<OpenReactMap
center={currentCoord}
center={currentLocation}
zoom={18}
markers={[
{
position: currentCoord,
tooltip: currentAddressText
position: currentLocation,
tooltip: reversedAddressText
}
]}
{...this.props}
Expand Down
Loading

1 comment on commit 5566cfd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for wiki-map ready!

✅ Preview
https://wiki-bmsqshpke-techquery.vercel.app

Built with commit 5566cfd.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.