Customize a planet's radius in R Leaflet?

We're (successfully!) using Leaflet to explore Mars via the M20 mission endpoint...yeah!

Unfortunately, when we take measurements using addMeasure(), the results are much larger than expected, suggesting that addMeasure() is using the Earth's radius rather than Mars' ( 3.3895e+6 meters).


According to NASA, the distance between the current location of Perseverance and the final location of Ingenuity is closer to 415m, instead of the 793m shown

I've seen some examples "out there" for tweaking the CRS for pure JS Leaflet, but none for R Leaflet. How do we customize the planet's radius in R Leaflet?

Thanks!
[1] Example of setting the Moon's radius in JS Leaflet

FWIW, calculating the distance "manually" (using the correct Mars radius):

> ingenuityFinal
     lon      lat 
77.32254 18.49726 
> roverCurrent
         lon      lat
368 77.32722 18.49182
> distHaversine(ingenuityFinal,roverCurrent,r)
[1] 415.8136

Hi @olyerickson ,

i used the leaflet version bundled in the R package to recreate the example you gave with java script (So all imports which start with leaflet/leaflet-measure can be found here leaflet/inst/htmlwidgets/lib at main · rstudio/leaflet · GitHub).

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Leaflet</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link type="text/css" rel="stylesheet" href="./leaflet/leaflet.css" />
    <link type="text/css" rel="stylesheet" href="./leaflet-measure/leaflet-measure.css" />
</head>
<body>
    <div id="leaflet" style="height: 500px;"></div>
    <script src="./leaflet/leaflet.js"></script>
    <script src="./leaflet-measure/leaflet-measure.js"></script>
    <script src="script.js"></script>
</body>
</html>

script.js

L.CRS.MarsphericalMercator = L.extend({}, L.CRS.EPSG3857, {R: 3396190});

var map = new L.Map('leaflet', {
    layers: [
        L.tileLayer('https://mars.nasa.gov/mmgis-maps/M20/Layers/M20_HiRISE_RGB_mosaic_25cm_v4p2/{z}/{x}/{-y}.png', {
            'attribution': 'Map data © <a href="https://www.openplanetary.org">OpenPlanetary</a> contributors'
        })
    ],
    center: [0, 0],
    zoom: 12,
    crs: L.CRS.MarsphericalMercator
});
var marker = new L.Marker([18.49726, 77.32254]);
marker.addTo(map);
var marker2 = new L.Marker([18.49182, 77.3272]);
marker2.addTo(map);
map.panTo(new L.LatLng(18.49726, 77.32254));
L.control.measure({
    primaryLengthUnit: 'meters',
    secondaryLengthUnit: 'miles'
}).addTo(map);
L.control.scale().addTo(map);

still gives the ~800 meters

So i can reproduce the "error" even in js. If you can get the WMTS service of the tiles you are using (like here -> Trek API | Welcome) i would try to make the projections.

But for now it seems to be "correct" the way it is.

Unfortunately, the "capabilities" API for the M20 mission does not seem to be available.

As you know, the tiles for the M20 mission area are being served up via TMS, not WMTS; I wonder if that makes a difference RE discovering capabilities.

You are right it is a TMS but it still should have the capabilities listed somewhere. Unfortunately i couldn't deduce it from inspecting the calls of the "original" MMGIS map and NASA doesn't list the service anywhere.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.