Using CSS to Display Fonts for Greek and Hebrew, but not English

September 30, 2016 | Bible Tools, HTML/CSS | 4 Comments

If you have a website that mixes Latin characters languages like English or Spanish with characters from a non-Latin language like Greek, Hebrew, or Arabic it usually requires a lot of extra CSS classes and <span> tags.

The good news is that there’s an easier way. You can do all of this without <span> tags for each language using the the CSS unicode-range property. It’s lets you create a font stack per language. Here’s a complete example with both Greek and Hebrew:

CSS

@font-face {
	font-family: EzraSILW;
	src: url(SILEOT.woff);
	unicode-range: U+0590-05FF;
}
@font-face {
	font-family: GentiumPlusW;
	font-style: italic;
	src: url(GentiumPlus-I.woff);
	unicode-range: U+0370-03FF, U+1F00-1FFF;
}
body {
	font-family: EzraSILW, GentiumPlusW, Arial;
}

I’ve defined two @font-faces, one for Greek and one for Hebrew, and then specified that they should only apply to the Unicode range for Greek and Hebrew respectively. Then the body font stack will apply them only to the characters in that range and then fall back to Arial for those outside the range.

HTML

<p>This paragraph is in English, using the core Latin unicode letters (unicode-range: U+00-FF) </p>
	
<p>Below this paragraph is a sentence in Greek (unicode-range: U+00-FF) John 1:1</p>
	
<p>Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς ἦν ὁ λόγος.</p>

<p>Below this paragraph is a sentence in Hebrew (unicode-range: U+00-FF) Genesis 1:1</p>
	
<p>בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃</p>

This is just some simple paragraphs with no additional markup, but because I have all the necessary fonts and unicode ranges it all “just works.” To see it in action, just hit the link below. Also, more details and techniques from Drew McLellan on 24ways.

Live Example »

 

Creating a Logo Background in Adobe Illustrator Using JavaScript

March 21, 2016 | JavaScript | 1 comment

Today, my team was working on options for creating a backdrop like you see at red carpet events or press conference with repeating logos. In our case, we wanted something our graduates could stand in front of at a commencement ceremony to take photos with their families.

One of our designers spent a lot of time manually positioning various sizes and colors of our logos to try out how different patterns might look work, and I thought this would be a perfect time to apply programming to get it just right and be able to iterate quickly. Thankfully Adobe has a great scripting library for doing just this sort of thing.

The Code

To make this work, open up Illustrator, create a new 16’x8′ document, make sure you have two images (JPG, SVG, AI, or anything Illustrator can understand) in the directory, then run the following script (File->Scripts->Other Script).

/*************************
Creates a repeating pattern of images on Illustrator
For a logo wall on a 16' x 8' area

John Dyer (http://j.hn/ 2016)
MIT license
**************************/

// variables/settings
var
	xRepeat = 9, // how many times the first logo will show on the top row (1 less for the second one)
	yRepeat = 5, // how many rows down
	xPadding = 0, // space from left and right edge (0 for bleed)
	yPadding = 400,	// space from top and bottom	
	item1Width = 650, // size in Illustrator units
	item2Width = 400, // size in Illustrator units
	item1Filename = 'DTS.seal.white.ai',
	item2Filename = 'DTS.logo.white.ai';


/// DO THE APP
if (typeof app != 'undefined') {
	runScript();
}

