clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

feat/atlas-next-horizon
atlas / format / vnext / roundtrip_test.go
roundtrip_test.go 3.5K
1package vnext23import (4 "bytes"5 "testing"6)78func TestVolumeTravelsFromDomainThroughBundleToPresentation(t *testing.T) {9 t.Parallel()1011 emergency := Field{12 ID: IDFromName("com.example.emergency", "feature.level"),13 Name: "emergencyLevel",14 Kind: KindInt64,15 Optional: true,16 }17 volume := Volume{18 ID: "bend-or",19 Title: "Bend, Oregon",20 Worlds: []World{{21 ID: "2026-08-01",22 Title: "2026-08-01",23 CoordinateSpace: CoordinateSpace{24 ID: "bend-web-mercator",25 Kind: "projected",26 Unit: "metre",27 Definition: "EPSG:3857",28 Extent: [4]float64{-13500000, 5400000, -13400000, 5500000},29 SourceZoom: 13,30 TileSize: 256,31 Size: 8192,32 },33 FeatureSets: []FeatureSet{{34 ID: "hospitals",35 Title: "Hospitals",36 SemanticType: "healthcare.hospital",37 Properties: []Field{emergency},38 Features: []Feature{{39 ID: "osm/node/1842",40 Title: "St. Charles Bend",41 Geometry: Geometry{42 Kind: GeometryPoint,43 Parts: []GeometryPart{{Rings: [][]Position{{{-121.2691, 44.0671}}}}},44 },45 Properties: []Property{{FieldID: emergency.ID, Value: Int64Value(4)}},46 Relationships: []Relationship{{Predicate: "within", Target: "bend-or"}},47 Provenance: []Provenance{{Source: "openstreetmap", NativeID: "node/1842", CapturedAt: "2026-08-01T20:13:08Z"}},48 }},49 }},50 RasterPyramids: []RasterPyramid{{51 ID: "streets", Name: "Streets", Codec: "image/webp", TileSize: 256, MinZoom: 0, MaxZoom: 13, FullZoom: 13, SourceZoom: 13,52 Template: "rasters/streets/{z}/{x}/{y}.webp",53 Formats: []string{"webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp", "webp"},54 }},55 Presentation: Presentation{56 ID: "default", Title: "Default",57 Styles: []Style{{ID: "hospital", Symbol: "asset:hospital", Fill: "#bc3b4a"}},58 Layers: []Layer{{ID: "services-hospitals", FeatureSet: "hospitals", Style: "hospital", Visible: true, Order: 30, MinZoom: 8, MaxZoom: 22}},59 Legend: []LegendEntry{{Layer: "services-hospitals", Label: "Hospitals", Order: 10}},60 },61 }},62 Assets: []Asset{{ID: "hospital", MediaType: "image/svg+xml", Data: []byte("<svg/>"), Provenance: "custom"}},63 }6465 packed, err := Compile(volume)66 if err != nil {67 t.Fatalf("compile volume: %v", err)68 }69 packed.Release.CreatedAt = "2026-08-01T20:13:08Z"70 var archive bytes.Buffer71 if err := Write(&archive, packed); err != nil {72 t.Fatalf("write bundle: %v", err)73 }74 opened, err := Open(bytes.NewReader(archive.Bytes()), int64(archive.Len()), StandardSchema())75 if err != nil {76 t.Fatalf("open bundle: %v", err)77 }78 restored, err := opened.Volume()79 if err != nil {80 t.Fatalf("restore domain volume: %v", err)81 }82 if restored.ID != volume.ID || restored.Worlds[0].CoordinateSpace.Definition != "EPSG:3857" {83 t.Fatalf("restored wrong volume: %#v", restored)84 }85 if got := restored.Worlds[0].FeatureSets[0].Features[0].Properties[0].Value.Int64; got != 4 {86 t.Fatalf("typed extension property = %d, want 4", got)87 }88 if got := string(restored.Assets[0].Data); got != "<svg/>" {89 t.Fatalf("asset = %q", got)90 }9192 presented, err := Present(restored.Worlds[0])93 if err != nil {94 t.Fatalf("present world: %v", err)95 }96 if len(presented) != 1 {97 t.Fatalf("presented %d features, want 1", len(presented))98 }99 if got := presented[0]; got.FeatureID != "osm/node/1842" || got.LayerID != "services-hospitals" || got.Symbol != "asset:hospital" || got.Legend != "Hospitals" {100 t.Fatalf("presented feature = %#v", got)101 }102}