Skip to content

Commit

Permalink
feat: Produce a bbox property for GroundOverlays with LatLonBox eleme…
Browse files Browse the repository at this point in the history
…nts (#113)
  • Loading branch information
tmcw authored Jun 22, 2023
1 parent d395dde commit e110459
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12769,6 +12769,12 @@ exports[`toGeoJSON > ground_overlay.kml 1`] = `
{
"features": [
{
"bbox": [
14.60128369746704,
37.46543388598137,
15.35832653742206,
37.91904192681665,
],
"geometry": {
"coordinates": [
[
Expand Down Expand Up @@ -12816,6 +12822,12 @@ exports[`toGeoJSON > ground_overlay.kml 2`] = `
{
"children": [
{
"bbox": [
14.60128369746704,
37.46543388598137,
15.35832653742206,
37.91904192681665,
],
"geometry": {
"coordinates": [
[
Expand Down
30 changes: 22 additions & 8 deletions lib/kml/ground_overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
};
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -81,8 +88,11 @@ function getLatLonBox(node: Element): Polygon | null {
coordinates = rotateBox(bbox, coordinates, rotation);
}
return {
type: "Polygon",
coordinates,
bbox,
geometry: {
type: "Polygon",
coordinates,
},
};
}
}
Expand All @@ -95,11 +105,11 @@ export function getGroundOverlay(
styleMap: StyleMap,
schema: Schema
): Feature<Polygon | null> {
const geometry = getGroundOverlayBox(node);
const box = getGroundOverlayBox(node);

const feature: Feature<Polygon | null> = {
type: "Feature",
geometry,
geometry: box?.geometry || null,
properties: Object.assign(
/**
* Related to
Expand All @@ -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";
}
Expand Down

0 comments on commit e110459

Please sign in to comment.