2

We have some customer's who have facility data they are publishing through their own WMS or ArcGIS/REST services.

We're exploring the idea of building an IOS app that can display their facilities using MapBox's IOS SDK.

We've had no trouble configuring a set of landbase layers in MapBox, and displaying them in our demo app. We've not yet tried uploading sample facility data onto the MapBox site, but we don't expect to have any difficulty with that.

We expect some of our customers will want to upload their facility data into MapBox, so that they can take advantage of MapBox's offline mapping features. But a good many of them won't.

For those that don't, we're trying to figure out how to access our customers' facility services directly.

MapBox IOS SDK supports custom raster styles: Custom raster style

The idea is you create a custom style in json, and in it you specify a template for the tile URLs.

{
  "version": 8,
  "name": "Raster Tiles",
  "sources": {
    "yourTileLayer": {
      "type": "raster",
      "tiles": [
        "https://1.tile.server/{z}/{x}/{y}.png",
        "https://2.tile.server/{z}/{x}/{y}.png"
      ],
      "tileSize": 256
    }
  },
  "layers": [{
    "id": "yourTileLayer",
    "type": "raster",
    "source": "yourTileLayer",
    "paint": {
      "raster-fade-duration": 100
    }
  }]
}

Those templates look suspiciously like the templates use by Leaflet's TileLayer: TileLayer

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar'}).addTo(map);

Leaflet has a TileLayer.WMS class, that derives from TileLayer, that provides an interface that's usually used for displaying WMS on a Leaflet map.

Is there a template I could pass to Leaflet's TileLayer class, that would retrieve tiles from a WMS server, without using Leaflet's TileLayer.WMS class?

Can anyone tell me how to build it?

Similarly, ESRI has a Leaflet plugin to display ArcGIS/REST data on a Leaflet map. Is there a template I could pass to Leaflet's TileLayer class, that would retrieve tiles from an ArcGIS/REST server, without using ESRI's plugin?

Can anyone tell me how to build that?

My hope is whatever URL I might build that works with Leaflet's TileLayer class will also work with MapBox's IOS SDK.

2

Is there a template I could pass to Leaflet's TileLayer class, that would retrieve tiles from a WMS server, without using Leaflet's TileLayer.WMS class?

No.

Even though you might think that all L.TileLayers rely on templates, that's not the case. Subclasses can override the getTileUrl() method to provide custom URLs for the tile coordinates. There is a good explanation of how this is done, in the tutorials about creating Leaflet plugins.

L.TileLayer.WMS's job is precisely that: for every tile, it will ditch the template and calculate the tile bounds (in CRS units) in order to assemble the URL for the tile.

If WMS layers could be added with simple template URLs, Leaflet wouldn't need to have L.TileLayer.WMS in the first place.

My hope is whatever URL I might build that works with Leaflet's TileLayer class will also work with MapBox's IOS SDK.

Contact MapBox support. They will probably give you a better and definitive answer, and/or a timeline for that feature.

  • I was afraid of that. We could, of course, create our own web service that did the appropriate projection math, but I doubt that we'll bother. – Jeff Dege Nov 21 '16 at 23:50
  • Setting up such a service is no hassle. In the past, I've deployed MapProxy instances in a couple of hours for similar scenarios. WMS goes in, TMS or XYZ tiles go out. – IvanSanchez Nov 22 '16 at 8:28
  • Looking at the MapProxy docs, it supports a number of output formats. Can you tell me which specific format works with L.TileLayer? – Jeff Dege Nov 22 '16 at 19:24
2

My hope is whatever URL I might build that works with Leaflet's TileLayer class will also work with MapBox's IOS SDK.

In Mapbox iOS SDK v3.4.0 and above (as well as in other Mapbox GL libraries), you can construct a tile URL that works with a WMS server. This example targets Mapbox GL JS, but the same URL template works with the iOS SDK:

{
    "type": "raster",
    "tiles:" ["https://geodata.state.nj.us/imagerywms/Natural2015?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=Natural2015"],
    "tileSize": 256
}

For details on all the supported template placeholders, consult the MGLTileSource documentation. That document is written in terms of the runtime styling API, which allows you to add a raster source to the map on the fly, but the same placeholders work inside a style JSON file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.