Fixed the underlying hotlink map to match the coordinates of the actual image. Also fixed a few issues with requested_width propogation, although there may still be some bugs.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@35 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -26,12 +26,12 @@ class MapsController extends AppController {
|
|||||||
* - Generates a site map page
|
* - Generates a site map page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function view($id = null) {
|
function view($id = null, $requested_width = 800) {
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
$this->set('info', $this->mapInfo($id));
|
$this->set('info', $this->mapInfo($id, $requested_width));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class MapsController extends AppController {
|
|||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
$this->image($this->mapInfo($id), $requested_width);
|
$this->image($this->mapInfo($id, $requested_width));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@@ -56,16 +56,11 @@ class MapsController extends AppController {
|
|||||||
* mapInfo
|
* mapInfo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function mapInfo($id) {
|
function mapInfo($id, $requested_width) {
|
||||||
// Set up array to hold the map information
|
// Set up array to hold the map information
|
||||||
$info = array('extents' => array(), 'units' => array(),
|
$info = array('map_id' => $id,
|
||||||
'map_id' => $id, 'border' => true);
|
'border' => true,
|
||||||
|
'units' => array());
|
||||||
/* // Find all of the map/unit information from this SiteArea */
|
|
||||||
/* $this->Map->SiteArea->recursive = 3; */
|
|
||||||
/* $this->Map->SiteArea->Site->unbindModel(array('hasMany' => array('SiteArea'))); */
|
|
||||||
/* $this->Map->unbindModel(array('belongsTo' => array('SiteArea'))); */
|
|
||||||
/* $map = $this->Map->SiteArea->read(null, $site_area_id); */
|
|
||||||
|
|
||||||
// Find all of the map/unit information from this SiteArea
|
// Find all of the map/unit information from this SiteArea
|
||||||
$this->Map->recursive = 2;
|
$this->Map->recursive = 2;
|
||||||
@@ -73,19 +68,32 @@ class MapsController extends AppController {
|
|||||||
$map = $this->Map->read(null, $id);
|
$map = $this->Map->read(null, $id);
|
||||||
//pr($map);
|
//pr($map);
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* The preference would be to leave all things "screen" related
|
||||||
|
* to reside in the view. However, two separate views need this
|
||||||
|
* information. The 'view' needs it to include a clickable map
|
||||||
|
* that corresponds to the map image, and of course, the 'map'
|
||||||
|
* (or 'image') view needs it to render the image. So, in the
|
||||||
|
* controller for now, unless I come up with a better idea.
|
||||||
|
*****/
|
||||||
|
|
||||||
// Get the overall site limits, and then compute the
|
// Get the overall site limits, and then compute the
|
||||||
// actual boundary extents, adjusting for a border
|
// actual boundary extents, adjusting for a border
|
||||||
$top_adjustment = 5;
|
$boundary_adjustment = 5;
|
||||||
$left_adjustment = 5;
|
$bottom = 2*$boundary_adjustment + $map['Map']['depth'];
|
||||||
$info['extents']['top'] = 0;
|
$right = 2*$boundary_adjustment + $map['Map']['width'];
|
||||||
$info['extents']['left'] = 0;
|
|
||||||
$info['extents']['bottom'] = $top_adjustment + $map['Map']['depth'] + 5;
|
// Scale things according to desired display width
|
||||||
$info['extents']['right'] = $left_adjustment + $map['Map']['width'] + 5;
|
$screen_adjustment_factor = $requested_width / $right;
|
||||||
|
|
||||||
|
// Define the overall canvas size
|
||||||
|
$info['width'] = $right * $screen_adjustment_factor;
|
||||||
|
$info['depth'] = $bottom * $screen_adjustment_factor;
|
||||||
|
|
||||||
// Go through each unit in the map, calculating the map location
|
// Go through each unit in the map, calculating the map location
|
||||||
foreach ($map['Unit'] AS $unit) {
|
foreach ($map['Unit'] AS $unit) {
|
||||||
$lft = $unit['MapsUnit']['pt_left'] + $left_adjustment;
|
$lft = $unit['MapsUnit']['pt_left'] + $boundary_adjustment;
|
||||||
$top = $unit['MapsUnit']['pt_top'] + $top_adjustment;
|
$top = $unit['MapsUnit']['pt_top'] + $boundary_adjustment;
|
||||||
|
|
||||||
$width =
|
$width =
|
||||||
$unit['MapsUnit']['transpose']
|
$unit['MapsUnit']['transpose']
|
||||||
@@ -97,7 +105,13 @@ class MapsController extends AppController {
|
|||||||
? $unit['UnitSize']['width']
|
? $unit['UnitSize']['width']
|
||||||
: $unit['UnitSize']['depth'];
|
: $unit['UnitSize']['depth'];
|
||||||
|
|
||||||
$info['units'][$unit['id']] =
|
$lft *= $screen_adjustment_factor;
|
||||||
|
$top *= $screen_adjustment_factor;
|
||||||
|
$width *= $screen_adjustment_factor;
|
||||||
|
$depth *= $screen_adjustment_factor;
|
||||||
|
|
||||||
|
//$info['units'][$unit['id']] =
|
||||||
|
$info['units'][] =
|
||||||
array( 'id' => $unit['id'],
|
array( 'id' => $unit['id'],
|
||||||
'name' => $unit['name'],
|
'name' => $unit['name'],
|
||||||
'left' => $lft,
|
'left' => $lft,
|
||||||
@@ -144,14 +158,22 @@ class MapsController extends AppController {
|
|||||||
$cols = 6;
|
$cols = 6;
|
||||||
$rows = (int)((count($status) + $cols - 1) / $cols);
|
$rows = (int)((count($status) + $cols - 1) / $cols);
|
||||||
|
|
||||||
$info = array('extents' => array(), 'units' => array(), 'legend' => array());
|
$info = array('units' => array(), 'legend' => array());
|
||||||
$info['legend']['width'] = 360;
|
|
||||||
$info['legend']['depth'] = 120;
|
|
||||||
|
|
||||||
$info['extents']['right'] = $info['legend']['width'] * $cols;
|
// Get the overall site limits, and then compute the
|
||||||
$info['extents']['bottom'] = $info['legend']['depth'] * $rows;
|
// actual boundary extents, adjusting for a border
|
||||||
|
$boundary_adjustment = 2;
|
||||||
|
$bottom = 2*$boundary_adjustment + $cols*360;
|
||||||
|
$right = 2*$boundary_adjustment + $rows*120;
|
||||||
|
|
||||||
$top = $lft = 0;
|
// Scale things according to desired display width
|
||||||
|
$screen_adjustment_factor = $requested_width / $right;
|
||||||
|
|
||||||
|
// Define the overall canvas size
|
||||||
|
$info['width'] = $right * $screen_adjustment_factor;
|
||||||
|
$info['depth'] = $bottom * $screen_adjustment_factor;
|
||||||
|
|
||||||
|
$top = $lft = $boundary_adjustment;
|
||||||
foreach ($status AS $code => $color) {
|
foreach ($status AS $code => $color) {
|
||||||
$info['units'][] = array('name' => $code,
|
$info['units'][] = array('name' => $code,
|
||||||
'status' => $code,
|
'status' => $code,
|
||||||
@@ -163,11 +185,11 @@ class MapsController extends AppController {
|
|||||||
'bottom' => $top + $info['legend']['depth']);
|
'bottom' => $top + $info['legend']['depth']);
|
||||||
$top += $info['legend']['depth'];
|
$top += $info['legend']['depth'];
|
||||||
if ($top >= $info['legend']['depth'] * $rows) {
|
if ($top >= $info['legend']['depth'] * $rows) {
|
||||||
$top = 0; $lft += $info['legend']['width'];
|
$top = $boundary_adjustment; $lft += $info['legend']['width'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->image($info, $requested_width, true);
|
$this->image($info, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@@ -178,7 +200,7 @@ class MapsController extends AppController {
|
|||||||
* color palates before rendering the PNG image.
|
* color palates before rendering the PNG image.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function image($info, $requested_width, $legend = false) {
|
function image($info, $legend = false) {
|
||||||
//var $helpers = array('Html', 'Form', 'Javascript', 'Graph');
|
//var $helpers = array('Html', 'Form', 'Javascript', 'Graph');
|
||||||
$this->layout = null;
|
$this->layout = null;
|
||||||
$this->autoLayout = false;
|
$this->autoLayout = false;
|
||||||
@@ -225,30 +247,6 @@ class MapsController extends AppController {
|
|||||||
|
|
||||||
//pr($info);
|
//pr($info);
|
||||||
|
|
||||||
/*****
|
|
||||||
* The preference would be to leave all things "screen" related
|
|
||||||
* to reside in the view. However, two separate views need this
|
|
||||||
* information. The 'view' needs it to include a clickable map
|
|
||||||
* that corresponds to the map image, and of course, the 'map'
|
|
||||||
* (or 'image') view needs it to render the image. So, in the
|
|
||||||
* controller for now, unless I come up with a better idea.
|
|
||||||
*****/
|
|
||||||
|
|
||||||
// Scale things according to desired display width
|
|
||||||
$screen_adjustment_factor = $requested_width / $info['extents']['right'];
|
|
||||||
|
|
||||||
// Define image size
|
|
||||||
$info['width'] = $info['extents']['right'] * $screen_adjustment_factor;
|
|
||||||
$info['depth'] = $info['extents']['bottom'] * $screen_adjustment_factor;
|
|
||||||
|
|
||||||
// Go through each unit, adjusting map locations
|
|
||||||
foreach ($info['units'] AS &$unit) {
|
|
||||||
$unit['left'] *= $screen_adjustment_factor;
|
|
||||||
$unit['right'] *= $screen_adjustment_factor;
|
|
||||||
$unit['top'] *= $screen_adjustment_factor;
|
|
||||||
$unit['bottom'] *= $screen_adjustment_factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->set(compact('info'));
|
$this->set(compact('info'));
|
||||||
$this->render('image');
|
$this->render('image');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<?php /* -*- mode:PHP -*- */ ?>
|
<?php /* -*- mode:PHP -*- */ ?>
|
||||||
|
|
||||||
<DIV class="map">
|
<DIV class="map">
|
||||||
<MAP name="mapzones"><?php
|
<MAP name="mapzones">
|
||||||
|
<?php
|
||||||
{// for indentation purposes
|
{// for indentation purposes
|
||||||
// Go through each unit, adding a clickable region for the unit
|
// Go through each unit, adding a clickable region for the unit
|
||||||
foreach ($info['units'] AS $unit){
|
foreach ($info['units'] AS $unit){
|
||||||
echo(' <area shape="rect"' .
|
echo(' <area shape="rect"' .
|
||||||
' coords="' .
|
' coords="' .
|
||||||
$unit['left'] . ',' .
|
$unit['left'] . ',' .
|
||||||
$unit['right'] . ',' .
|
|
||||||
$unit['top'] . ',' .
|
$unit['top'] . ',' .
|
||||||
|
$unit['right'] . ',' .
|
||||||
$unit['bottom'] .
|
$unit['bottom'] .
|
||||||
'" href="' .
|
'" href="' .
|
||||||
$html->url(array('controller' => 'units',
|
$html->url(array('controller' => 'units',
|
||||||
@@ -26,7 +27,8 @@
|
|||||||
<?php
|
<?php
|
||||||
echo $html->image(array('controller' => 'maps',
|
echo $html->image(array('controller' => 'maps',
|
||||||
'action' => 'map',
|
'action' => 'map',
|
||||||
$info['map_id']),
|
$info['map_id'],
|
||||||
|
$info['width']),
|
||||||
array('alt' => 'Site Map',
|
array('alt' => 'Site Map',
|
||||||
'class' => 'map',
|
'class' => 'map',
|
||||||
'usemap' => '#mapzones'));
|
'usemap' => '#mapzones'));
|
||||||
@@ -38,7 +40,8 @@
|
|||||||
<?php
|
<?php
|
||||||
echo $html->image(array('controller' => 'maps',
|
echo $html->image(array('controller' => 'maps',
|
||||||
'action' => 'legend',
|
'action' => 'legend',
|
||||||
$info['map_id']),
|
$info['map_id'],
|
||||||
|
$info['width']),
|
||||||
array('alt' => 'Site Map Legend',
|
array('alt' => 'Site Map Legend',
|
||||||
'class' => 'map'));
|
'class' => 'map'));
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user