Skip to content

Commit

Permalink
Add MVT Playground example (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabs authored Feb 11, 2024
1 parent f19faad commit 6aab82d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
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>

0 comments on commit 6aab82d

Please sign in to comment.