app loads configuration from json at runtime

This commit is contained in:
geoffsee
2025-06-30 11:17:25 -04:00
parent 31bb3b336b
commit 08fb45dbaf
9 changed files with 275 additions and 84 deletions

View File

@@ -1,5 +1,7 @@
package org.example
import kotlinx.serialization.json.Json
fun main() {
println("OSM Maker - Wasm Version")
println("This is a WebAssembly-compiled version of the OSM processing application.")
@@ -13,16 +15,49 @@ fun main() {
// 2. Use browser APIs for file operations
// 3. Use WebGL or similar for 3D rendering instead of generating GLB files
val bbox = "37.115,-76.396,37.139,-76.345" // Poquoson, VA bounding box
// For demo purposes, we'll use a default configuration
// In a real implementation, you would fetch config.json via browser fetch API
val defaultConfig = Config(
osmData = OsmDataConfig(
useLocalExtract = false,
localFilePath = "virginia.osm.pbf",
boundingBox = BoundingBoxConfig(
south = 37.115,
west = -76.396,
north = 37.139,
east = -76.345,
description = "Poquoson, VA"
),
overpassTimeout = 25
),
projection = ProjectionConfig(
origin = OriginConfig(
latitude = 37.120907,
longitude = -76.333694
)
),
output = OutputConfig(
fileName = "municipality.glb",
autoOpen = true
)
)
println("Configuration loaded:")
println(" Area: ${defaultConfig.osmData.boundingBox.description}")
println(" Use local extract: ${defaultConfig.osmData.useLocalExtract}")
println(" Output file: ${defaultConfig.output.fileName}")
val bbox = "${defaultConfig.osmData.boundingBox.south},${defaultConfig.osmData.boundingBox.west},${defaultConfig.osmData.boundingBox.north},${defaultConfig.osmData.boundingBox.east}"
println("Processing OSM data for bounding box: $bbox")
// Simulate processing
processOsmData(bbox)
processOsmData(defaultConfig)
println("Wasm compilation successful! Check browser console for output.")
}
fun processOsmData(bbox: String) {
fun processOsmData(config: Config) {
val bbox = "${config.osmData.boundingBox.south},${config.osmData.boundingBox.west},${config.osmData.boundingBox.north},${config.osmData.boundingBox.east}"
println("Simulating OSM data processing for bbox: $bbox")
// In a real implementation, this would:
@@ -30,24 +65,19 @@ fun processOsmData(bbox: String) {
// - Process the data using Wasm-compatible libraries
// - Render 3D output using WebGL
val coordinates = bbox.split(",")
if (coordinates.size == 4) {
val south = coordinates[0].toDoubleOrNull()
val west = coordinates[1].toDoubleOrNull()
val north = coordinates[2].toDoubleOrNull()
val east = coordinates[3].toDoubleOrNull()
val boundingBox = config.osmData.boundingBox
println("Parsed coordinates from configuration:")
println(" South: ${boundingBox.south}")
println(" West: ${boundingBox.west}")
println(" North: ${boundingBox.north}")
println(" East: ${boundingBox.east}")
if (south != null && west != null && north != null && east != null) {
println("Parsed coordinates:")
println(" South: $south")
println(" West: $west")
println(" North: $north")
println(" East: $east")
val area = (boundingBox.north - boundingBox.south) * (boundingBox.east - boundingBox.west)
println(" Approximate area: $area square degrees")
val area = (north - south) * (east - west)
println(" Approximate area: $area square degrees")
}
}
println("Projection origin: ${config.projection.origin.latitude}, ${config.projection.origin.longitude}")
println("Output file would be: ${config.output.fileName}")
println("Auto-open enabled: ${config.output.autoOpen}")
println("OSM data processing simulation complete.")
}