Useful scripts for the Google Maps API
You may remember the SimpleMarker class I made about a year ago. Recently, I started working with the Maps API quite a lot again since I'm currently writing a Google+ extension with which you can get a map of your circles. During development, I realized that an update of my marker class was long overdue. Not anymore ;-)
Not only that, but the work on my extension resulted in some new scripts which I want to share with you. I gathered all of them in a GitHub repository so that you can easily participate in filing bug reports or even commiting your own code. All scripts are licensed under the Apache License Version 2 and you're free to use them in your own projects. Here's the link to it:
Google Maps API Addons on GitHub
In this article I want to give you a quick overview over the scripts in my repository.
SimpleMarker
As I have written some applications that involve a high amount of markers to be shown simultaneously, I made a lightweight marker class that has just a minimal footprint in the DOM hierarchy while still offering the most frequently used methods (and even a little bit more).
In the most recent update, I changed the interface strongly in order to match it to the interface of the regular google.maps.Marker
. If you have used my marker class before, please keep this in mind when replacing the file. You _will_ have to update some of your handling code in order not to encounter any errors.
Thanks to these changes, the marker should be compatible to most of the marker managing extensions like MarkerManager or MarkerClusterer. If this is not the case, just create an issue in the issue tracker and I'll take care of it.
DayNightOverlay
This is one of the products of my "Map My Circles" extension for the Chrome browser and Google+. As the name might suggest, this overlay shows you where it's currently day and where it's night on the earth. You can even customize it by changing the color of the night area or specify a custom date which shall be rendered.
At first I thought making such an overlay would be really simple. Just some kind of a sine wave which is offset horizontally depending on the current time. Well, it got a lot more complex than that. Because of the tilt that the earth has towards the sun, the area being lit varies highly throughout the year. Around the equinoxes (that are the dates when the sun is exactly over the equatorial line, usually in March and September), the shadow line has practically nothing in common with a sine, it's more of a square wave.
While doing some research, I stumbled upon geoastro.de, a site which provided all the formulas I needed to create an accurate Day/Night-Overlay. After having implemented the overlay, I compared the results to other websites that provide Day/Night maps and found that my calculated terminator line is in fact very precise.
FeatureControl
In order to provide the user a consistent way of enabling or disabling features such as certain overlays or clustering of markers, I made a simple yet extensible control element that looks like the map type chooser and can be added as a normal control element to your Google Maps map.
The script itself is made up of two parts. First of all, there is the actual control element which takes care of displaying the available features and handling the user interaction. Secondly, I wrote a generic Feature
class from which your specific feature should in inherit. With that, your own feature class just has to implement two event handlers (onEnable
and onDisable
) and you're all set.
Please note that the FeatureControl is not available in the above mentioned repository yet. I'm currently in the process of generalizing some parts of it as it has some dependencies on the application I originally built it for.