Skip to main content

Your first map

This walkthrough puts an interactive map on screen. It assumes you have installed the SDK.

Put the view on screen

res/layout/main.xml
<com.massifmaps.ui.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

Then build the map

The surface API is the shortest way in and the one every example is written against: a layer is a JSON spec, and the same code reads the same in every language.

val map = MassifMap.attach(mapView)

map.addLayer("basemap", Spec.of("vector")
.set("source", Spec.of("http")
.set("url", "https://example.com/tiles/{z}/{x}/{y}.pbf")
.set("maxZoom", 14))
.set("style", Spec.of("mbvt")
.set("cartocss", Spec.of("cartocss").set("css", "#water { polygon-fill: #9cc3e0; }"))))

// Longitude first, in degrees — no projection conversion to get wrong.
map.camera().moveTo(Position(-0.8164, 51.2131), 5.0)

Any {z}/{x}/{y}.pbf endpoint on the OpenMapTiles schema works. For a real style, point at a style project instead of inline CartoCSS — see style sets, and the style CLI if you are converting one from MapBox.

The same thing with the object API

The classic class-per-capability API is still fully supported, and is what the Javadoc / Jazzy reference documents.

val source = HTTPTileDataSource(0, 14, "https://example.com/tiles/{z}/{x}/{y}.pbf")
val style = CartoCSSStyleSet("#water { polygon-fill: #9cc3e0; }")
val baseLayer = VectorTileLayer(source, MBVectorTileDecoder(style))
mapView.layers.add(baseLayer)

// Coordinates are in the layer's projection (EPSG:3857 by default), so they need converting.
val proj = baseLayer.dataSource.projection
mapView.setFocusPos(proj.fromWgs84(MapPos(-0.8164, 51.2131)), 0f)
mapView.setZoom(5f, 0f)
Naming across platforms

The object API is generated by SWIG, so class names map 1:1 across languages with a platform prefix or namespace:

ConceptAndroid (Java/Kotlin)iOS (Objective-C/Swift)
Map viewcom.massifmaps.ui.MapViewMSFMapView
Positioncom.massifmaps.core.MapPosMSFMapPos
Vector tile layercom.massifmaps.layers.VectorTileLayerMSFVectorTileLayer

The surface API has no such split — an id and a spec are the same string everywhere.

Where to go from here

  • Examples — every one is a single file, in Java, Objective-C and TypeScript.
  • Surface API — ids, specs, paths and events, and the generated reference.
  • Vector objects — markers, lines, polygons, popups.
  • Offline maps — MBTiles, PMTiles and packaged tiles.
  • Features — 3D terrain, contours, hillshade and more.