function runScript() {

	var
		// current document
		doc = app.documents[0],
		// add a new layer for our stuff
		layer = doc.layers.add(),

		// script file
		thisFile = new File($.fileName),
		basePath = thisFile.path,
		rootDir = basePath.replace('%20',' ') + '/';

		// open files for calculations
		file1 = new File(rootDir + item1Filename),
		item1 = layer.groupItems.createFromFile( file1 ),
		item1Ratio = item1.height / item1.width,
		item1Height = item1Width * item1Ratio,
		file2 = new File(rootDir + item2Filename),
		item2 = layer.groupItems.createFromFile( file2 ),
		item2Ratio = item2.height / item2.width,
		item2Height = item2Width * item2Ratio,

		// calculate image sizes and offsets
		largestHeight = Math.max(item1Height, item2Height),
		largestWidth =  Math.max(item1Width, item2Width),
		item1xOffset = largestWidth/2 - item1Width/2,
		item1yOffset = largestHeight/2 - item1Height/2,
		item2xOffset = largestWidth/2 - item2Width/2,
		item2yOffset = largestHeight/2 - item2Height/2,

		// calculate gaps
		docWidth = doc.width,
		docHeight = doc.height,
		xGap = (docWidth-largestWidth-xPadding*2) / (xRepeat-1),
		yGap = (docHeight-largestHeight-yPadding*2) / (yRepeat-1);

	// remove the images used for sizing
	item1.remove();
	item2.remove();

	layer.name = 'Fun new pattern';

	// main loop
	for (var x=0; x < xRepeat; x++) {

		for (var y=0; y < yRepeat; y++) {

			// check for the end of the row so we don't create too many
			var do1 = true;
			var do2 = true;

			if (x == xRepeat -1) {
				if (y % 2 == 0) {
					do1 = false;
				} else {
					do2 = false;
				}
			}

			if (do1) {
				var item1 = layer.groupItems.createFromFile( file1 ),
					item1x = xPadding + (x * xGap) + (y % 2 == 0 ? xGap/2 : 0) + item1xOffset,
					item1y = - (yPadding + (y * yGap) + item1yOffset);

				item1.name = 'logo1 ' + x + 'x' + y;
				item1.width = item1Width;
				item1.height = item1Height;
				item1.position = [item1x, item1y];
			}

			if (do2) {
				var item2 = layer.groupItems.createFromFile( file2 ),
					item2x = xPadding + (x * xGap) + (y % 2 != 0 ? xGap/2 : 0) + item2xOffset,
					item2y = - (yPadding + (y * yGap) + item2yOffset);

				item2.name = 'logo2 ' + x + 'x' + y;
				item2.width = item2Width;
				item2.height = item2Height;
				item2.position = [item2x, item2y];
			}
		}
	}
}

 

The Results

Here’s a few patterns we created. You can vary the logos, sizes, and spacing to make it work as needed.

Dallas Theological Seminary Logo Pattern Purple Reversed

Dallas Theological Seminary Logo Pattern White Commencement

Coloring Hebrew Vowels and Accents in HTML/CSS

May 18, 2013 | Bible Tools, HTML/CSS, JavaScript | 23 Comments

In a recent conversation with a Hebrew professor, we discussed adding color to Hebrew vowels and accents. If you’re unfamiliar, Hebrew is different from most Western languages in two main ways. First, it reads right to left (or rtl in HTML terms) and second vowels are represented as dots and lines that can be above or below the consonants.

Browsers seem to handle the rtl part pretty well, but they don’t do an awesome job with the vowel points. And for teaching purposes, it’s very hard to make the vowels a different color from the consonants. Below are a few attempts to do this using various combinations of HTML and JavaScript.

Standard Hebrew Text vs. Pointed Text

In the table below, you can see what Hebrew text looks like with and without vowels. Unlike English, when you remove the vowels the word still takes up the same amount of space.

Hebrew English
Consonants Only אלהים lhm
With Vowels אֱלֹהִים elohim

Coloring Individual Vowels

The first thing I wanted to try was adding <span> tags around vowels and coloring them differently. In the markup below you’ll see the letters pulled out of order with the English HTML, but it’ll give you an idea of what we’re trying to do.

Markup

א<span class="hebrew-vowel">ֱ</span>ל<span class="hebrew-vowel">ֹ</span>ה<span class="hebrew-vowel">ִ</span><span class="hebrew-accent-minor">֤</span>ים

CSS

.hebrew-vowel {
	color: #ff0000;
}
.hebrew-accent-minor, .hebrew-accent-major {
	color: #00ff00;
}

