Skip to content

Commit

Permalink
Merge pull request #23 from StefanoSperetta/master
Browse files Browse the repository at this point in the history
Adding latitude range option
  • Loading branch information
joergdietrich authored May 11, 2024
2 parents e7e1175 + edc383e commit e31f2ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ points are computed. The step size is 1°/resolution, i.e. higher
resolution values have smaller step sizes and more points in the
polygon. The default value is 2.

Leaflet.Terminator computes the terminator from longitudes -360° to +360°
(a range of 720°), covering the Earth twice. To limit the terminator
longitude range, the `longitudeRange` option is available.

```js
var sunlightOverlay = L.terminator({resolution: 5, longitudeRange:360});
```

You can pass the `time` option in the constructor or use the `setTime()`
method to control the reference time and date for the terminator; the
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var Terminator = L.Polygon.extend({
opacity: 0.5,
fillColor: '#00',
fillOpacity: 0.5,
resolution: 2
resolution: 2,
longitudeRange: 720
},

initialize: function (options) {
Expand Down Expand Up @@ -118,17 +119,17 @@ var Terminator = L.Polygon.extend({
var sunEclPos = this._sunEclipticPosition(julianDay);
var eclObliq = this._eclipticObliquity(julianDay);
var sunEqPos = this._sunEquatorialPosition(sunEclPos.lambda, eclObliq);
for (var i = 0; i <= 720 * this.options.resolution; i++) {
var lng = -360 + i / this.options.resolution;
for (var i = 0; i <= this.options.longitudeRange * this.options.resolution; i++) {
var lng = -this.options.longitudeRange/2 + i / this.options.resolution;
var ha = this._hourAngle(lng, sunEqPos, gst);
latLng[i + 1] = [this._latitude(ha, sunEqPos), lng];
}
if (sunEqPos.delta < 0) {
latLng[0] = [90, -360];
latLng[latLng.length] = [90, 360];
latLng[0] = [90, -this.options.longitudeRange/2];
latLng[latLng.length] = [90, this.options.longitudeRange/2];
} else {
latLng[0] = [-90, -360];
latLng[latLng.length] = [-90, 360];
latLng[0] = [-90, -this.options.longitudeRange/2];
latLng[latLng.length] = [-90, this.options.longitudeRange/2];
}
return latLng;
}
Expand Down

0 comments on commit e31f2ba

Please sign in to comment.