How I made my maps using MacHTTP (Version 1.2.3)

(Note: Our WWW server has since moved to a "dedicated" Unix machine (HP 9000/433), and I make no guarantee that these scripts will work without modifications on the present release of MacHTTP. A listing of useful tools is provided at the BIAP Systems, and these tools (probably) do not require you to write scripts. Note that the newest MacHTTP is now called WebSTAR, and is distributed by StarNine Technologies. An excellent list of WWW Development Resources for Macintoshes is provided by Jon Wiederspan, and I recommend people to refer to his page.)
In addition, I have some Web tutorials which may be of interest to those who are planning to make image maps

I created the maps of Holmes hall using the following tools:

HyperMapEdit creates imagemap files that can be used by NCSA httpd. Unfortunately, we can't directly use this file with MacHTTP. The format of the file is pretty simple. There are three kinds of lines that can be placed in this simple text file: In the description above, the URL corresponds to the locator, but for my own script, this can only exist on the local Macintosh. In the NCSA httpd code, there are three types of methods (circle, poly, and rect) but I chose to implement only the rect type. If other types exist in the map file, my script will ignore it. Using HyperMapEdit will create a map file.

After creating a map file (make sure you name the file with the .map extension), run my script to make maps. One word of caution, however. The script expects a certain library to exist on the server, and needs to be configured accordingly.

The script will create a script containing a series of if ... else statements. Include the script in your document using the ismap for an inlined graphics. For example:
<a href="bigmap.script"><img src="bigmap.gif" ismap></a>

If you have comments of questions, send me email. I'm sure I can try to answer the question. (This was a kludgy hack, but it did seem to work, provided you don't change the name of your hard drive -- I found out the hard way.) The scripts follow:


Any questions or comments should be directed to the following address:
ben@wiliki.eng.hawaii.edu (Ben Yoshino)
Link to Jon Wiederspan corrected on Wednesday, July 3, 1996
Some links added on Thursday, February 15, 1996
Last updated on Tuesday, August 2, 1994
Minor link changes on Friday, May 5, 1995
Typo fixed on Tuesday, May 16, 1995
Copyright © 1996 Ben Yoshino
All rights reserved.


MakeMapScript.script

This script takes a .map file for NCSA httpd and converts it to an AppleScript script for use with MacHTTP. There are configuration options at the beginning of the document, which must be changed to reflect your site. I have a feeling the file will not transfer properly depending on the user. The script contains some Macintosh-specific characters which will not translate properly. For example, the ¬ stands for the line-continuation character; ¾ is less than or equal to and „ is greater than or equal to .

(* Configuration options *)
set myscript_location to "Macintosh HD:MacHTTP Folder:" & ¬
	"Scripts:bensmaplib.script"
set mybasehref to "http://www.myschool.edu/"
(* Local function definitions *)
to fix_colons of the_string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"/"}
	set the_path to text items in the_string
	set AppleScript's text item delimiters to {":"}
	set result to text items in the_path as string
	if length of result is 0 then return result
	if character 1 of result is ":" then
		set AppleScript's text item delimiters to {}
		set result to (characters 2 through -1 of result) as string
	end if
	set AppleScript's text item delimiters to saveDelim
	return result
end fix_colons

to unfix_colons of the_string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set the_path to text items in the_string
	set AppleScript's text item delimiters to {"/"}
	set result to text items in the_path as string
	if length of result is 0 then return result
	if character 1 of result is "/" then
		set AppleScript's text item delimiters to {}
		set result to (characters 2 through -1 of result) as string
	end if
	set AppleScript's text item delimiters to saveDelim
	return result
end unfix_colons

to makenewname of oldFileName
	set theFileString to oldFileName as string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set theFile to last text item of theFileString
	set period to offset of ".map" in theFile
	if period is not equal to 0 then
		set AppleScript's text item delimiters to {}
		set root to characters 1 through period of theFile as string
		set AppleScript's text item delimiters to {":"}
		set newFile to root & "script"
		set newstring to text items 1 through -2 of theFileString & {newFile}
		set newFileName to text items of newstring as string
	else
		set newFileName to ""
	end if
	set AppleScript's text item delimiters to saveDelim
	return newFileName
end makenewname

to convertnums from a_string
	if (count a_string) is equal to 0 then return {-1, -1}
	set comma to offset of "," in a_string
	set theLast to count a_string
	set x to (text 1 thru (comma - 1) of a_string) as integer
	set y to (text (comma + 1) thru theLast of a_string) as integer
	return {x, y}
end convertnums

to readMapFile from MapFileName
	local fileLine, fileList
	set fileList to {}
	try
		set refNum to open file alias MapFileName for reading
	on error
		return fileList
	end try
	set defaultline to {"default", ""}
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {space}
	repeat
		try
			set fileLine to read file refNum
		on error -- assume EOF hit
			exit repeat
		end try
		--		set fileLine to fixcolons of fileLine
		if length of fileLine is not 0 and ¬
			first character of fileLine is not "#" then
			set currentItem to text items of fileLine
			set itemCount to count currentItem
			set item 2 of currentItem to fixcolons of ¬
				item 2 of currentItem
			if (item 1 of currentItem) is equal to "default" then
				set defaultline to {currentItem}
			else
				repeat with indx from 3 to itemCount
					set item indx of currentItem to convertnums from ¬
						item indx of currentItem
				end repeat
				set fileList to fileList & {currentItem}
			end if
		end if
	end repeat
	set AppleScript's text item delimiters to saveDelim
	set fileList to fileList & defaultline
	close file refNum
	return fileList
end readMapFile

(* Beginning of main script *)
set mymap to (choose file with prompt "Please select a map file:" ¬
	of type {"TEXT", "text"}) as string
set newFile to makenewname of mymap
if newFile is equal to "" then
	display dialog "I'm sorry, the file has to end with \".map\"" ¬
		buttons {"Ok"} default button "Ok"
	return
end if
set maps to readMapFile from mymap
set itemCount to number of items in maps
set outputText to "set the_code to (load script " & ¬
	"alias \"" & myscript_location & "\")" & return & ¬
	"set base_html to \"<base href=\\\"" & mybasehref & "\"" & ¬
	return & "tell the_code" & return & ¬
	"set currentpath to (getappldir of \"MacHTTP 1.2.3\")" & return & ¬
	"if http_search_args is equal to \"\" then" & return & ¬
	"return \"<h1>Sorry</h1>nothing to search for\"" & return & ¬
	"end if" & return & "set coords to convertnums from http_search_args" & ¬
	return & "set x to item 1 of coords" & return & ¬
	"set y to item 2 of coords" & return
repeat with itx from 1 to itemCount
	set thisItem to item itx of maps
	if item 1 of thisItem is equal to "rect" then
		set x1 to item 1 of item 3 of thisItem
		set y1 to item 2 of item 3 of thisItem
		set x2 to item 1 of item 4 of thisItem
		set y2 to item 2 of item 4 of thisItem
		set outputText to outputText & "if x „ " & x1 & " and x ¾ " & x2 & ¬
			" and y „ " & y1 & " and y ¾ " & y2 & " then " & return & ¬
			"set outputFile to \"" & item 2 of thisItem & "\"" & return & ¬
			"else "
	else if item 1 of thisItem is equal to "default" then
		set outputText to outputText & return & "set outputFile to  \"" & ¬
			item 2 of thisItem & "\"" & return
	end if
end repeat
set outputText to outputText & "end if" & return & ¬
	"set fileName to unfix_colons of outputFile" & return & ¬
	"return base_html & fileName & \"\\\">\" & " & ¬
	"returnContents of (currentpath & outputFile)" & return & ¬
	"end tell"
try
	create file newFile owner "ToyS" -- ScriptEditor
on error
	set answer to display dialog "This file already exists." & return & ¬
		"Overwrite?" buttons {"Ok", "Cancel"} default button "Cancel"
	if answer is equal to "Cancel" then return
end try
set fileDes to open file alias newFile for writing
try
	write file fileDes text outputText
on error
	set answer to display dialog "Error encountered when attempting to" & ¬
		"write." buttons {"Ok"}
end try
close file fileDes

bensmaplib.script

This script is used by other scripts created by MakeMapScript.script in order to determine the click locations. It MUST be stored as a compiled script. I have a feeling the file will not transfer properly depending on the user. The script contains some Macintosh-specific characters which will not translate properly.

(* Ben's Library 
This contains several functions which can be used for map searching -- especially
with .map files
*)
to convertnums from a_string
	if (count a_string) is equal to 0 then return {-1, -1}
	set comma to offset of "," in a_string
	set theLast to count a_string
	set x to (text 1 thru (comma - 1) of a_string) as integer
	set y to (text (comma + 1) thru theLast of a_string) as integer
	return {x, y}
end convertnums

to getappldir of whichAppl
	set currentpath to path to application whichAppl as string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set num to number of text items in currentpath
	set new to text items 1 through (num - 1) of currentpath
	set currentpath to (new as string) & ":"
	set AppleScript's text item delimiters to saveDelim
	return currentpath
end getappldir

to returnContents of returnFileName
	local fileText
	set fileText to ""
	try
		set refNum to open file alias returnFileName for reading
	on error
		return "<title>Script Error</title><h1>Couldn't find requested file.</h1>" & ¬
			"Filename: <i>" & returnFileName & "</i>"
	end try
	repeat
		try
			set fileText to fileText & (read file refNum) & (ASCII character of 32)
		on error -- assume EOF hit
			exit repeat
		end try
	end repeat
	close file refNum
	return fileText
end returnContents

to fix_colons of the_string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"/"}
	set the_path to text items in the_string
	set AppleScript's text item delimiters to {":"}
	set result to text items in the_path as string
	if character 1 of result is ":" then
		set result to (text 2 through -1 of result) as string
	end if
	set AppleScript's text item delimiters to saveDelim
	return result
end fix_colons

to unfix_colons of the_string
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set the_path to text items in the_string
	set AppleScript's text item delimiters to {"/"}
	set result to text items in the_path as string
	if character 1 of result is "/" then
		set result to (text 2 through -1 of result) as string
	end if
	set AppleScript's text item delimiters to saveDelim
	return result
end unfix_colons