mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
updates - compressed overlay data
This commit is contained in:
parent
6adefdb3aa
commit
64c96ccb94
3 changed files with 6 additions and 44 deletions
|
|
@ -16,55 +16,32 @@ class GeoJSONOverlayManager {
|
|||
}
|
||||
|
||||
guard let url = Bundle.main.url(forResource: "BurningManGeoJSONMapConfig", withExtension: "json.zlib") else {
|
||||
print("GeoJSONOverlayManager: No compressed configuration file found")
|
||||
return nil
|
||||
}
|
||||
|
||||
do {
|
||||
let compressedData = try Data(contentsOf: url)
|
||||
print("GeoJSONOverlayManager: Loaded compressed data size: \(compressedData.count) bytes")
|
||||
|
||||
let decompressedData = try compressedData.zlibDecompressed()
|
||||
print("GeoJSONOverlayManager: Decompressed data size: \(decompressedData.count) bytes")
|
||||
|
||||
// Debug: Check the first few characters of decompressed data
|
||||
if let decompressedString = String(data: decompressedData, encoding: .utf8) {
|
||||
let firstChars = String(decompressedString.prefix(100))
|
||||
print("GeoJSONOverlayManager: First 100 chars of decompressed data: \(firstChars)")
|
||||
} else {
|
||||
print("GeoJSONOverlayManager: Decompressed data is not valid UTF-8")
|
||||
// Show first few bytes as hex
|
||||
let firstBytes = decompressedData.prefix(20).map { String(format: "%02x", $0) }.joined()
|
||||
print("GeoJSONOverlayManager: First 20 bytes (hex): \(firstBytes)")
|
||||
}
|
||||
|
||||
let config = try JSONDecoder().decode(GeoJSONOverlayConfiguration.self, from: decompressedData)
|
||||
print("GeoJSONOverlayManager: Loaded configuration with \(config.overlays.count) overlays")
|
||||
|
||||
configuration = config
|
||||
return config
|
||||
} catch {
|
||||
print("GeoJSONOverlayManager: Failed to load configuration: \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// Load overlays for a specific overlay ID
|
||||
func loadOverlays(for overlayId: String) -> [MKOverlay] {
|
||||
print("GeoJSONOverlayManager: Attempting to load overlays for \(overlayId)")
|
||||
|
||||
if let cached = overlays[overlayId] {
|
||||
print("GeoJSONOverlayManager: Returning cached overlays for \(overlayId), count: \(cached.count)")
|
||||
return cached
|
||||
}
|
||||
|
||||
guard let config = loadConfiguration() else {
|
||||
print("GeoJSONOverlayManager: Failed to load configuration")
|
||||
return []
|
||||
}
|
||||
|
||||
guard let overlayDef = config.overlays.first(where: { $0.id == overlayId }) else {
|
||||
print("GeoJSONOverlayManager: No overlay found for ID: \(overlayId)")
|
||||
return []
|
||||
}
|
||||
|
||||
|
|
@ -78,48 +55,35 @@ class GeoJSONOverlayManager {
|
|||
"geometry": [
|
||||
"type": feature.geometry.type,
|
||||
"coordinates": feature.geometry.coordinates.toAnyObject()
|
||||
]
|
||||
],
|
||||
"properties": [:]
|
||||
]
|
||||
|
||||
if let id = feature.id {
|
||||
featureDict["id"] = id
|
||||
}
|
||||
|
||||
if let properties = feature.properties {
|
||||
featureDict["properties"] = properties.mapValues { $0.toAnyObject() }
|
||||
}
|
||||
|
||||
return featureDict
|
||||
}
|
||||
]
|
||||
|
||||
let geojsonData = try JSONSerialization.data(withJSONObject: standardGeoJSON)
|
||||
let features = try MKGeoJSONDecoder().decode(geojsonData)
|
||||
print("GeoJSONOverlayManager: Decoded \(features.count) features for \(overlayId)")
|
||||
|
||||
var allOverlays: [MKOverlay] = []
|
||||
for (index, feature) in features.enumerated() {
|
||||
if let mkFeature = feature as? MKGeoJSONFeature {
|
||||
print("GeoJSONOverlayManager: Feature \(index) has \(mkFeature.geometry.count) geometries")
|
||||
for (geoIndex, geometry) in mkFeature.geometry.enumerated() {
|
||||
print("GeoJSONOverlayManager: Geometry \(geoIndex): \(Swift.type(of: geometry))")
|
||||
if let overlay = geometry as? MKOverlay {
|
||||
allOverlays.append(overlay)
|
||||
print("GeoJSONOverlayManager: Added as overlay")
|
||||
} else {
|
||||
print("GeoJSONOverlayManager: Could not cast to MKOverlay")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print("GeoJSONOverlayManager: Feature \(index) could not be cast to MKGeoJSONFeature")
|
||||
}
|
||||
}
|
||||
|
||||
print("GeoJSONOverlayManager: Created \(allOverlays.count) total overlays for \(overlayId)")
|
||||
overlays[overlayId] = allOverlays
|
||||
overlays[overlayId] = allOverlays
|
||||
return allOverlays
|
||||
} catch {
|
||||
print("GeoJSONOverlayManager: Failed to decode overlays for \(overlayId): \(error)")
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -231,18 +231,16 @@ struct MeshMapContent: MapContent {
|
|||
}
|
||||
}
|
||||
|
||||
/// GeoJSON Overlays (Configuration-Driven)
|
||||
/// GeoJSON Overlays (Configuration-Driven)
|
||||
if showBurningMan {
|
||||
let overlayManager = GeoJSONOverlayManager.shared
|
||||
let availableOverlays = overlayManager.getAvailableOverlayIds()
|
||||
|
||||
ForEach(availableOverlays, id: \.self) { overlayId in
|
||||
ForEach(Array(availableOverlays.enumerated()), id: \.element) { _, overlayId in
|
||||
let overlays = overlayManager.loadOverlays(for: overlayId)
|
||||
let rendering = overlayManager.getRenderingProperties(for: overlayId)
|
||||
|
||||
ForEach(overlays.map { IdentifiableOverlay(overlay: $0) }) { identifiable in
|
||||
let overlay = identifiable.overlay
|
||||
|
||||
ForEach(Array(overlays.enumerated()), id: \.offset) { _, overlay in
|
||||
if let polygon = overlay as? MKPolygon {
|
||||
MapPolygon(polygon)
|
||||
.stroke(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue