Leaflet.Terminator icon indicating copy to clipboard operation
Leaflet.Terminator copied to clipboard

Light side of the earth

Open Foaly opened this issue 4 years ago • 2 comments

Hello! Thank you very much for this handy library! I was wondering about a feature request that I think would be a useful addition. I have a dark map so using a dark overlay make the map even darker and is hard to distinguish the terminator. I would much rather visualize the light/day side with a white overlay. How hard would it be to calculate the "inverse" Polygon? Could this possible be added?

Foaly avatar Jul 21 '19 00:07 Foaly

I was able to implement this using Leaflets polygon cutout feature:

let terminatorConfig = {
  stroke: false,
  fillColor: '#FFFFFF',
  fillOpacity: 0.15
};

// get the coordinates of the terminator and flatten them from an array of objects to an array of arrays
let terminatorCoords = L.terminator().getLatLngs()[0].map( function(obj) {
  return [ obj.lat, obj.lng ];
});

// create the inverse of the terminator to highlight the day side
L.polygon(
  [[[ 90, -300],
    [ 90,  300],
    [-90,  300],
    [-90, -300]], //outer rect
   terminatorCoords], // terminator cutout
   terminatorConfig
).addTo(map);

It's a little hacky, but it shows that it is possible to arrive at the inverse of the polygon. So mathematically it should only be some clever subtraction. I think it would still be cool to have a helper function in the library that does it for you :)

Foaly avatar Jul 21 '19 19:07 Foaly

I'll keep this in mind but it´s not a priority item for me. Feel free to submit a pull request, though.

joergdietrich avatar Oct 29 '19 13:10 joergdietrich