Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 13, 2016
0 parents
commit d1e24c0
Showing
153 changed files
with
14,390 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2009 Jon Udell | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to 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 OR APRESS 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,15 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*Beginning Google Maps Mashups with Mapplets, KML, and GeoRSS*](http://www.apress.com/9781430216209) by Jon Udell (Apress, 2009). | ||
|
||
![Cover image](9781430216209.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
##Releases | ||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
##Contributions | ||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
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,22 @@ | ||
function dms2decimal(deg, min, sec) | ||
{ | ||
// dms2decimal: converts degrees/minutes/seconds to decimal degrees | ||
|
||
if (sec == null) | ||
sec = 0; | ||
|
||
if (deg >= 0) | ||
return deg + (min / 60) + (sec / 3600); | ||
else | ||
return deg - ((min / 60) + (sec / 3600)); | ||
}; | ||
|
||
function decimal2dms(degrees) | ||
{ | ||
// decimal2dms: converts decimal degrees to degrees/minutes/seconds | ||
var minutes = (Math.abs(degrees) - Math.floor(Math.abs(degrees))) * 60; | ||
var seconds = Number(((minutes - Math.floor(minutes)) * 60).toFixed(2)); | ||
var minutes = Math.floor(minutes); | ||
var degrees = Math.floor(degrees); | ||
return {deg: degrees, min: minutes, sec: seconds}; | ||
}; |
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,13 @@ | ||
<?php | ||
$lat1 = $_GET['lat1']; | ||
$lon1 = $_GET['lon1']; | ||
$lat2 = $_GET['lat2']; | ||
$lon2 = $_GET['lon2']; | ||
|
||
$distance = (6371008 * acos(cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * | ||
cos(deg2rad($lon2) - deg2rad($lon1)) + | ||
sin(deg2rad($lat1)) * sin(deg2rad($lat2)))); | ||
|
||
echo 'Distance is '.round($distance).' meters, '. | ||
round($distance / 1609, 3).' miles.'; | ||
?> |
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,10 @@ | ||
if (a == b) | ||
{ | ||
// Statements here execute if a is equal to b | ||
... | ||
} | ||
else | ||
{ | ||
// Statements here execute if a is not equal to b | ||
... | ||
} |
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,15 @@ | ||
if (a == b) | ||
{ | ||
// Statements here execute if a is equal to b | ||
... | ||
} | ||
else if (a == c) | ||
{ | ||
// Statements here execute if a is equal to c | ||
... | ||
} | ||
else | ||
{ | ||
// Statements here execute if a is not equal to b or c | ||
... | ||
} |
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,5 @@ | ||
for (a = 0; a < 5; a++) | ||
{ | ||
// Statements here will execute five times | ||
... | ||
} |
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,5 @@ | ||
for (var a = 0; a < array.length; a++) | ||
{ | ||
// Actions can be performed here on array[a] | ||
... | ||
} |
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,7 @@ | ||
for (var a = array.length ? 1; a >= 0; a--) | ||
{ | ||
// Actions can be performed here on array[a], before deletion | ||
... | ||
|
||
array.splice(a, 1); | ||
} |
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,5 @@ | ||
while (a == b) | ||
{ | ||
// Statements here will execute until a is no longer equal to b | ||
... | ||
} |
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,12 @@ | ||
var found = -1; | ||
for (var a = 0; a < array.length; a++) | ||
{ | ||
if (array[a] == 'banana') | ||
{ | ||
found = a; | ||
break; | ||
} | ||
} | ||
|
||
if (found > -1) | ||
alert('banana found at element ' + found); |
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,16 @@ | ||
switch (a) | ||
{ | ||
case b: | ||
// Statements here execute if a is equal to b | ||
... | ||
break | ||
|
||
case c: | ||
// Statements here execute if a is equal to c | ||
... | ||
break; | ||
|
||
default: | ||
// Statements here execute if a is not equal to b or c | ||
... | ||
} |
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,19 @@ | ||
switch (currencyCode) | ||
{ | ||
case 'AUD': | ||
case 'CAD': | ||
case 'USD': | ||
var symbol = '$'; | ||
break; | ||
|
||
case 'GBP': | ||
var symbol = '£'; | ||
break; | ||
|
||
case 'JPY': | ||
var symbol = '¥'; | ||
break; | ||
|
||
default: | ||
var symbol = currencyCode; | ||
} |
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,12 @@ | ||
function doSomething(a) | ||
{ | ||
var b; | ||
// Actions can be performed here on the parameter, a | ||
... | ||
|
||
return b; | ||
}; | ||
|
||
... | ||
// Later in the code, we can invoke those actions: | ||
var c = doSomething(d); |
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,8 @@ | ||
function square (x) | ||
{ | ||
var sqr = x * x; | ||
return sqr; | ||
}; | ||
|
||
var nine = square(3); | ||
var thirtySix = square(6); |
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,5 @@ | ||
var x = {length: 6, width: 4, color: 'gray'}; | ||
x.area = function () | ||
{ | ||
return this.length * this.width; | ||
}; |
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,10 @@ | ||
var a; | ||
|
||
function doSomething() | ||
{ | ||
var b; | ||
var c = a + b; | ||
... | ||
}; | ||
... | ||
var d = a + b; // This statement will produce an error! |
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,6 @@ | ||
GEvent.addListener(map, 'zoomend', | ||
function (oldZoom, newZoom) | ||
{ | ||
// Perform actions here, after the map zooms, using the old and new zoom levels | ||
... | ||
}); |
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,13 @@ | ||
function addDataPoint(coordinates, name, description, style) | ||
{ | ||
var thisMarker = new GMarker(coordinates, options); | ||
... | ||
var sidebarRow = document.createElement('div'); | ||
... | ||
sidebarRow.onclick = | ||
function () | ||
{ | ||
// A click on the sidebar entry triggers a click on its associated marker | ||
GEvent.trigger(thisMarker, 'click') | ||
}; | ||
}; |
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,2 @@ | ||
Note: Most of the listings in this chapter are example code snippets to illustrate | ||
structure, not complete (nor syntactically valid) JavaScript. |
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 @@ | ||
var map; | ||
|
||
function loadMap() | ||
{ | ||
var mapDiv = document.getElementById('map'); | ||
|
||
if (!GBrowserIsCompatible()) | ||
mapDiv.innerHTML = 'Sorry, your browser isn\'t compatible with Google Maps.'; | ||
else | ||
{ | ||
map = new GMap2(mapDiv); | ||
map.setCenter(new GLatLng(39.8, -98.5), 4); | ||
|
||
GEvent.addListener(map, 'moveend', mapMoveEnd); | ||
} | ||
}; | ||
|
||
function mapMoveEnd() | ||
{ | ||
GLog.write(map.getCenter().toUrlValue()); | ||
}; |
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,17 @@ | ||
var map; | ||
|
||
GEvent.addDomListener(window, 'load', loadMap); | ||
GEvent.addDomListener(window, 'unload', GUnload); | ||
|
||
function loadMap() | ||
{ | ||
var mapDiv = document.getElementById('map'); | ||
|
||
if (!GBrowserIsCompatible()) | ||
mapDiv.innerHTML = 'Sorry, your browser isn\'t compatible with Google Maps.'; | ||
else | ||
{ | ||
map = new GMap2(mapDiv); | ||
map.setCenter(new GLatLng(39.8, -98.5), 4); | ||
} | ||
}; |
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,15 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>Better Event Listeners</title> | ||
<link type="text/css" rel="stylesheet" href="figure_c_01.css" /> | ||
<script type="text/javascript" | ||
src="http://maps.google.com/maps?file=api&v=2.124&key=ABQIAAAAN_IKAOv-fz9s2G9ZOihkhRQRiYyMmFOXXgCIe1BMmHtWUkPqiRROh48Y3J93_SbAzngd63KZMurFqQ"></script> | ||
<script type="text/javascript" src="listing_c_03.js"></script> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
</body> | ||
</html> |
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,14 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>Multiple API Keys</title> | ||
<link type="text/css" rel="stylesheet" href="figure_c_01.css" /> | ||
<script type="text/javascript" src="listing_c_05.js"></script> | ||
<script type="text/javascript" src="listing_c_02.js"></script> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
</body> | ||
</html> |
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,12 @@ | ||
// Set Google maps API key | ||
|
||
var scriptUrl = 'http://maps.google.com/maps?file=api&v=2.124&key='; | ||
|
||
if (location.host == 'www.somedomain.com') | ||
// Live server | ||
scriptUrl = scriptUrl + 'ABQIAAAA5wG_Upp3E2E2FvbwfSzPchQEMNwiYNXG5Xk21FzWxftqhFg'; | ||
else | ||
// Development server | ||
scriptUrl = scriptUrl + 'ABQIAAAAN_IKAOv-fz9s2G9ZOihkhRQRiYyMmFOXXgCIe1BMmHtWUkP'; | ||
|
||
document.write('<script type="text/javascript" src="' + scriptUrl + '"></script>'); |
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,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Module> | ||
<ModulePrefs title="US State Capitals" | ||
description="The capitals (and capitols) of the 50 US states." | ||
author="Sterling Udell" | ||
author_email="sterling.udell+mapplet@googlemail.com" | ||
screenshot="http://sterlingudell.com/bgmm/chapter_09/state_scr.png" | ||
thumbnail="http://sterlingudell.com/bgmm/chapter_09/state_thm.png"> | ||
<Require feature="sharedmap" /> | ||
<Require feature="dynamic-height" /> | ||
</ModulePrefs> | ||
<Content type="html"><![CDATA[ | ||
<style type="text/css"> | ||
p { | ||
font-size: 90%; | ||
} | ||
</style> | ||
<p id="list"></p> | ||
<script type="text/javascript"> | ||
var scriptUrl = _IG_GetCachedUrl('http://sterlingudell.com/bgmm/egeoxml.js'); | ||
document.write( | ||
'<script type="text/javascript" src="' + scriptUrl + '"><\/script>'); | ||
function xmlParsed() | ||
{ | ||
// xmlParsed: After KML processing, adjust the height of the sidebar display | ||
_IG_AdjustIFrameHeight(); | ||
}; | ||
function loadMap() | ||
{ | ||
// Initialize the map | ||
var map = new GMap2(); | ||
// Initialize a custom marker icon | ||
var starIcon = new GIcon(); | ||
starIcon.image = 'http://gmodules.com' + | ||
_IG_GetCachedUrl('http://sterlingudell.com/bgmm/markers/star.png'); | ||
starIcon.iconSize = new GSize(17, 17); | ||
starIcon.iconAnchor = new GPoint(8, 8); | ||
starIcon.infoWindowAnchor = new GPoint(12, 4); | ||
// Initialize the KML processor | ||
var url = 'http://sterlingudell.com/bgmm/chapter_09/state_capitals.kml'; | ||
var options = {sidebarid: 'list', | ||
markeroptions: {icon: starIcon}, | ||
nozoom: true}; | ||
var geoXml = new EGeoXml(map, url, options); | ||
// Attach an event handler for after the KML is processed | ||
GEvent.addListener(geoXml, 'parsed', xmlParsed); | ||
// Load the KML | ||
geoXml.parse(); | ||
}; | ||
_IG_RegisterOnloadHandler(loadMap); | ||
</script> | ||
]]></Content> | ||
</Module> |
Oops, something went wrong.