Skip to content
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

loading class #339

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions react/src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export interface MapGenericProps {

export type Polygons = Readonly<[string[], Record<string, unknown>[], Record<string, unknown>[], number]>

interface MapState {
loading: boolean
}

// eslint-disable-next-line prefer-function-component/prefer-function-component -- TODO: Maps don't support function components yet.
export class MapGeneric<P extends MapGenericProps> extends React.Component<P> {
export class MapGeneric<P extends MapGenericProps> extends React.Component<P, MapState> {
private polygon_by_name = new Map<string, L.FeatureGroup>()
private delta = 0.25
private version = 0
Expand All @@ -36,11 +40,12 @@ export class MapGeneric<P extends MapGenericProps> extends React.Component<P> {
constructor(props: P) {
super(props)
this.id = `map-${Math.random().toString(36).substring(2)}`
this.state = { loading: true }
}

override render(): ReactNode {
return (
<div className="map-container-for-testing">
<div className={`map-container-for-testing${this.state.loading ? ' map-container-loading-for-testing' : ''}`}>
<div id={this.id} className="map" style={{ background: '#fff8f0', height: this.props.height ?? 400 }}>
{/* place this on the right of the map */}
<div style={
Expand Down Expand Up @@ -202,6 +207,8 @@ export class MapGeneric<P extends MapGenericProps> extends React.Component<P> {
}

async updateFn(): Promise<void> {
this.setState({ loading: true })

const map = this.map!
this.exist_this_time = []

Expand All @@ -220,6 +227,7 @@ export class MapGeneric<P extends MapGenericProps> extends React.Component<P> {
this.polygon_by_name.delete(name)
}
}
this.setState({ loading: false })
}

attachBasemap(): void {
Expand Down