Demo

Hebrew English Result
Original אֱלֹהִ֤ים elohim Correct in all browsers
Span Colors אֱלֹהִ֤ים elohim Chrome/Safari: colored, but misaligned. Firefox/IE: aligned, but not colored

Results

In the example above if you’re using a Webkit based browser on a Mac, you’ll see nice red vowels and green accents. The only problem is that – depending on the font – the vowels are often shifted of place.

However, if you’re using Firefox or Internet Explorer, the vowels and accents stay in the right place, but apparently Firefox and IE can’t color them – they just stay black and ignore the CSS color. Lastly there is the strange case of PC/Chrome which renders the vowels as as standalone entities with an outline for the missing consonants (see screenshots at the end).

Layering Vowels with Absolute Positioning

Since Chrome can’t keep the vowels correctly aligned and Firefox and IE can’t color the vowels, I decided to try to layer the text using absolute positioning. In the example, I’ve tried putting the accents and vowels on a single layer and splitting them into two layers with different colors.

  1. Transparent: The bottom layer is the original text used to correctly size the outer span tag
  2. Green: The second layer has vowels removed and only leaves consonants and accents
  3. Red: The third layer has consonants removed and only leaves consonants and vowels
  4. Black: The top layer has only consonants layered on top of the colored layers below

Markup

<span class="hebrew-layers">
	<span class="hebrew-layers-original">אֱלֹהִים</span>
	<span class="hebrew-layers-accents">אלה֤ים</span>	
	<span class="hebrew-layers-vowels">אֱלֹהִים</span>
	<span class="hebrew-layers-consonants">אלהים</span>
</span>

CSS

.hebrew-layers {
	display: inline-block;
	position: relative;
}
.hebrew-layers .hebrew-layers-original {
	color: transparent;
}
.hebrew-layers .hebrew-layers-vowels {
	position: absolute;
	top: 0;
	right: 0;
	color: #ff0000;
}
.hebrew-layers .hebrew-layers-accents {
	position: absolute;
	top: 0;
	right: 0;
	color: #00ff00;
}
.hebrew-layers .hebrew-layers-consonants {
	position: absolute;
	top: 0;
	right: 0;
	color: #000000;
}

Demo: Layering

Style Demo Result
Original אֱלֹהִ֤ים Correct in all browsers.
Span Colors אֱלֹהִ֤ים Chrome/Safari: colored, but misaligned. Firefox/IE: aligned, but not colored
Single Layer אֱלֹהִ֤יםאֱלֹהִ֤יםאלהים Mostly works. Webkit often misaligns.
Double Layer אֱלֹהִיםאלה֤יםאֱלֹהִיםאלהים
Mostly works, but messes up accent/vowel pairs

Results

In this case, all browsers (including Firefox and IE) are now able to render different colors for the consonants and vowels. And, for the most part, they all put them in the right place.

There are, however, two problems. First, is that while IE and Firefox render things perfectly almost all the time, Chrome doesn’t always keep the consonants in the same position across layers and that creates what looks like a text-shadow effect. I love using and developing in Chrome, and this is one of the few ares I’ve ever found Chrome/Webkit to be the worst in an area (Chrome 26 vs. IE 10 vs. Firefox 21).

The second problem is a bit more obscure. Even in browsers that render more consistently (IE and Firefox), the layered solution isn’t perfect if you want a different color for accents and vowels. The reason is that the vowel and accent positions change depending on if a consonant has only a vowel, only an accent, or both an accent and a vowel. You can see this on the middle letter where the red dot [hiriq] and green arrow [yetiv] change positions in the two layers example. Since the accents are typically bigger I put them in a layer underneath the vowel point so the vowel would show up more clearly on top. So this effect is a kind of trade-off that may or may not be worth it depending on your teaching or reading goals.

Font Demos

While Chrome is by far the worst at rendering the layers consistently, all browsers have trouble at times with some popular Hebrew fonts. Below I’m including some popular ones (Ezra SIL and SBL Hebrew) with screenshots of how they render. At the end, there is a demo of an entire verse where problems are even more frequent.

