Cmen
3 years ago
6 changed files with 38 additions and 7 deletions
@ -1 +1,30 @@ |
|||||||
|
import { OverlayTypes } from "@types"; |
||||||
|
|
||||||
export * from "./hotkeys"; |
export * from "./hotkeys"; |
||||||
|
|
||||||
|
export function getOverlayPaths(target: AMap.MapOverlay, type: OverlayTypes) { |
||||||
|
if (type === OverlayTypes.Rectangle) { |
||||||
|
const overlay = target as AMap.Rectangle; |
||||||
|
const bounds = overlay.getBounds(); |
||||||
|
const [west, south, east, north] = getBBox(bounds!); |
||||||
|
return [ |
||||||
|
[west, south], |
||||||
|
[west, north], |
||||||
|
[east, north], |
||||||
|
[east, south], |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
const overlay = target as AMap.Polygon | AMap.Polyline; |
||||||
|
return overlay.getPath()?.map((path) => { |
||||||
|
const lngLat = path as AMap.LngLat; |
||||||
|
return [lngLat.lng, lngLat.lat] || []; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
function getBBox(bounds: AMap.Bounds) { |
||||||
|
const { northEast, southWest } = bounds; |
||||||
|
let { lng: east, lat: north } = northEast; |
||||||
|
let { lng: west, lat: south } = southWest; |
||||||
|
return [west, south, east, north]; |
||||||
|
} |
||||||
|
Loading…
Reference in new issue