Styled MapBox map tiles: Custom maps in QGC with minimal effort

This is my first ever post in this forum, so please be gentle if I go about the wrong way.
I’d like to suggest a new and easily implemented feature that will allow any user to utilize their own “custom” MapBox maps in both planning and flight views.

I had already read through Mapbox’ API specification. And although I’m far from a developer, I decided to get my hands dirty: Installed Qt and patiently worked my way through some of the code. Yesterday I finally had a working solution. But being an absolute newbie, the resulting code is nothing but a hack (I simply re-wrote the current code to do a proof of concept). I need help to implement this in a proper way so that everyone interested can utilize the ability. But the solution does work - with no errors.

I concluded that the key to get map tiles lies within QGCMapEngine.cpp, and that the URL to retrieve Mapbox tiles is constructed there. Currently, the URL is built based on the “Retrieve tiles” API. According to specification, this API also offers the ability to include an optional “style” attribute. But I failed to get this to work.
But then I dicsovered the “Retrieve raster tiles from styles” API. And after some trial and error, QGC now use my own styled version of the maps. Which is key to my use of QGC: I map water depths with an Arduboat. Mapping may take several days of effort, so I need to be able to view temporary maps during the efforts. And like any sailor, the finished map contains key information that I need when planning and executing missions. Depths, plateaus, ridges etc are my points of interests :slight_smile:

To get this to work I humbly suggest:

  • Add two new attributes: mapboxAccount and mapboxStyle (both text fields)
  • Consider to add useMapboxStyle (boolean)
  • The boolean should perhaps only be selectable if the two text fields have values
  • UI: Alter the settings (currently under “offline maps”, then “options”) for the user to enter values into the suggested fields

Then, in QGCMapEngine.cpp, enter a new section to build the URL for this new API (please read with an understanding that I am no developer)

Condition (pseudo): IF mapBoxToken AND mapboxAccount AND mapboxStyle “all have values” AND useMapboxStyle = true

Then build URL like this:
QString server = “https://api.mapbox.com/styles/v1”;
server += QString(“/%1/%2/tiles/256”).arg(mapboxAccount).arg(mapboxStyle);
server += QString(“/%1/%2/%3?access_token=%4”).arg(zoom).arg(x).arg(y).arg(mapBoxToken);

And finally: Important to also alter the current condition to build mapbox URL. In addition to the current condition, it should only run if useMapboxStyle = false

Done!

Here’s a pict of a running version of QGC displaying a flight map modified by Mapbox studio in my Mapbox account. In Mapbox, I add depth maps as tilesets (one per water), thereafter the tilesets are simply added to a custom map style of my choosing.

Could anyone help implement this???

5 Likes

Hi, great performance. It is something I would like to do with a flight controller. I am absolutely unable to write a line of code. It would be highly appreciated if this somebody could implement this as a functionality or plug in (or whaterver easy) in QGC. I fully support oaamaas demand. thanks!!!

Hi oaamaas,

I just came across this post and am curious if you have any additional documentation on how you achieved this custom mapping? I am interested in displaying custom map tiles on QGC and I am impressed with your hydrological layering.

Regards,

jamus2013

In this particular case, the data source is a CSV file including position (decimal latitude and longitude) and depth. And the “depth map” itself was produced based on this data using Reefmaster. Then result was exported. And then put into the desired map using MapBox style editor. So, some work involved.
I made some code and then made a request for QGC to implement the solution in order to display mapbox maps in general (missing at the time). Back then it was suggested that such changes should wait since map solution in general was to be re-designed.

I have not tried to code anything based on QGC for some time. But a few months back I created a dev environment once more. Briefly built a sample app (and got seriously concerned as it seems to struggle to keep telemetry link active when communicating with my ArduRover SITL- over TCP). Anyway, I discovered that mapbox map along with other alternatives are available (incl offline) which is good. Did not check if a custom map is available though. You would need that (using a combo of MapBox account name and mapid) to utilize personal maps in made in MapBox as described above.

However, in retrospect, the better change in QGC is as follows: The export from Reefmaster is typically a KMZ file. KMZ is an archive, and the archive MAY include a picture and always include a KML file. Picture is typically only there if you make bathymetric maps as “shaded reliefs” - artificial sun shining on the map with desired angle an elevation to cast shadows and create a 3D-like vizual experience. This is created as an image, and the KML file will then include the needed GroundOverlay tag to correctly place it on the map. The picture above is a type “isobath” with no picture to be overlaid. The KML file will anyway include all linerings to paint the lines onto the map. Using isobath only, polygons are described as filled with color. Resulting in the above image.

The point is: It should not be too hard to implement display of either the KMZ directly or the KML only. (IE: Export from Reefmaster, put in a folder that QGC can reach, add a function to select KMZ/KML file from file list, and then treat the data properly. When I checked this some year back, KML import was as far as I remember available in QGC. But obviously intended to support mission planning. Such a layer needs to be made non-clickable as supporting information laid on top of the map only.
This is totally doable. I do not have time to do anything than merely suggest.