Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MVT Playground example #14

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions mvt-tools.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import MVTTools

/*
```console
# Download from MapLibre a vector tile at zoom 2, with an extent showing Norway to India
wget https://demotiles.maplibre.org/tiles/2/2/1.pbf
```
*/
//: Set the path to the `.pbf` file in `<playground>/Resources`
let playgroundFile = "maplibre.org_2_2_1.pbf"
let fileURL = Bundle.main.url(forResource: playgroundFile, withExtension: nil)!
let mvtData = try Data(contentsOf: fileURL)

//: Load tile using MVT
let tile = VectorTile(data: mvtData, x: 2, y: 1, z: 2, indexed: .hilbert)!

//: Inspect the properties of the `VectorTile`
tile.isIndexed
tile.projection

print(tile.layerNames.sorted())
//: ### MapLibre ZXY = 2/2/1 — Layers: ["centroids", "countries", "geolines"]
//: ![](maplibre.org_2_2_1.png)
//: ---
//: ### OpenStreetMap ZXY = 2/2/1
//: ![](openstreetmap.org_2_2_1.png)
1 change: 1 addition & 0 deletions mvt-tools.playground/Resources/get_vector_tile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wget https://demotiles.maplibre.org/tiles/2/2/1.pbf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions mvt-tools.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' display-mode='rendered' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>
Loading