Browser Font Matrix

Your Browser Mac/Chrome PC/Chrome Mac/Firefox PC/IE
Default Font
Original אֱלֹהִ֤ים
Span Colors אֱלֹהִ֤ים
Single Layer אֱלֹהִ֤יםאֱלֹהִ֤יםאלהים
Double Layer אֱלֹהִיםאלה֤יםאֱלֹהִיםאלהים
macchrome-default pcchrome-default macfirefox-default ie-default
Ezra SIL
Original אֱלֹהִ֤ים
Span Colors אֱלֹהִ֤ים
Single Layer אֱלֹהִ֤יםאֱלֹהִ֤יםאלהים
Double Layer אֱלֹהִיםאלה֤יםאֱלֹהִיםאלהים
macchrome-ezra pcchrome-ezra macfirefox-ezra ie-ezra
SBL Hebrew
Original אֱלֹהִ֤ים
Span Colors אֱלֹהִ֤ים
Single Layer אֱלֹהִ֤יםאֱלֹהִ֤יםאלהים
Double Layer אֱלֹהִיםאלה֤יםאֱלֹהִיםאלהים
macchrome-sbl pcchrome-sbl macfirefox-sbl ie-sbl
Arial
Original אֱלֹהִ֤ים
Span Colors אֱלֹהִ֤ים
Single Layer אֱלֹהִ֤יםאֱלֹהִ֤יםאלהים
Double Layer אֱלֹהִיםאלה֤יםאֱלֹהִיםאלהים
macchrome-arial pcchrome-arial macfirefox-arial ie-arial

Full Sentence Demo

I have this running in a Bible application:

Bible Web App: Hebrew style

And here is entire Hebrew sentence marked up in all the styles:

Original וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֙הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְה֑וֹם וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת עַל־פְּנֵ֥י הַמָּֽיִם׃
Span Colors וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֙הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְה֑וֹם וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת עַל־פְּנֵ֥י הַמָּֽיִם׃
Double Layered וְהָאָ֗רֶץוְהָאָרֶץוהא֗רץוהארץ הָיְתָ֥ההָיְתָההית֥ההיתה תֹ֙הוּ֙תֹהוּת֙הו֙תהו וָבֹ֔הוּוָבֹהוּוב֔הוובהו וְחֹ֖שֶׁךְוְחֹשֶׁךְוח֖שךוחשך עַלעַלעלעל־פְּנֵ֣יפְּנֵיפנ֣יפני תְה֑וֹםתְהוֹםתה֑וםתהום וְר֣וּחַוְרוּחַור֣וחורוח אֱלֹהִ֔יםאֱלֹהִיםאלה֔יםאלהים מְרַחֶ֖פֶתמְרַחֶפֶתמרח֖פתמרחפת עַלעַלעלעל־פְּנֵ֥יפְּנֵיפנ֥יפני הַמָּֽיִםהַמָּֽיִםהמיםהמים ׃

 

Conclusion

Right now, it seems there isn’t a perfect HTML/CSS way of colorizing the Hebrew pointing system, but the layering solution seems best for making it work across browsers as long as you don’t mind the accents being slightly out of place.

If you have any other ideas, please let me know!

This Site Best Viewed in Google Glass

April 17, 2013 | JavaScript | 17 Comments

Screen Shot 2013-04-17 at 1.35.20 PM

Google Glass is Coming!

You might have noticed that Google Glass is now shipping to early adopters and people who won the #ifihadglass competition.

Google has also released their developer documentation, and this means we’re about to start hearing about a lot of cool, new apps that people are building for Glass.

But sadly most of us won’t be able to test them out.

To remedy this sad state of affairs, I’ve come up with a simple tool to simulate using Glass on a website to start giving people ideas of how they might use it. I also really miss the “Best viewed in Internet Explorer” days of web development, so I’m doing what I can to bring back that culture.

