-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
象数
committed
Dec 9, 2024
1 parent
50cbb53
commit c21960d
Showing
8 changed files
with
120 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useScene } from '@antv/larkmap'; | ||
import { useEffect } from 'react'; | ||
import type { Map } from '../../types/map'; | ||
import { fitBounds, setMapStatus, setMapView } from '../../utils/map'; | ||
|
||
// 更新地图视野 | ||
export default (props: Map) => { | ||
const scene = useScene(); | ||
useEffect(() => { | ||
setMapView(props, scene); | ||
}, []); | ||
useEffect(() => { | ||
setMapStatus(props, scene); | ||
}, [props.enableRotate, props.enableScroll, props.enableZoom]); | ||
useEffect(() => { | ||
fitBounds(props, scene); | ||
}, [props.includePoints, props.markers, props.polyline, props.includePadding]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { ILayer } from '@antv/l7'; | ||
import { useScene } from '@antv/larkmap'; | ||
import { useEffect, useState } from 'react'; | ||
import type { Map } from '../../types/map'; | ||
import { setMapContext, setMarkers } from '../../utils/map'; | ||
// 更新地图视野 | ||
export default (props: Map) => { | ||
const scene = useScene(); | ||
const [layers, setLayers] = useState<ILayer[]>([]); | ||
const removeLayers = () => { | ||
layers.forEach((item) => { | ||
scene.removeLayer(item); | ||
}); | ||
}; | ||
useEffect(() => { | ||
if (!props.markers) return; | ||
// 异步调用 | ||
setMapContext(props, scene)?.then(() => { | ||
// 初始化资源 | ||
const markerLayer = setMarkers(props.markers || []); | ||
removeLayers(); | ||
markerLayer.forEach((item) => { | ||
scene.addLayer(item); | ||
}); | ||
setLayers(markerLayer); | ||
}); | ||
return () => { | ||
removeLayers(); | ||
}; | ||
}, [props.markers]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ILayer } from '@antv/l7'; | ||
import { useScene } from '@antv/larkmap'; | ||
import { useEffect, useState } from 'react'; | ||
import type { Map } from '../../types/map'; | ||
import { setPolyline } from '../../utils/map'; | ||
// 更新地图视野 | ||
export default (props: Map) => { | ||
const scene = useScene(); | ||
const [layers, setLayers] = useState<ILayer[]>([]); | ||
const removeLayers = () => { | ||
layers.forEach((item) => { | ||
scene.removeLayer(item); | ||
}); | ||
}; | ||
useEffect(() => { | ||
if (!props.polyline) return; | ||
const lineLayers = setPolyline(props.polyline || []); | ||
removeLayers(); | ||
console.log('lineLayers', lineLayers); | ||
lineLayers.forEach((item) => { | ||
scene.addLayer(item); | ||
}); | ||
setLayers(lineLayers); | ||
|
||
return () => { | ||
removeLayers(); | ||
}; | ||
}, [props.polyline]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import MapView from './MapView'; | ||
import Marker from './Marker'; | ||
import Polyline from './Polyline'; | ||
|
||
export { MapView, Marker, Polyline }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters