Pascal and Mapbox

Part 1: The Road to Pascal


Contents

Introduction
Ways of doing cross-platform
One platform at a time

Part 2: macOS and Lazarus
Part 3: macOS and Xcode
Part 4: Pascal to JavaScript


Introduction

Mapbox is everywhere these days, or so it seems. Mapbox's JavaScript library was even the focus of a student book chapter. And Mapbox the company was mentioned in a recent issue of The Economist. In the area I work in, lots of companies are using Mapbox. I know some of these companies and respect the programming they do. What did they know that I didn't? Maybe it was time to take a look at Mapbox and find out.

And so I did and now I'm a Mapbox user too. My needs are relatively modest at this point, so the Mapbox free tier account is fine. I can host my maps and geographic data on Mapbox, with up to 50,000 map views per month at no charge.

Mapbox's business is hosting maps and data on their servers. If your needs are big enough, you pay for that service. But they also create a ton of open source software. In fact, they describe themselves as an "open source company."

You can use their software for free to access your maps and data in any app that you write, whether it's a Web app, desktop app, or mobile app. Currently I'm using Mapbox GL JS, their WebGL-based JavaScript library, but there are a lot of native app options available too. If you look at the list of native SDKs, there appears to be something for everyone:

(The full list is here.)

Something for everyone except Pascal users, that is. Or is there something there for us after all? Let's take a closer look.


Ways of doing cross-platform

With the Lazarus IDE for the Free Pascal compilers, it's an article of faith that "cross-platform" means the same interface everywhere and that all platforms where those interfaces have been implemented are equal in the eyes of the IDE. So if you design a form and write some code for it on one platform, you ought to be able to take your source files and compile them with Lazarus on a different platform. This works fairly well and is a noble sentiment, but in practice some platforms are more "equal" others. This approach also has trouble accommodating platforms such as mobile and the modern Web, which weren't around when the original design was set in stone.

With Mapbox, cross-platform has a different meaning. Sure, there's the native library that's used by all native SDKs, but you normally don't work with it directly. Instead, you work with an SDK that's designed for a particular language and target. For example, if you're targeting iOS or macOS, you'll likely be using Objective C or Swift and so the Mapbox iOS and macOS SDKs provide a framework library that exposes Objective C classes. If you're targeting Android, you'll likely be using Java and so the Mapbox Android SDK provides Java classes. If your app uses Qt 5, you'll work with the Mapbox Qt SDK's C++ classes. And so on.

And so even though you'll be indirectly using the same speedy OpenGL-based map engine that's at the heart of every native SDK, and you'll do similar things in a similar fashion with any map (pan, zoom, annotate, etc.), you don't do it with common code. Instead, with Mapbox, cross-platform lies more in the specifications for the maps (called styles) and geographic data (typically vector tilesets) that you'll be using on all platforms, native and Web.

You can create styles and tilesets with the nifty online Mapbox Studio, or you can create them locally. A style is just a JSON file that you can edit with a text editor; tilesets can be created from various file types common to desktop GIS, such as shapefiles. In other words, you can do a lot of prep work without writing a line of code for any platform. It also means you can share map styles with other developers and projects across all platforms. In fact, Mapbox provides a number of standard styles that you're free to use.


One platform at a time

So where does that leave us as Pascal programmers? Well, in some ways, Mapbox's approach is to our advantage and means we can do this one bite at a time, like eating the proverbial elephant. We don't need to come up with an omnibus solution that covers all platforms. We can pick and choose amongst the SDKs, both the ones available now and any future SDKs that Mapbox or anyone else might create. (This is another advantage of Mapbox's approach: they don't have to worry about a new or updated SDK affecting other platforms.)

Looking at the available Mapbox SDKs, there are a couple obvious candidates that we can start with and create Pascal "SDKs" for:

There are other possibilities as well, but let's start with these two.

On to Part 2 ...


Copyright 2018 by Phil Hess.

macpgmr (at) icloud (dot) com

First posted March 16, 2018.