Google Glass jQuery Plugin

Here’s the simple code (running on this post) to help people get started:

jQuery(function($) {

	// add Google's Roboto font
	$('<link href="http://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet" type="text/css" />')
		.appendTo( $('head') );

	// insert helpful message with base64 image
	$('<div style="position: fixed; top: 0; right: 0; background: rgba(0,0,0,0.9); border: solid 1px #eee; color: #fff; font-family: Roboto, Helvetica, sanserif; z-index: 9999;">' +
			'<div style="padding: 10%; font-size:3.0em; line-height: 1.5;">' +				
				'<p>Google Glass not detected.<p>' + 
				'<p>Please upgrade to view the top right corner of this site.</p>' + 
			'</div>' +
			'<img alt="Glass Logo" style="position: absolute; bottom: 10%; right: 10%;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAA3CAYAAABJnAVSAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/Ii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2MWCpMg2BySMvr6h4UvL4MQ/pJ9LS1mZ6eniY8njtDampd3sxrwuHqKup0T19fKz4AoEvS5WlSqZQMF9TIhbj29p48Py3jNzc7MdCoahVJpX0SZDk9TmIVBc3T2MajTwU8JkOlUpFsUREqQTH5TbJLMwtAJ8V5AMzkItgR4n8N6/9k4n1R0TpXde9e/cQJfWcoNSDOzPV1NQQdXV15YD0E2Fh/n84+xICpCMMKI+B7iapqKggMJAAmR5eb5/SYGJighVZgGRtbY1JO3gQKjwxGF5K6h/CTsDtoYXSoYkFDzh8/vy58rjmd2hdyPCwqvqbs/DgTrVXdi+KAQaO3ds7AV9VA1HKow8NQCwWC9HT0+seQJSkpH+9maYcAiUpSQkQJSlJCRAlKUkJECUpSQkQJSnpw6D/E2AA5pyokfLLVHEAAAAASUVORK5CYII=" />' + 
		'</div>')
		.appendTo( $('body') )
		.width( $(window).width() / 2 )
		.height( $(window).height() / 2 );
});

How Will You Use It?

I really hope this gets your ideas flowing.

If you use this incredible powerful new script or come up with any additions, please let me know.

Drawing 3D Objects and Buildings on Google Maps

February 11, 2013 | HTML/CSS, JavaScript | 23 Comments

As a web developer for a school, I’ve always enjoyed the challenge of creating a good campus map. The school I work for has a growing online seminary program to train pastors around the world, but helping people get around the main campus in Dallas is a still an integral part of any school.

TL;DR: Final result: DTS “3D” campus map

campus-map-sidebyside

Back Story: The Old Map

Several years ago, I wanted to make an interactive 3D building map, so I learned Papervision 3D a powerful Flash-based 3D engine (papervision map). I really liked it at the time but now that Flash is largely out of the picture, it was time to replace the map. I’ve wanted to port the old map to Three.js a JavaScript based 3D engine, but I found that conversion wasn’t as easy as I thought (three.js experiment).

Flash based map

To Google Maps

Since I also want to give first-class support to mobile devices, I decided to switch gears to Google Maps API since it runs really well on phones and tablets now. The problem was finding a way to display the map in an interesting and clear way.

Attempt #1: Flat polygons

My team and I drew out the floor line  of several buildings using Google’s Polygon tool with editable:true turned on, then we created a little loop to draw them all at once. It looks great, but the problem is that it’s not really clear that we’re showing buildings and other than color, it’s hard to tell what’s a parking lot.

