Mapbox GL JS Convert Screen (X, Y) coordinates to LngLat - mapbox

I want to convert a few (X,Y) positions on the mapbox map to their lnglat positions.
I know project() converts from lnglat to X, Y. But, I can't find the reverse.

map.unproject() exists and does what you need: https://docs.mapbox.com/mapbox-gl-js/api/map/#map#unproject

Related

Track Pixel Coordinates in Leaflet

I am trying to build a Vt of 360 degree panopictures with OSM map using Leaflet.
I need a function which returns the pixel coordinates of a point/marker relative to the origin pixel (to the top left corner of the map container) when moving (i.e panning/dragging) the map and when zooming the map.
Any suggestions/hints?
From the Leaflet API:
// #method containerPointToLayerPoint(point: Point): Point
// Given a pixel coordinate relative to the map container, returns the corresponding
// pixel coordinate relative to the [origin pixel](#map-getpixelorigin).
containerPointToLayerPoint: function (point) {
return toPoint(point).subtract(this._getMapPanePos());
},
Is this what you are looking for?

convert pixel coordinates to map coordinates

I have an image A of dimension p x q. If I know the UTM coordinate of A(1,1) and A(p,q) and pixel size in meters.
How to convert the pixel coordinates to map coordinates in MATLAB?
Xsize = (1:p)*PixelSizeInMeter+UTM_x_onA11;
Ysize = (1:q)*PixelSizeInMeter+UTM_y_onA11;
figure;
surface(Xsize,Ysize,A);
Now you can plot your map using Xsize and Ysize. Since UTM is a Cartesian grid, life's quite easy: get the correct number of elements, multiply with the grid size and add the lower corner's coordinates to shift the plot to the correct location.

Unity Get Pixel Coordinate Values from RectTransform

I am in need of a way to obtain the pixel coordinates of a rect transform.
x position where 0 is the left of the screen and y position where 0 is the bottom of the screen.
You want to use Camera.WorldToScreenPoint.
Convert the object origin.
Convert the object origin+width.
Convert the object origin+height.
Your pixel coords are Array[origin.x, origin.y, origin.x+width, origin.y+height]
In 3d there are not pixels. Only a units in unity 3d.
float x = transform.x;
float y = transform.y;
You will get units in x, y.
If you working with textures you might use Texture2D, it has some methods for pixel working.

leaflet and xy coordinates

I have list of xy coordinates (shapex, shapey) belonging to UK region. I need to draw a marker with respect to those xy coordinates.
Is it possible to achieve this? if yes then how?
//update.
I have an XY coordinates like (535055.00,164129.00),(535055.00,164129.00),(535408.00,164064.00)
but L.Marker() method need LatLong as an argument. so my problem consist of two queries.
Can we convert XY coordinates into LatLong?
If no then how can we draw marker at location XY coordinate.
Of course you can. Just create a variable that stores your coordinates, like this:
var coordinates = [[x, y], [x, y], [x, y]]
Then loop through your coordinates, and create a marker for each set.
for (i = 0; i < coordinate.length; i++) {
var marker = L.marker(coordinate[i]).addTo(map)
}

Can I transform the embedded interactivity coordinate system result from lat lon to epsg 3857 (web mercator)?

When using the embedded interactivity embedded interactivity function on the iOS SDK I can click a map tile and get the data coords in LAT LON but I would like to have the result in EPSG 3857 WGS 84...is this possible? If so what is the transform command?
Looks like I am going to answer my own question. I could not find a transform function. So I passed the LAT LONG coordinate pair to the webservice and did the transformation on the server.
You can do this with Leaflet/Mapbox.
Here's an example
var latlng = L.latLng(45, -120);
var sphericalMercator = L.Projection.SphericalMercator.project(latlng);
sperhicalMercator.x => -2.0943951023931953
sphericalMercator.y => 0.8813735870195429
You'll still need to multiply these coordinates by 6378137 (earth's radius in meters) (why Leaflet doesn't do this, I don't know...), and you get the spherical mercator equivalent to the original lat/long (45, -120):
(-13358338.8952, 5621521.48619)