Skip to content

Commit

Permalink
bug fix to load xmls
Browse files Browse the repository at this point in the history
  • Loading branch information
miya0001 committed Feb 9, 2023
1 parent e7aff8d commit 89e73c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
17 changes: 7 additions & 10 deletions src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@ import Log from './Log'
import './Home.scss';

interface XMLData {
name: string;
projection: string;
count: number;
geojson: GeoJSON.FeatureCollection;
id: string;
data: any;
resolve: Function;
}

const Home = () => {
const [ map, setMap ] = React.useState()
const [ id, setId ] = React.useState<string>('')
const [ data, setData ] = React.useState<XMLData>()
const [ geoJSONs, setGeoJSONs ] = React.useState<XMLData[]>([])

React.useEffect(() => {
if (id && data) {
setGeoJSONs(array => [data, ...array])
data.resolve(data.geojson)
if (data && data.data) {
setGeoJSONs(array => [data.data, ...array])
data.resolve(data.data.geojson)
}
}, [id, data])
}, [data])

return (
<div className='main'>
<Uploader className="uploader" map={map} dataCallback={setData} setid={setId}></Uploader>
<Uploader className="uploader" map={map} dataCallback={setData}></Uploader>
<Loading className='loading'></Loading>
<Map className="map" setmap={setMap} />
<Log className='log' geojsons={geoJSONs} map={map}></Log>
Expand Down
26 changes: 13 additions & 13 deletions src/Uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ interface Props {
className: string;
map: any;
dataCallback: Function;
setid: Function;
}

const Component = (props: Props) => {
Expand Down Expand Up @@ -137,26 +136,27 @@ const Component = (props: Props) => {
const count = _geojson.count || 0
const color = _geojson.color || ''

props.dataCallback({
name: name,
filename: filename,
projection: projection,
count: count,
geojson: geojson,
color: color,
resolve: resolve,
await props.dataCallback(() => {
return {
id: id,
data: {
name: name,
filename: filename,
projection: projection,
count: count,
geojson: geojson,
color: color,
},
resolve: resolve,
}
})

props.setid(id)

if ('任意座標系' !== projection) {
if (! props.map.getSource(id)) {
const simpleStyle = new window.geolonia.simpleStyle(geojson, {id: id}).addTo(props.map)
simpleStyle.updateData(geojson)
}
}

resolve(geojson)
}
}) // end Promise()

Expand Down

0 comments on commit 89e73c7

Please sign in to comment.