0

I have a process which generates a simple Google Static Map (can also be a MapBox static image as the code is pretty much interchangeable).

It's recycled code from a project I found years ago.

The final map url creation string is something like this:

var mapurl = "https://maps.googleapis.com/maps/api/staticmap?center=" +
            center[1].toFixed(6) + "," + center[0].toFixed(6) +
            "&zoom=" + zoominfo.zoom + "&size=" + mapsize.width + "x" + mapsize.height + "&scale=4&format=png&key=APIKEY" + mapStyle

Lets say a URL string is this:

https://maps.googleapis.com/maps/api/staticmap?center=42.803331,4.744135&zoom=7&size=640x640&scale=4&format=png&key=APIKEY&maptype=hybrid

And produces this map: Map

What I'd like to do is set up a bounding box for a specific set of lat/lon co-oridnates, and if the the url generated comes within those bounds, a seperate "customised" image is instead shown as an overlay. Think of this as essentially a custom map tile, nothing to do with google or mapbox static maps.

This map tile represents a particular region on earth, aligned to specific co-ordinates.

The end result would be something like this: Map with custom overlay

The closest thing I've seen is an implementaion of Google Maps GL JS where an overlay can be added: https://docs.mapbox.com/mapbox-gl-js/example/image-on-a-map/

This is essentially what I'm trying to do, albeit with Static Maps. Static Maps does not allow you to add custom raster overlays.

1

If using Mapbox you could create a custom style within your account which combines the base satellite map with your overlay image into a single style, then use that style with Mapbox Static Images API.

  • Thanks @AndrewHarvey - I've played around with custom styles in MBStudio but didn't realise I could incorporate a staic image overlay into it. I can see an option for SVG sprites/glyphs (road sign styles and so on). Is there documentation on how to overlay a JPG/PNG? – Huskie69 Oct 10 at 10:41
  • 1
    See docs.mapbox.com/help/tutorials/georeferencing-imagery for how to georeference and upload raster data you can then use in Mapbox Studio. – AndrewHarvey Oct 12 at 23:10
  • Perfect, thank you! – Huskie69 21 hours ago

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.