var 
	mapCenter = [32.794488, -96.780372],
	mapOptions = {
		zoom: dts.maps.current.campus.zoom,
		center: new google.maps.LatLng(mapCenter[0], mapCenter[1]),
		mapTypeId: google.maps.MapTypeId.SATELLITE			

	},
	map = new google.maps.Map(document.getElementById("map"), mapOptions),
	buildingCoordinates = [
		[32.7948702128665,-96.78071821155265],
		[32.79478789915277,-96.780713852963],
		[32.794745606448785,-96.7807638091059],
		[32.79465594788115,-96.78065450908855],
		[32.794983444026556,-96.78026383449742],
		[32.79507153522898,-96.78037564908573],
		[32.79502490803293,-96.78043113728472],
		[32.79502635107838,-96.78054211368271]	
	],
	polygonCoords = [];

for (var j=0; j&lt;buildingCoordinates.length; j++) {
	polygonCoords.push(new google.maps.LatLng(
		buildingCoordinates[j][0], 
		buildingCoordinates[j][1]
	));	
}       

var polygon = new google.maps.Polygon({
  paths: polygonCoords,
  strokeColor: '#ee1111',
  strokeOpacity: 0.6,
  strokeWeight: 1,
  fillColor: '#eeeeee',
  fillOpacity: 0.7
});		

polygon.setMap(map);

campus-map-flat

Attempt #2: Roof

The next step was trying draw a floating roof simply by copying the the coordinates and adding a little bit to the latitude to make it seem like it was “up in the air.” The result doesn’t really make sense, but it starts to give some building like feeling:

campus-map-roofs

Attempt #3: Drawing a single “Wall”

My next thought was to remove the floor and then draw to draw a single wall on the South side to make it look like a wrap around wall. To do this, I looked through the coordinates and found the western and eastern edge and then tried to draw along it. It worked in many places, but in complex buildings it looked a little strange since there is only one “south” wall.

campus-map-single-wall

Attempt #4: Drawing individual Walls

To fix the problem of complex buildings, I decided to draw a polygon for each wall. This involves taking each floor coordinate and making a pair with the next one and then stretching it upward. Here’s what my new function looks like

function drawExcrudedShape(map, coordinates, height, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity) {

	var pairs = [],
		polygons = [];

	// build line pairs for each wall
	for (var i=0; i<coordinates.length; i++) {

		var point = coordinates[i],
			otherIndex = (i == coordinates.length-1) ? 0 : i+1,
			otherPoint = coordinates[otherIndex];

		pairs.push([point, otherPoint]);
	}

	// draw excrusions
	for (var i=0; i<pairs.length; i++) {

		var first = pairs[i][0],
			second = pairs[i][1],
			wallCoordinates =  [
				new google.maps.LatLng(first[0],first[1]),
				new google.maps.LatLng(first[0]+height,first[1]),
				new google.maps.LatLng(second[0]+height,second[1]),
				new google.maps.LatLng(second[0],second[1])									
			],
			polygon = new google.maps.Polygon({
				paths: wallCoordinates,
				strokeColor: strokeColor,
				strokeOpacity: strokeOpacity, 
				strokeWeight: strokeWeight,
				fillColor: fillColor,
				fillOpacity: fillOpacity
				zIndex: zIndexBase+i
			});

		polygon.setMap(map);

		polygons.push(polygon);
	}		

	return polygons;
}

Here is the result:

campus-map-multi-wall

This looks much better, but now we have two problems. First, some walls incorrectly overlap since I haven’t explicitly told Google the correct order to draw them in z-index problem. Second, if you were to rotate the map 180 degrees (see below), the buildings would be upside-down. This is because I’m not checking which wall is the southern most or the direction of the map.

campus-map-upsidedown

Attempt #5: Re-Ordering the Walls

So in my final attempt, I’ve taken the pairs above and ordered them based on the Google’s heading (map.getHeading()). This allows me to figure out which way is “up” and correctly layer the walls so that they look like real 3D objects. Here’s the final function and map result:

