Commit aa7d57a9 authored by Russ Fish's avatar Russ Fish

Add MapQuest-style pan and zoom controls to the floormap.php3 page, and

generally improve the clarity and appearance of the maps.  The scale factor
buttons numbered 1-5 actually correspond to scale factors of 1, 1.5, 2, 2.5,
and 3.

Notice that the floorimages table in the database now has an integer "scale"
column to distinguish the cached zoomed-in images with a suffix "-[1-5].jpg" .

I use jpeg files instead of the png files that were used before.  They look as
good or better, and are a third the size.  Panning around at a given zoom
factor just involves cropping out a different rectangle of the scaled-up
images.

The 0311X064_[1-4]fl.pdf floor map files we got from Michael Kay started
out life in Adobe Illustrator.  Although GhostScript/gv crash while
trying to draw the pdf files, extracting them into PostScript files in
Acrobat on Coke allows GhostScript to render them flawlessly.

I started out using gs to render jpeg files in the shell, and then
found that ImageMagick uses the same GhostScript renderer, and nicely
handles cropping, drawing and annotations, and format conversion as well.

The PostScript rendering gets slow at higher zoom factors.  So I cache the
zoomed floor images, scaled up by rendering the PostScript files at a finer
dot-pitch (density) in GhostScript, and then cropping out the right rectangle
to register them properly.

For readability, and to avoid having the thin lines and bitmap fonts used in
some parts of the PostScript map from falling between the pixel cracks, I
actually render at twice the pixel density and filter down to the final image
with a gaussian -sharpen option to keep it from looking blurry.

ImageMagick is callable from both the shell and as the Image::Magick package
in Perl.  I converted the Perl logic in floormap.in to use Image::Magick
instead of the GD graphics library, resulting in anti-aliased (smoothed)
drawing of the wireless node dots and labels on floor maps for a better
appearance.  Then I added optional scaling and centering arguments which
select the proper cached zoomed-in image, and drive the logic for cropping and
drawing.

