diff --git a/site/controllers/maps_controller.php b/site/controllers/maps_controller.php index bab9533..88140c0 100644 --- a/site/controllers/maps_controller.php +++ b/site/controllers/maps_controller.php @@ -26,12 +26,12 @@ class MapsController extends AppController { * - Generates a site map page */ - function view($id = null) { + function view($id = null, $requested_width = 800) { if (!$id) { $this->Session->setFlash(__('Invalid Item.', true)); $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->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 */ - function mapInfo($id) { + function mapInfo($id, $requested_width) { // Set up array to hold the map information - $info = array('extents' => array(), 'units' => array(), - 'map_id' => $id, 'border' => true); - -/* // 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); */ + $info = array('map_id' => $id, + 'border' => true, + 'units' => array()); // Find all of the map/unit information from this SiteArea $this->Map->recursive = 2; @@ -73,19 +68,32 @@ class MapsController extends AppController { $map = $this->Map->read(null, $id); //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 // actual boundary extents, adjusting for a border - $top_adjustment = 5; - $left_adjustment = 5; - $info['extents']['top'] = 0; - $info['extents']['left'] = 0; - $info['extents']['bottom'] = $top_adjustment + $map['Map']['depth'] + 5; - $info['extents']['right'] = $left_adjustment + $map['Map']['width'] + 5; + $boundary_adjustment = 5; + $bottom = 2*$boundary_adjustment + $map['Map']['depth']; + $right = 2*$boundary_adjustment + $map['Map']['width']; + + // 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; // Go through each unit in the map, calculating the map location foreach ($map['Unit'] AS $unit) { - $lft = $unit['MapsUnit']['pt_left'] + $left_adjustment; - $top = $unit['MapsUnit']['pt_top'] + $top_adjustment; + $lft = $unit['MapsUnit']['pt_left'] + $boundary_adjustment; + $top = $unit['MapsUnit']['pt_top'] + $boundary_adjustment; $width = $unit['MapsUnit']['transpose'] @@ -97,7 +105,13 @@ class MapsController extends AppController { ? $unit['UnitSize']['width'] : $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'], 'name' => $unit['name'], 'left' => $lft, @@ -144,14 +158,22 @@ class MapsController extends AppController { $cols = 6; $rows = (int)((count($status) + $cols - 1) / $cols); - $info = array('extents' => array(), 'units' => array(), 'legend' => array()); - $info['legend']['width'] = 360; - $info['legend']['depth'] = 120; + $info = array('units' => array(), 'legend' => array()); - $info['extents']['right'] = $info['legend']['width'] * $cols; - $info['extents']['bottom'] = $info['legend']['depth'] * $rows; + // Get the overall site limits, and then compute the + // 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) { $info['units'][] = array('name' => $code, 'status' => $code, @@ -163,11 +185,11 @@ class MapsController extends AppController { 'bottom' => $top + $info['legend']['depth']); $top += $info['legend']['depth']; 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. */ - function image($info, $requested_width, $legend = false) { + function image($info, $legend = false) { //var $helpers = array('Html', 'Form', 'Javascript', 'Graph'); $this->layout = null; $this->autoLayout = false; @@ -225,30 +247,6 @@ class MapsController extends AppController { //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->render('image'); } diff --git a/site/views/maps/view.ctp b/site/views/maps/view.ctp index a6d5ef6..e6324df 100644 --- a/site/views/maps/view.ctp +++ b/site/views/maps/view.ctp @@ -1,15 +1,16 @@
- +url(array('controller' => 'units', @@ -26,7 +27,8 @@ image(array('controller' => 'maps', 'action' => 'map', - $info['map_id']), + $info['map_id'], + $info['width']), array('alt' => 'Site Map', 'class' => 'map', 'usemap' => '#mapzones')); @@ -38,7 +40,8 @@ image(array('controller' => 'maps', 'action' => 'legend', - $info['map_id']), + $info['map_id'], + $info['width']), array('alt' => 'Site Map Legend', 'class' => 'map')); ?>