Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.52.0 Added Daytime / Nighttime shroud to signal and listener maps -…
… uses library developed by [Rossen Georgiev] - https://github.com/rossengeorgiev
- Loading branch information
Showing
14 changed files
with
269 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright 2013 Rossen Georgiev | ||
https://github.com/rossengeorgiev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
![Preview of Nite Overlay](preview.jpg "Preview of Nite Overlay") | ||
|
||
# Nite Overlay - Overview | ||
|
||
Generates an overlay to illustrate the day/night cycle. | ||
There are 4 shade levels going from light to dark. | ||
They are civil twilight, nautical twilight, astronomical twilight and night. | ||
|
||
Works with Google Maps API v3 | ||
|
||
The sun position is estimated using an adapted method from NOAA's solar calculator, which is based on equations from Astronomical Algorithms, by Jean Meeus. | ||
More details: http://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html | ||
|
||
*Might not work on some mobile devices. I've not explored the reason for this* | ||
|
||
## Quick start | ||
|
||
```javascript | ||
var map = google.maps.Map(...); | ||
nite.init(map); | ||
``` | ||
Use `refresh()` method to update the overlay periodically. Perhaps via `setInterval()`; | ||
|
||
``` | ||
setInterval(function() { nite.refresh() }, 10000); // every 10s | ||
``` | ||
|
||
Alternatively, a specific date can be selected via `setDate()` followed by a call to `refresh()` to redraw the overlay. Setting the date to `null` will cause nite overlay to use current date and time. | ||
|
||
Note: *If the overlay is hidden and refresh() is called, the overlay position will not be updated. | ||
Not until the overlay is visible again.* | ||
|
||
## Available methods | ||
|
||
`nite.setMap()` set a specific map object | ||
`nite.setDate(Date object)` set a specific datetime, or `null` to use current datetime | ||
`nite.calculatePositionOfSun(Date object)` returns LatLng for the specified date (has no effect on the overlay) | ||
`nite.refresh()` Recalculate and refresh the position of the overlay | ||
`nite.isVisible()` returns a boolean if the overlay is visible on the map | ||
`nite.show()` Make the overlay visible | ||
`nite.hide()` Hide the overlay | ||
`nite.getSunPosition()` returns LatLng for the Sun | ||
`nite.getShadowPosition()` returns LatLng for the night side | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* Nite v1.7 | ||
* A tiny library to create a night overlay over the map | ||
* Author: Rossen Georgiev @ https://github.com/rossengeorgiev | ||
* Requires: GMaps API 3 | ||
*/ | ||
|
||
|
||
var nite = { | ||
map: null, | ||
date: null, | ||
sun_position: null, | ||
earth_radius_meters: 6371008, | ||
marker_twilight_civil: null, | ||
marker_twilight_nautical: null, | ||
marker_twilight_astronomical: null, | ||
marker_night: null, | ||
|
||
init: function(map) { | ||
if(typeof google === 'undefined' | ||
|| typeof google.maps === 'undefined') throw "Nite Overlay: no google.maps detected"; | ||
|
||
this.map = map; | ||
this.sun_position = this.calculatePositionOfSun(); | ||
|
||
this.marker_twilight_civil = new google.maps.Circle({ | ||
map: this.map, | ||
center: this.getShadowPosition(), | ||
radius: this.getShadowRadiusFromAngle(0.566666), | ||
fillColor: "#000", | ||
fillOpacity: 0.1, | ||
strokeOpacity: 0, | ||
clickable: false, | ||
editable: false | ||
}); | ||
this.marker_twilight_nautical = new google.maps.Circle({ | ||
map: this.map, | ||
center: this.getShadowPosition(), | ||
radius: this.getShadowRadiusFromAngle(6), | ||
fillColor: "#000", | ||
fillOpacity: 0.1, | ||
strokeOpacity: 0, | ||
clickable: false, | ||
editable: false | ||
}); | ||
this.marker_twilight_astronomical = new google.maps.Circle({ | ||
map: this.map, | ||
center: this.getShadowPosition(), | ||
radius: this.getShadowRadiusFromAngle(12), | ||
fillColor: "#000", | ||
fillOpacity: 0.1, | ||
strokeOpacity: 0, | ||
clickable: false, | ||
editable: false | ||
}); | ||
this.marker_night = new google.maps.Circle({ | ||
map: this.map, | ||
center: this.getShadowPosition(), | ||
radius: this.getShadowRadiusFromAngle(18), | ||
fillColor: "#000", | ||
fillOpacity: 0.1, | ||
strokeOpacity: 0, | ||
clickable: false, | ||
editable: false | ||
}); | ||
}, | ||
getShadowRadiusFromAngle: function(angle) { | ||
var shadow_radius = this.earth_radius_meters * Math.PI * 0.5; | ||
var twilight_dist = ((this.earth_radius_meters * 2 * Math.PI) / 360) * angle; | ||
return shadow_radius - twilight_dist; | ||
}, | ||
getSunPosition: function() { | ||
return this.sun_position; | ||
}, | ||
getShadowPosition: function() { | ||
return (this.sun_position) ? new google.maps.LatLng(-this.sun_position.lat(), this.sun_position.lng() + 180) : null; | ||
}, | ||
refresh: function() { | ||
if(!this.isVisible()) return; | ||
this.sun_position = this.calculatePositionOfSun(this.date); | ||
var shadow_position = this.getShadowPosition(); | ||
this.marker_twilight_civil.setCenter(shadow_position); | ||
this.marker_twilight_nautical.setCenter(shadow_position); | ||
this.marker_twilight_astronomical.setCenter(shadow_position); | ||
this.marker_night.setCenter(shadow_position); | ||
}, | ||
jday: function(date) { | ||
return (date.getTime() / 86400000.0) + 2440587.5; | ||
}, | ||
calculatePositionOfSun: function(date) { | ||
date = (date instanceof Date) ? date : new Date(); | ||
|
||
var rad = 0.017453292519943295; | ||
|
||
// based on NOAA solar calculations | ||
var ms_past_midnight = ((date.getUTCHours() * 60 + date.getUTCMinutes()) * 60 + date.getUTCSeconds()) * 1000 + date.getUTCMilliseconds(); | ||
var jc = (this.jday(date) - 2451545)/36525; | ||
var mean_long_sun = (280.46646+jc*(36000.76983+jc*0.0003032)) % 360; | ||
var mean_anom_sun = 357.52911+jc*(35999.05029-0.0001537*jc); | ||
var sun_eq = Math.sin(rad*mean_anom_sun)*(1.914602-jc*(0.004817+0.000014*jc))+Math.sin(rad*2*mean_anom_sun)*(0.019993-0.000101*jc)+Math.sin(rad*3*mean_anom_sun)*0.000289; | ||
var sun_true_long = mean_long_sun + sun_eq; | ||
var sun_app_long = sun_true_long - 0.00569 - 0.00478*Math.sin(rad*125.04-1934.136*jc); | ||
var mean_obliq_ecliptic = 23+(26+((21.448-jc*(46.815+jc*(0.00059-jc*0.001813))))/60)/60; | ||
var obliq_corr = mean_obliq_ecliptic + 0.00256*Math.cos(rad*125.04-1934.136*jc); | ||
|
||
var lat = Math.asin(Math.sin(rad*obliq_corr)*Math.sin(rad*sun_app_long)) / rad; | ||
|
||
var eccent = 0.016708634-jc*(0.000042037+0.0000001267*jc); | ||
var y = Math.tan(rad*(obliq_corr/2))*Math.tan(rad*(obliq_corr/2)); | ||
var rq_of_time = 4*((y*Math.sin(2*rad*mean_long_sun)-2*eccent*Math.sin(rad*mean_anom_sun)+4*eccent*y*Math.sin(rad*mean_anom_sun)*Math.cos(2*rad*mean_long_sun)-0.5*y*y*Math.sin(4*rad*mean_long_sun)-1.25*eccent*eccent*Math.sin(2*rad*mean_anom_sun))/rad); | ||
var true_solar_time_in_deg = ((ms_past_midnight+rq_of_time*60000) % 86400000) / 240000; | ||
|
||
var lng = -((true_solar_time_in_deg < 0) ? true_solar_time_in_deg + 180 : true_solar_time_in_deg - 180); | ||
|
||
return new google.maps.LatLng(lat, lng); | ||
}, | ||
setDate: function(date) { | ||
this.date = date; | ||
this.refresh(); | ||
}, | ||
setMap: function(map) { | ||
this.map = map; | ||
this.marker_twilight_civil.setMap(this.map); | ||
this.marker_twilight_nautical.setMap(this.map); | ||
this.marker_twilight_astronomical.setMap(this.map); | ||
this.marker_night.setMap(this.map); | ||
}, | ||
show: function() { | ||
this.marker_twilight_civil.setVisible(true); | ||
this.marker_twilight_nautical.setVisible(true); | ||
this.marker_twilight_astronomical.setVisible(true); | ||
this.marker_night.setVisible(true); | ||
this.refresh(); | ||
}, | ||
hide: function() { | ||
this.marker_twilight_civil.setVisible(false); | ||
this.marker_twilight_nautical.setVisible(false); | ||
this.marker_twilight_astronomical.setVisible(false); | ||
this.marker_night.setVisible(false); | ||
}, | ||
isVisible: function() { | ||
return this.marker_night.getVisible(); | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.