Skip to content

Instantly share code, notes, and snippets.

View mousebird's full-sized avatar

Steve Gifford mousebird

View GitHub Profile
@mousebird
mousebird / maplibre_native_metal.md
Last active September 14, 2022 16:51
Stamen's Proposal for MapLibre Native Rendering Support

Who

Stamen is a design/technology company known for its data visualization and open work (e.g. Stamen Watercolor). SteveG consults for Stamen now and then on mobile and is known for another open source map toolkit (WhirlyGlobe-Maply) which made the transition to Metal years ago.

What

We're floating a proposal with some of Stamen's clients to upgrade MapLibre Native to:

  • Open up the rendering subsystem in MapLibre Native
  • Implement a Metal rendering module for iOS / MacOS
struct VertexArgBufferA {
const device Uniforms *uniforms [[ id(WKSUniformArgBuffer) ]];
const device UniformDrawStateA *uniDrawState [[ id(WKSUniformDrawStateArgBuffer) ]];
};
// Vertex shader for simple line on the globe
vertex ProjVertexA vertexLineOnly_globe(
VertexA vert [[stage_in]],
const device VertexArgBufferA & vertArgs [[buffer(WKSVertexArgBuffer)]])
{
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>openstreetmap buildings</Name>
<UserStyle>
<Name>normal</Name>
<FeatureTypeStyle>
<Rule>
<MinScaleDenominator>0</MinScaleDenominator>
<MaxScaleDenominator>13000</MaxScaleDenominator>
@mousebird
mousebird / Sticker.swift
Last active November 7, 2016 18:19
Smiley Face Stickers
func addStickers (_ arrayComp: NSArray , baseViewC: MaplyBaseViewController) {
// Pick up a smiley face image
let startImage = UIImage(named: "Smiley_Face_Avatar_by_PixelTwist")
var stickers = [MaplySticker]()
// Add a sticker for each input point
for object in arrayComp {
let sticker = MaplySticker()
let center = (object as! MaplyVectorObject).center()
static public CoordSystem MakeBNGCoordSystem(Activity activity, boolean displayVersion)
{
String projStr = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs";
Proj4CoordSystem coordSys = new Proj4CoordSystem(projStr);
// Set the bounding box for validity. It assumes it can go everywhere by default
Mbr bbox = new Mbr();
bbox.addPoint(new Point2d(1393.0196,13494.9764));
bbox.addPoint(new Point2d(671196.3657,1230275.0454));
// Add a marker for each point in a list of vectors
private void insertClusteredMarkers(List<VectorObject> vectors, MaplyBaseController inController)
{
// The markers will be 32x32 pixels
Point2d size = new Point2d(32, 32);
List<ScreenMarker> markers = new ArrayList<>();
Bitmap icon = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.sticker);
// For each vector object, add a marker in the middle
for (VectorObject v : vectors) {
// Set up a cache directory
String cacheDirName = "stamen_watercolor";
File cacheDir = new File(getActivity().getCacheDir(), cacheDirName);
cacheDir.mkdir();
// Set up the a remote tile source and point it at Stamen Watercolor
RemoteTileSource remoteTileSource = new RemoteTileSource(new RemoteTileInfo("http://tile.stamen.com/watercolor/", "png", 0, 18));
remoteTileSource.setCacheDir(cacheDir);
QuadImageTileLayer baseLayer = new QuadImageTileLayer(baseController, new SphericalMercatorCoordSystem(), remoteTileSource);
pod 'WhirlyGlobe', :http => 'https://s3-us-west-1.amazonaws.com/whirlyglobemaplydistribution/iOS_daily_builds/WhirlyGlobe-Maply_Nightly_latest.zip'
// A test case that displays an animated weather layer on top of
// the standard Geography Class basemap.
// This is part of the AutoTester in the WhirlyGlobe-Maply repo.
class AnimatedBasemapTestCase: MaplyTestCase {
// Use Geography Class as the base layer
let geographyClass = GeographyClassTestCase()
let cacheDir = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0]
var tileSources = [MaplyRemoteTileInfo]()
func createLayer(baseView: MaplyBaseViewController) -> (MaplyQuadImageTilesLayer) {
let precipTileSource = MaplyMultiplexTileSource(sources: tileSources)
// Create a precipitation layer that animates
let precipLayer = MaplyQuadImageTilesLayer(tileSource: precipTileSource!)
precipLayer?.imageDepth = UInt32(tileSources.count)
precipLayer?.animationPeriod = 1.0
precipLayer?.imageFormat = MaplyQuadImageFormat.ImageUByteRed
precipLayer?.numSimultaneousFetches = 4
precipLayer?.handleEdges = false
precipLayer?.coverPoles = false