Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:25:50+00:00 2026-05-25T02:25:50+00:00

I am trying to find a way to create an overlay for Google Maps

  • 0

I am trying to find a way to create an overlay for Google Maps API V3 that shows the sunlit areas of the world. This is the basic result I am looking for:

http://www.daylightmap.com/index.php

But want more control over the appearance (ideally just a 10% black overlay with no city lights). I can draw the shape in a canvas element but can not figure out how to calculate the shape based on earth’s tilt and rotation etc.

Any help would be appreciated.

EDIT: Javascript

I still don’t know where to implement the y-offset variable below. I also need to figure out how to adjust/stretch the y-offset from this (equal distant latitudinal lines) to mercator (closer at poles).

// Get the canvas element
var ctx = document.getElementById('canvas').getContext('2d');
ctx.clearRect( 0, 0, 800, 620 );

// Current time
var map_width = $("#canvas").width();
var map_height = $("#canvas").height();
var now = new Date();
var cur_hour = now.getHours();
var cur_min = now.getMinutes();
var cur_sec = now.getSeconds();
var cur_jul = now.julianDate() - 1;
var equinox_jul = new Date(now.getFullYear(),2,20,24,-now.getTimezoneOffset(),0,0).julianDate() - 1;

var offset_x = Math.round(((cur_hour*3600 + cur_min*60 + cur_sec)/86400) * map_width); // Resulting offset X
var offset_sin = ((365.25 - equinox_jul + cur_jul)%365.25)/365.25; // Day offset, mapped on the equinox offset
var offset_sin_factor = Math.sin(offset_sin * 2 * Math.PI); // Sine wave offset
var offset_y = offset_sin_factor * 23.44; // Map onto angle. Maximum angle is 23.44° in both directions

var degrees_per_radian = 180.0 / Math.PI;
var offset_y_mercator = Math.atan( offset_y.sinh() ) * degrees_per_radian;


// Global wave variables
var period = 1 / 6.28291;   // Original value 2Pi: 6.28291
var amplitude = (map_height/2);

// Draw vertical lines: One for each horizontal pixel on the map
for( var x = 0; x <= map_width; x++ ) {
    ctx.beginPath();

    // Start at the bottom of the map
    ctx.moveTo(x,map_height);

    // Get the y value for the x pixel on the sine wave
    var y = (map_height/2) - (Math.sin( (offset_x / map_width) / period ) * amplitude);

    offset_x++;

    // Draw the line up to the point on the sine wave
    ctx.lineTo(x,y);
    ctx.stroke();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:25:51+00:00Added an answer on May 25, 2026 at 2:25 am

    If you want it to be physically accurate, you actually need to consider two offsets: a vertical (depending on the current date) and a horizontal (depending on the current time).

    The horizontal offset X may be calculated by looking at the current time on some fixed geographic location on earth. The shadow offset will be 0 at midnight and will increase by 1/86400 for each seconds after midnight. So the formular is

    offsetX = (curHour*3600 + curMinute*60 + curSeconds)/86400
    

    The vertical offset will change between the Solstices on June 21st and Dec 22nd (if it’s not a leap year, where the Solstices are on June 20th and Dec 21st). The maximum angles are 23.44° in both directions. We have 90° per hemisphere and 365/2 = 182.5 days between the two solstices, and we are working with a mapping of a circular motion, so a sin()-function has to be used. The wavelength of a sinus wave is 2pi, so we need pi for half the vertical offset Y of one year.

    Please note, that I did not take leap seconds into account, so the calculation might be a bit off in the distant past/future.

    // current time
    $curHour = date("H");
    $curMin  = date("i");
    $curSec  = date("s");
    
    // resulting offset X
    $offsetX = ($curHour*3600 + $curMin*60 + $curSec)/86400;
    
    
    echo "======== OFFSET X ==========\n";
    echo "curHour:      $curHour\n";
    echo "curMin:       $curMin\n";
    echo "curSec:       $curSec\n";
    echo "offsetX:      $offsetX\n\n";
    
    
    // spring equinox date as day of year
    $equinox = date("z", mktime(0, 0, 0, 3, 20));
    
    // current day of year
        // first line is for testing purposes
    //$curDay = date("z", mktime(0, 0, 0, 6, 21));
        $curDay = date("z");
    
    // Day offset, mapped on the equinox offset
    $offsetSin = ((365.25 - $equinox + $curDay)%365.25)/365.25;
    
    // sinus wave offset
    $offsetSinFactor = sin($offsetSin * 2 * pi());
    
    // map onto angle
    $offsetY = $offsetSinFactor * 23.44;
    
    // optional: Mercator projection
    $degreesPerRadian = 180.0 / pi();
    $offsetYmercator = atan(sinh($offsetY)) * $degreesPerRadian;
    
    // missing: mapping onto canvas height (it's currently
    // mapped on $offsetY = 90 as the total height of the
    // canvas.
    
    
    echo "========= OFFSET Y =========\n";
    echo "equinox day:  $equinox\n";
    echo "curDay:       $curDay\n";
    echo "offsetSin:    $offsetSin\n";
    echo "offsetSinFac: $offsetSinFactor\n";
    echo "offsetY:      $offsetY\n";
    echo "offsetYmerc:  $offsetYmercator\n";
    

    You should be able to port this calculation to any language you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find the best way of create an overlap/overlay layer to fill the
Trying to find a more elegant way to create an int that has discrete
I am trying to find a way to create a menu in Codeigniter that
I am trying to find a way to create a report in BIRT that
I'm trying to find a way to create a simple outer join without too
I'm trying to find the way to face this situation. Having these tables in
I am trying to find a way to create an entry point for my
I'm trying to find a way to get the list of people that I'm
I'm trying to find a way to create a calculation from results in a
this is a more generic question: I am trying to find a way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.