function drawExcrudedShape(map, coordinates, height, zIndexBase, heading, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity) {

	
	var pairs = [],
		polygons = [];
		
	// build line pairs
	for (var i=0; i<coordinates.length; i++) {
	
		var point = coordinates[i],
			otherIndex = (i == coordinates.length-1) ? 0 : i+1,
			otherPoint = coordinates[otherIndex];
	
		pairs.push([point, otherPoint]);
	}
	
	// sort the pairs based on which one has the "lowest" point based on the heading
	pairs.sort(function(a, b) {
		var aLowest = 0,
			bLowest = 0;
			
		switch (heading) {
			case 0:
				aLowest = Math.min(a[0][0], a[1][0]);
				bLowest = Math.min(b[0][0], b[1][0]);	
				
				
				if (aLowest < bLowest) {
					return 1;
				} else if (aLowest > bLowest) {
					return -1;
				} else {
					return 0;
				}						
			case 90:
				aLowest = Math.min(a[0][1], a[1][1]);
				bLowest = Math.min(b[0][1], b[1][1]);	
				
				if (aLowest < bLowest) {
					return 1;
				} else if (aLowest > bLowest) {
					return -1;
				} else {
					return 0;
				}						
	
			case 180:
				aLowest = Math.max(a[0][0], a[1][0]);
				bLowest = Math.max(b[0][0], b[1][0]);	
				
				
				if (aLowest > bLowest) {
					return 1;
				} else if (aLowest < bLowest) {
					return -1;
				} else {
					return 0;
				}	
			
			case 270:
				aLowest = Math.max(a[0][1], a[1][1]);
				bLowest = Math.max(b[0][1], b[1][1]);	
				
				if (aLowest > bLowest) {
					return 1;
				} else if (aLowest < bLowest) {
					return -1;
				} else {
					return 0;
				}	
		
		} 
	});
			
	// draw excrusions
	for (var i=0; i<pairs.length; i++) {
		
		var first = pairs[i][0],
			second = pairs[i][1],
			wallCoordinates = null;
			
		switch (heading) {
			case 0:
				wallCoordinates = [
					new google.maps.LatLng(first[0],first[1]),
					new google.maps.LatLng(first[0]+height,first[1]),
					new google.maps.LatLng(second[0]+height,second[1]),
					new google.maps.LatLng(second[0],second[1])									
				];
				break;
				
			case 90:
				wallCoordinates = [
					new google.maps.LatLng(first[0],first[1]),
					new google.maps.LatLng(first[0],first[1]+height),
					new google.maps.LatLng(second[0],second[1]+height),
					new google.maps.LatLng(second[0],second[1])									
				];
				break;
				
			case 180:
				wallCoordinates = [
					new google.maps.LatLng(first[0],first[1]),
					new google.maps.LatLng(first[0]-height,first[1]),
					new google.maps.LatLng(second[0]-height,second[1]),
					new google.maps.LatLng(second[0],second[1])									
				];
				break;
				
			case 270:
				wallCoordinates = [
					new google.maps.LatLng(first[0],first[1]),
					new google.maps.LatLng(first[0],first[1]-height),
					new google.maps.LatLng(second[0],second[1]-height),
					new google.maps.LatLng(second[0],second[1])									
				];
				break;
		}				
			
		var polygon = new google.maps.Polygon({
			paths: wallCoordinates,
			strokeColor: strokeColor,
			strokeOpacity: strokeOpacity, 
			strokeWeight: strokeWeight,
			fillColor: fillColor,
			fillOpacity: fillOpacity, 
			zIndex: zIndexBase+i
		});
		
		polygon.setMap(map);
		
		polygons.push(polygon);
	}		
	
	return polygons;
}

Final Map

Here is the final result. We’ve changed the parking lots to just have a colored border to help people know where to park and the full map has some interactivity on the buildings, lots, and departments. Go give it a try!

campus-map-final

Thanks to Google Maps Mania for the kind words here and here.

Hi, I'm John Dyer. In my day job, I build websites and create online seminary software for a seminary in Dallas. I also like to release open source tools including a pretty popular HTML5 video player and build tools that help people find best bible commentaries and do bible study. And just for fun, I also wrote a book on the theology of technology and media.

Fork me on GitHub

Social Widgets powered by AB-WebLog.com.