-
Describe the bug I'm playing with MapLibre native library for ios and I get non-working behaviour. When I try using local mbtiles on iOS simulator, I get blank maps. Compass is visible, scale is visible, but the actual map contents are not. The tiles I'm using were downloaded from https://data.maptiler.com/downloads/tileset/osm/europe/poland/, but it doesn't matter which one I try. MapView.swift:
osmbright.json:
In debug panel in Xcode there is one message only: "will start rendering" which comes from this function:
I have not entered any key, because I'm using local files only. Platform information
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Stupid iOS question, but can the iOS simulator read from the local file system? |
Beta Was this translation helpful? Give feedback.
-
Afaik no |
Beta Was this translation helpful? Give feedback.
-
it can, it does read and print the contents of the files. Checked already |
Beta Was this translation helpful? Give feedback.
-
@prawel Yes you are right, since the style is definitely loaded from the local filesystem. I am not sure if the style syntax of the source is correct. See this comment: Definitely needs to be better documented. |
Beta Was this translation helpful? Give feedback.
-
unfortunately, this is not the case, it didn't change much. |
Beta Was this translation helpful? Give feedback.
-
Here is my attempt that appears to work. Very hackey and would love any suggestions to improve. struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MGLMapView {
let mapView = MGLMapView(frame: .zero)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.delegate = context.coordinator
guard let localMbtiles = Bundle.main.url(forResource: "APT_BASE", withExtension: "mbtiles") else {
fatalError("Failed to find the style file.")
}
guard let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") else {
fatalError("Failed to find the style file.")
}
// Load the style.json template from your bundle
if let path = Bundle.main.path(forResource: "style", ofType: "json") {
do {
var styleJSON = try String(contentsOfFile: path, encoding: .utf8)
// let localMbString = localMb.absoluteString
styleJSON = styleJSON.replacingOccurrences(of: "{{LOCAL_FILE_NAME}}", with: localMbtiles.path)
let temporaryDirectory = FileManager.default.temporaryDirectory
let temporaryFileURL = temporaryDirectory.appendingPathComponent("temp_style.json")
try styleJSON.write(to: temporaryFileURL, atomically: true, encoding: .utf8)
// Set the temporary file's URL as the mapView.styleURL
mapView.styleURL = temporaryFileURL
} catch {
print("Error loading style.json template: \(error)")
}
}
... Style.json section:
|
Beta Was this translation helpful? Give feedback.
Here is my attempt that appears to work. Very hackey and would love any suggestions to improve.
style.json
andAPT_BASE.mbtiles
are bundled with the app. Definitely open to suggestions but this does work for me. Essentially it is grabbing the mbtiles location and runtime, and rewriting the style.json with that value.