diff --git a/lib/__snapshots__/index.test.ts.snap b/lib/__snapshots__/index.test.ts.snap index d762bd2..c21f189 100644 --- a/lib/__snapshots__/index.test.ts.snap +++ b/lib/__snapshots__/index.test.ts.snap @@ -12769,6 +12769,12 @@ exports[`toGeoJSON > ground_overlay.kml 1`] = ` { "features": [ { + "bbox": [ + 14.60128369746704, + 37.46543388598137, + 15.35832653742206, + 37.91904192681665, + ], "geometry": { "coordinates": [ [ @@ -12816,6 +12822,12 @@ exports[`toGeoJSON > ground_overlay.kml 2`] = ` { "children": [ { + "bbox": [ + 14.60128369746704, + 37.46543388598137, + 15.35832653742206, + 37.91904192681665, + ], "geometry": { "coordinates": [ [ diff --git a/lib/kml/ground_overlay.ts b/lib/kml/ground_overlay.ts index 7c3c59f..b846e3e 100644 --- a/lib/kml/ground_overlay.ts +++ b/lib/kml/ground_overlay.ts @@ -11,14 +11,21 @@ import { import { extractIconHref, extractStyle } from "./extractStyle"; import { coord, fixRing, getCoordinates } from "./geometry"; -function getGroundOverlayBox(node: Element): Polygon | null { +interface BoxGeometry { + bbox?: BBox; + geometry: Polygon; +} + +function getGroundOverlayBox(node: Element): BoxGeometry | null { const latLonQuad = get1(node, "gx:LatLonQuad"); if (latLonQuad) { const ring = fixRing(coord(getCoordinates(node))); return { - type: "Polygon", - coordinates: [ring], + geometry: { + type: "Polygon", + coordinates: [ring], + }, }; } @@ -51,7 +58,7 @@ function rotateBox( ]; } -function getLatLonBox(node: Element): Polygon | null { +function getLatLonBox(node: Element): BoxGeometry | null { const latLonBox = get1(node, "LatLonBox"); if (latLonBox) { @@ -81,8 +88,11 @@ function getLatLonBox(node: Element): Polygon | null { coordinates = rotateBox(bbox, coordinates, rotation); } return { - type: "Polygon", - coordinates, + bbox, + geometry: { + type: "Polygon", + coordinates, + }, }; } } @@ -95,11 +105,11 @@ export function getGroundOverlay( styleMap: StyleMap, schema: Schema ): Feature { - const geometry = getGroundOverlayBox(node); + const box = getGroundOverlayBox(node); const feature: Feature = { type: "Feature", - geometry, + geometry: box?.geometry || null, properties: Object.assign( /** * Related to @@ -124,6 +134,10 @@ export function getGroundOverlay( ), }; + if (box?.bbox) { + feature.bbox = box.bbox; + } + if (feature.properties?.visibility !== undefined) { feature.properties.visibility = feature.properties.visibility !== "0"; }