Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 13, 2016
0 parents commit d1e24c0
Show file tree
Hide file tree
Showing 153 changed files with 14,390 additions and 0 deletions.
Binary file added 4190.pdf
Binary file not shown.
Binary file added 4191.pdf
Binary file not shown.
Binary file added 9781430216209.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -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.


15 changes: 15 additions & 0 deletions README.md
@@ -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.
22 changes: 22 additions & 0 deletions appendix_a/listing_a_01.js
@@ -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};
};
13 changes: 13 additions & 0 deletions appendix_a/listing_a_02.php
@@ -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.';
?>
10 changes: 10 additions & 0 deletions appendix_b/listing_b_01.js
@@ -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
...
}
15 changes: 15 additions & 0 deletions appendix_b/listing_b_02.js
@@ -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
...
}
5 changes: 5 additions & 0 deletions appendix_b/listing_b_03.js
@@ -0,0 +1,5 @@
for (a = 0; a < 5; a++)
{
// Statements here will execute five times
...
}
5 changes: 5 additions & 0 deletions appendix_b/listing_b_04.js
@@ -0,0 +1,5 @@
for (var a = 0; a < array.length; a++)
{
// Actions can be performed here on array[a]
...
}
7 changes: 7 additions & 0 deletions appendix_b/listing_b_05.js
@@ -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);
}
5 changes: 5 additions & 0 deletions appendix_b/listing_b_06.js
@@ -0,0 +1,5 @@
while (a == b)
{
// Statements here will execute until a is no longer equal to b
...
}
12 changes: 12 additions & 0 deletions appendix_b/listing_b_07.js
@@ -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);
16 changes: 16 additions & 0 deletions appendix_b/listing_b_08.js
@@ -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
...
}
19 changes: 19 additions & 0 deletions appendix_b/listing_b_09.js
@@ -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;
}
12 changes: 12 additions & 0 deletions appendix_b/listing_b_10.js
@@ -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);
8 changes: 8 additions & 0 deletions appendix_b/listing_b_11.js
@@ -0,0 +1,8 @@
function square (x)
{
var sqr = x * x;
return sqr;
};

var nine = square(3);
var thirtySix = square(6);
5 changes: 5 additions & 0 deletions appendix_b/listing_b_12.js
@@ -0,0 +1,5 @@
var x = {length: 6, width: 4, color: 'gray'};
x.area = function ()
{
return this.length * this.width;
};
10 changes: 10 additions & 0 deletions appendix_b/listing_b_13.js
@@ -0,0 +1,10 @@
var a;

function doSomething()
{
var b;
var c = a + b;
...
};
...
var d = a + b; // This statement will produce an error!
6 changes: 6 additions & 0 deletions appendix_b/listing_b_14.js
@@ -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
...
});
13 changes: 13 additions & 0 deletions appendix_b/listing_b_15.js
@@ -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')
};
};
2 changes: 2 additions & 0 deletions appendix_b/readme.txt
@@ -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.
21 changes: 21 additions & 0 deletions appendix_c/listing_c_01.js
@@ -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());
};
17 changes: 17 additions & 0 deletions appendix_c/listing_c_02.js
@@ -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);
}
};
15 changes: 15 additions & 0 deletions appendix_c/listing_c_03.html
@@ -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&amp;v=2.124&amp;key=ABQIAAAAN_IKAOv-fz9s2G9ZOihkhRQRiYyMmFOXXgCIe1BMmHtWUkPqiRROh48Y3J93_SbAzngd63KZMurFqQ"></script>
<script type="text/javascript" src="listing_c_03.js"></script>
</head>
<body>
<div id="map"></div>
</body>
</html>
14 changes: 14 additions & 0 deletions appendix_c/listing_c_04.html
@@ -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>
12 changes: 12 additions & 0 deletions appendix_c/listing_c_05.js
@@ -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>');
61 changes: 61 additions & 0 deletions appendix_c/listing_c_06.xml
@@ -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>

0 comments on commit d1e24c0

Please sign in to comment.