I modified the floormap.php3 file to wrap an input form around a set of zoom
control buttons and the floormap image.  The zoom buttons set the scale
argument to the Perl floormap script called on the server.  The floor map
image itself is wrapped in a graphical submit button, so clicking on it
returns the mouse coordinates within the image, which are then sent to the
centering argument of the Perl script.
parent 4ed504e2
......@@ -1976,18 +1976,22 @@ last_net_act,last_cpu_act,last_ext_act);
('MEB', 1, 2, 'meb1fl-2.jpg', 'meb1fl-thumb.jpg'),
('MEB', 1, 3, 'meb1fl-3.jpg', 'meb1fl-thumb.jpg'),
('MEB', 1, 4, 'meb1fl-4.jpg', 'meb1fl-thumb.jpg'),
('MEB', 1, 5, 'meb1fl-5.jpg', 'meb1fl-thumb.jpg'),
('MEB', 2, 1, 'meb2fl-1.jpg', 'meb2fl-thumb.jpg'),
('MEB', 2, 2, 'meb2fl-2.jpg', 'meb2fl-thumb.jpg'),
('MEB', 2, 3, 'meb2fl-3.jpg', 'meb2fl-thumb.jpg'),
('MEB', 2, 4, 'meb2fl-4.jpg', 'meb2fl-thumb.jpg'),
('MEB', 2, 5, 'meb2fl-5.jpg', 'meb2fl-thumb.jpg'),
('MEB', 3, 1, 'meb3fl-1.jpg', 'meb3fl-thumb.jpg'),
('MEB', 3, 2, 'meb3fl-2.jpg', 'meb3fl-thumb.jpg'),
('MEB', 3, 3, 'meb3fl-3.jpg', 'meb3fl-thumb.jpg'),
('MEB', 3, 4, 'meb3fl-4.jpg', 'meb3fl-thumb.jpg'),
('MEB', 3, 5, 'meb3fl-5.jpg', 'meb3fl-thumb.jpg'),
('MEB', 4, 1, 'meb4fl-1.jpg', 'meb4fl-thumb.jpg'),
('MEB', 4, 2, 'meb4fl-2.jpg', 'meb4fl-thumb.jpg'),
('MEB', 4, 3, 'meb4fl-3.jpg', 'meb4fl-thumb.jpg'),
('MEB', 4, 4, 'meb4fl-4.jpg', 'meb4fl-thumb.jpg');
('MEB', 4, 4, 'meb4fl-4.jpg', 'meb4fl-thumb.jpg'),
('MEB', 4, 5, 'meb4fl-5.jpg', 'meb4fl-thumb.jpg');
1.275: Add timed-based mapping table for generic OSIDs. This augments the
nextosid mechinism of 1.114 making it possible to map a generic *-STD
......
This diff is collapsed.
......@@ -64,6 +64,97 @@ else {
unset($eid);
}
#
# Verify numeric scale and centering arguments.
#
if (isset($scale) && $scale != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $scale)) {
PAGEARGERROR("Invalid scale argument.");
}
}
else {
unset($scale);
}
#
# map_x and map_y are the map.x and map.y coordinates from clicking on the map.
#
if (isset($map_x) && $map_x != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $map_x)) {
PAGEARGERROR("Invalid map_x argument.");
}
}
else {
unset($map_x);
}
if (isset($map_y) && $map_y != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $map_y)) {
PAGEARGERROR("Invalid map_y argument.");
}
}
else {
unset($map_y);
}
#
# We need the previous scale and click coords, and offsets to interpret new click coords!
#
if (isset($last_scale) && $last_scale != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_scale)) {
PAGEARGERROR("Invalid last_scale argument.");
}
}
else {
unset($last_scale);
}
if (isset($last_x) && $last_x != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_x)) {
PAGEARGERROR("Invalid last_x argument.");
}
}
else {
unset($last_x);
}
if (isset($last_y) && $last_y != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_y)) {
PAGEARGERROR("Invalid last_y argument.");
}
}
else {
unset($last_y);
}
if (isset($last_x_off) && $last_x_off != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_x_off)) {
PAGEARGERROR("Invalid last_x_off argument.");
}
}
else {
unset($last_x_off);
}
if (isset($last_y_off) && $last_y_off != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_y_off)) {
PAGEARGERROR("Invalid last_y_off argument.");
}
}
else {
unset($last_y_off);
}
if (isset($last_notitles) && $last_notitles != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_notitles)) {
PAGEARGERROR("Invalid last_notitles argument.");
}
}
else {
unset($last_notitles);
}
#
# Figure out what channels are in use for the current building. We only
# have one building (MEB) at the moment, so this is quite easy.
......@@ -122,8 +213,8 @@ while ($row = mysql_fetch_array($query_result)) {
}
#
# Run the script. It will produce two output files; an image and an areamap.
# We want to embed both of these images into the page we send back. This
# Run the script. It will produce three output files; image, areamap, and state.
# We want to embed all of these images into the page we send back. This
# is painful!
#
# Need cleanup "handler" to make sure temp files get deleted!
......@@ -133,8 +224,9 @@ function CLEANUP()
global $prefix;
if (isset($prefix) && (connection_aborted())) {
unlink("${prefix}.png");
unlink("${prefix}.jpg");
unlink("${prefix}.map");
unlink("${prefix}.state");
unlink($prefix);
}
exit();
......@@ -143,7 +235,7 @@ register_shutdown_function("CLEANUP");
#
# Create a tempfile to use as a unique prefix; it is not actually used but
# serves the same purpose (the script uses ${prefix}.png and ${prefix}.map)
# serves the same purpose (The script uses ${prefix}.jpg and ${prefix}.map .)
#
$prefix = tempnam("/tmp", "floormap");
......@@ -158,7 +250,21 @@ $uniqueid = $matches[1];
$retval = SUEXEC("nobody", "nobody", "webfloormap -o $prefix " .
(isset($pid) ? "-e $pid,$eid " : "") .
(isset($floor) ? "-f $floor " : "") .
(isset($building) ? "$building" : ""),
(isset($building) ? "$building" : "") .
# From clicking on a zoom button.
(isset($scale) ? "-s $scale " : "") .
# From clicking on a map image.
(isset($map_x) ? "-c $map_x,$map_y " : "") .
# Previous image state info came from an included .state
# file, previously output by the Perl script along with the map.
(isset($last_scale) ? "-S $last_scale " : "") .
(isset($last_x) ? "-C $last_x,$last_y " : "") .
(isset($last_x_off) ? "-O $last_x_off,$last_y_off " : "") .
(isset($last_notitles) && $last_notitles ? "-T " : ""),
SUEXEC_ACTION_IGNORE);
if ($retval) {
......@@ -250,9 +356,51 @@ if (count($channels)) {
echo "</table>\n";
}
# Image
echo "<img src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">
</center>\n";
# Wrap the image and zoom controls together in an input form.
echo "<br>\n";
echo "<form method=\"get\" action=\"floormap.php3#zoom\">\n";
# Zoom controls may be clicked to set a new scale.
$curr_scale = (isset($scale) ? $scale : (isset($last_scale) ? $last_scale : 1));
echo " <a name=zoom></a>\n";
function zoom_btns($curr_scale) {
echo " <table align=\"center\" border=\"2\" cellpadding=\"0\" cellspacing=\"2\">\n";
echo " <tbody>\n";
echo " <tr>\n";
echo " <td><input type=\"image\" src=\"btn_zoom_out.jpg\"\n";
echo " name=\"scale\" value=\"" . max($curr_scale-1,1) . "\"><br></td>\n";
for ($i = 1; $i <= 5; $i++) {
$img = "btn_scale_" . $i . "_" . ($curr_scale==$i?"brt":"dim") . ".jpg";
echo " <td><input type=\"image\" src=\"$img\"\n";
echo " name=\"scale\" value=\"$i\"><br></td>\n";
}
echo " <td><input type=\"image\" src=\"btn_zoom_in.jpg\"\n";
echo " name=\"scale\" value=\"" . min($curr_scale+1,6) . "\"><br></td>\n";
echo " </tr>\n";
echo " </tbody>\n";
echo " </table>\n";
}
# The image may be clicked to set a new center-point.
zoom_btns($curr_scale); # Two copies of the zoom buttons bracket the image.
echo " Click on the map below to set the center point for a zoomed-in view.\n";
echo " <br>\n";
echo " <input name=\"map\" type=\"image\" style=\"border: 2px solid\" ";
echo "src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">\n";
echo " <br>\n";
echo " Click on the map above to set the center point for a zoomed-in view.\n";
zoom_btns($curr_scale);
# Hidden items are all returned as page arguments when any input control is clicked.
echo " <input type=\"hidden\" name=\"prefix\" value=\"$uniqueid\">\n";
# The last_* items come from a .state file with the map, from the Perl script.
if (! readfile("${prefix}.state")) {
TBERROR("Could not read ${prefix}.state", 1);
}
echo "</form>\n";
echo "</center>\n";
#
# Standard Testbed Footer
......
......@@ -38,8 +38,9 @@ function CLEANUP()
global $prefix;
if (isset($prefix)) {
unlink("${prefix}.png");
unlink("${prefix}.jpg");
unlink("${prefix}.map");
unlink("${prefix}.state");
unlink($prefix);
}
exit();
......@@ -50,8 +51,8 @@ register_shutdown_function("CLEANUP");
# Spit the areamap contained in the file out; it is fully formatted and
# called "floormap".
#
if (($fp = fopen("${prefix}.png", "r"))) {
header("Content-type: image/png");
if (($fp = fopen("${prefix}.jpg", "r"))) {
header("Content-type: image/jpg");
fpassthru($fp);
}
else {
......
......@@ -258,6 +258,7 @@ if (!isset($building) || $building == "" || !isset($floor) || $floor == "") {
DBQueryFatal("select b.building,b.title,f.floor,f.thumb_path ".
" from buildings as b ".
"left join floorimages as f on f.building=b.building " .
"where f.scale=1 " .
"order by b.building,f.floor");
if (! mysql_num_rows($building_result)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment