MapBox GL JS. Zoom to Altitude - mapbox

How can I convert zoom lavel to altitude?
There is some kind of function
or algorithm or table of values?

There is a draft PR at https://github.com/mapbox/mapbox-gl-js/pull/8830 which adds a method to set the camera with an altitude, you could pull out some of that code to make your own method which returns a zoom level given an altitude.

Related

How to change map color by current zoom level with mapbox gl js?

My question is about mapbox gl js.
How to change map fill-color by current zoom level?
The fill-color of this map has population growth rates by country, with a gradation from minimum to maximum. However, if the zoomed location has similar data, the fill-color difference becomes difficult to understand. So, I want to refer to the tile information according to the zoom level, get the country on the screen, and redraw it.
I searched a lot, but I couldn't figure out how to get the information on the screen. Please let me know if you have any information.
Zoom Level: 1
Zoom Level: 3
Thank you!
Your question initially asks:
How to change map color by current zoom level with mapbox gl js?
For that, you use an expression like 'fill-color': ['interpolate', ['linear'], ['zoom'], ...]
But what you want is something very different:
However, if the zoomed location has similar data, the fill-color difference becomes difficult to understand. So, I want to refer to the tile information according to the zoom level, get the country on the screen, and redraw it.
It sounds like what you want is context-sensitive color scaling. That is, instead of a fixed scale of colors where dark green always means X and light green means Y, instead, dark is the lowest value in the current viewport and light is the highest value in the viewport.
This does not have anything to do with zoom.
The steps you need are:
Detect when the viewport has changed: map.on("moveend", ...)
Find what values exist within the viewport: map.queryRenderedFeatures(...)
Calculate a new expression based on those values.
Set the new expression: map.setPaintProperty(...)

Marker Drag and drop event with overlay image calculate pix issue

this is an example. I am creating a custom function GetCoordinates this function calculates x and y positions for the image. but this function is not working for your Mapbox init method. can you help me with what can I do this?. Example: "https://jsfiddle.net/ufnvepms/"
Are you trying to get the coordinates of the marker as it is dragged? Or do you want to get the corresponding x/y position of the source image?
The first can be done by adding a listener on the "dragend" event, to get the lat/lon of the marker, as in this example: https://docs.mapbox.com/mapbox-gl-js/example/drag-a-marker/
If you need the second, it would require some more calculation, but before figuring that out wanted to understand more precisely what you're trying to achieve.

Mapbox Unity SDK: storying and displaying short relative distances

I was wondering how I can go about storing and displaying small, but geographically accurate distances in the mapbox unity SDK?
I'm storing radius' about markers on a map, I get the value in meters (from ~0.5m-10m), and then, adaptively with the zoom level, I want to accurately display those meters in Unity world space (draw an ellipse) using these stored values. The problem is that the mapbox api from my understanding only lets you to convert lat/long to unity world coordinates and I'm running into precision errors. I can get adequate precision when using the CheapRuler class and meters, but as soon as I use the _map.GeoToWorld(latlon) method the precision is lost.
How would I go about keeping adequate precession, is there a way I can use the marker as the reference point and the radius as the offset, and get the relative unity world coordinate distance (of the radius) that way? I know you can also store scale relative to the mapbox tiles, but I'm not sure how I can convert that back to a unity world distance. I'm operating on very small distances, so any warping due to lat/long being a Mercator projection can probably be ignored.
I figured out a round-about solution.
First I convert the meters into unity world space using whatever IMapScalingStrategy Mapbox is currently using.
Then I convert from world to the view space of whatever camera I want to scale to the given bounds.
After that, I use find out the scale of the bounds, solving for:
UnityRelativeScaleChange = 2Map Zoom Level Change; which (to my estimations) is the relationship between unity scale and mapbox zoom levels.
This solutions works great as long as you don't have to zoom in/out by too much, otherwise you'll run into precision problems as the functions rely on the relative view-based size of a given bounds to do their calculations which will lead to unstable results if those initially take a tiny portion of the screen.

Mapbox Static image with auto and pitch

I'm trying to create a static image using the "auto" feature to correctly calibrate the image according to the polyline I pass to it. It works very well but I'd like to add a pitch in addition.
I've tried something like this but I got this error: "Invalid query param pitch"
https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/pin-s-a+9ed4bd(-122.46589,37.77343),pin-s-b+000(-122.42816,37.75965),path-5+f44-0.5(%7DrpeFxbnjVsFwdAvr#cHgFor#jEmAlFmEMwM_FuItCkOi#wc#bg#wBSgM)/auto/500x300?access_token=xxxxx&pitch=50
Any help please ?
The auto parameter automatically sets the values for longitude, latitude, zoom, bearing, and pitch based on the overlay. When using auto you cannot set these values individually as the parameter replaces all of their values with the best settings for the overlay. From the documentation:
If auto is added, the viewport will fit the bounds of the overlay. If
used, auto replaces lon, lat, zoom, bearing, and pitch.
If you'd like to set the pitch, you will need to supply your own values for longitude, latitude, zoom, and bearing as well. For example: https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/pin-s-a+9ed4bd(-122.46589,37.77343),pin-s-b+000(-122.42816,37.75965),path-5+f44-0.5(%7DrpeFxbnjVsFwdAvr#cHgFor#jEmAlFmEMwM_FuItCkOi#wc#bg#wBSgM)/-122.46589,37.75965,11,0,50/500x300?access_token={YOUR_ACCESS_TOKEN}
Will return:

Mapbox - extruding lines

Is it possible to apply fill-extrusion for a GeoJSON LineString feature?
Basically I'm looking for a way to draw lines (can be 1 line or multiple connected) in a 3d mode with z-offset.
If that's not possible, maybe this can be done with a polygon instead?
Like, converting my lines to polygons (how can i do that?)
What you're asking for isn't yet implemented, but ticketed in Mapbox GL JS at https://github.com/mapbox/mapbox-gl-js/issues/3993.
For now you'll need to opt for your second suggestion of converting the LineString feature to a Polygon. You can do this with turf's buffer function http://turfjs.org/docs#buffer.
The whole line/polygon will be offset at the same height, so depending on your application you could use turf's linkChunk http://turfjs.org/docs#lineChunk to get it broken up into smaller features which you assign different height properties to.