-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
fc9a76a
commit c451241
Showing
13 changed files
with
19 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,100 +1,7 @@ | ||
import type { Feature, Point, Position } from "geojson"; | ||
import type { | ||
DataDrivenPropertyValueSpecification, | ||
ExpressionSpecification, | ||
} from "maplibre-gl"; | ||
|
||
export { default as BasemapPicker } from "./BasemapPicker.svelte"; | ||
export { default as DisableInteractiveLayers } from "./DisableInteractiveLayers.svelte"; | ||
export { default as Layout } from "./Layout.svelte"; | ||
export { default as Link } from "./Link.svelte"; | ||
export { default as Popup } from "./Popup.svelte"; | ||
export { default as StreetView } from "./StreetView.svelte"; | ||
export { layerId } from "./zorder"; | ||
|
||
export const isPolygon: ExpressionSpecification = [ | ||
"==", | ||
["geometry-type"], | ||
"Polygon", | ||
]; | ||
export const isLine: ExpressionSpecification = [ | ||
"==", | ||
["geometry-type"], | ||
"LineString", | ||
]; | ||
export const isPoint: ExpressionSpecification = [ | ||
"==", | ||
["geometry-type"], | ||
"Point", | ||
]; | ||
|
||
export function constructMatchExpression<OutputType>( | ||
getter: any[], | ||
map: { [name: string]: OutputType }, | ||
fallback: OutputType, | ||
): DataDrivenPropertyValueSpecification<OutputType> { | ||
let x: any[] = ["match", getter]; | ||
for (let [key, value] of Object.entries(map)) { | ||
x.push(key); | ||
x.push(value); | ||
} | ||
x.push(fallback); | ||
return x as DataDrivenPropertyValueSpecification<OutputType>; | ||
} | ||
|
||
// Helper for https://maplibre.org/maplibre-style-spec/expressions/#step. | ||
export function makeColorRamp( | ||
input: DataDrivenPropertyValueSpecification<number>, | ||
limits: number[], | ||
colorScale: string[], | ||
): DataDrivenPropertyValueSpecification<string> { | ||
let step: any[] = ["step", input]; | ||
for (let i = 1; i < limits.length; i++) { | ||
step.push(colorScale[i - 1]); | ||
step.push(limits[i]); | ||
} | ||
// Repeat the last color. The upper limit is exclusive, meaning a value | ||
// exactly equal to it will use this fallback. For things like percentages, | ||
// we want to set 100 as the cap. | ||
step.push(colorScale[colorScale.length - 1]); | ||
return step as DataDrivenPropertyValueSpecification<string>; | ||
} | ||
|
||
export function downloadGeneratedFile(filename: string, textInput: string) { | ||
let element = document.createElement("a"); | ||
element.setAttribute( | ||
"href", | ||
"data:text/plain;charset=utf-8," + encodeURIComponent(textInput), | ||
); | ||
element.setAttribute("download", filename); | ||
document.body.appendChild(element); | ||
element.click(); | ||
document.body.removeChild(element); | ||
} | ||
|
||
// Hack around | ||
// https://stackoverflow.com/questions/67336062/typescript-not-parsed-in-svelte-html-section | ||
// until we're using Svelte 5 | ||
export function notNull<T>(x: T | null | undefined): T { | ||
if (x == null || x == undefined) { | ||
throw new Error("Oops, notNull given something null"); | ||
} | ||
return x; | ||
} | ||
|
||
export function pointFeature(pt: Position): Feature<Point> { | ||
return { | ||
type: "Feature", | ||
properties: {}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: setPrecision(pt), | ||
}, | ||
}; | ||
} | ||
|
||
// Per https://datatracker.ietf.org/doc/html/rfc7946#section-11.2, 6 decimal | ||
// places (10cm) is plenty of precision | ||
export function setPrecision(pt: Position): Position { | ||
return [Math.round(pt[0] * 10e6) / 10e6, Math.round(pt[1] * 10e6) / 10e6]; | ||
} |
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
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