Adding mapping ability. Incomplete as of yet, but coming along nicely.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@32 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
61
views/elements/maps.ctp
Normal file
61
views/elements/maps.ctp
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Maps',true).'</h2>';
|
||||
?>
|
||||
</p>
|
||||
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
|
||||
<?php
|
||||
{
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$rows = array($paginator->sort('id'),
|
||||
$paginator->sort('name'),
|
||||
$paginator->sort('site_area_id'),
|
||||
$paginator->sort('width'),
|
||||
$paginator->sort('depth'),
|
||||
$paginator->sort('comment'));
|
||||
} else {
|
||||
$rows = array('Id', 'Name', 'Area', 'Width', 'Depth', 'Comment');
|
||||
}
|
||||
echo $html->tableHeaders($rows);
|
||||
|
||||
$rows = array();
|
||||
foreach ($maps as $map) {
|
||||
$rows[] = array($html->link($map['Map']['id'],
|
||||
array('controller' => 'maps',
|
||||
'action' => 'view',
|
||||
$map['Map']['id'])),
|
||||
$html->link($map['Map']['name'],
|
||||
array('controller' => 'maps',
|
||||
'action' => 'view',
|
||||
$map['Map']['id'])),
|
||||
$map['SiteArea']['name'],
|
||||
$map['Map']['width'] / 12,
|
||||
$map['Map']['depth'] / 12,
|
||||
$map['Map']['comment']);
|
||||
}
|
||||
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
if (isset($paginator)) {
|
||||
echo('<div class="paging">' . "\n");
|
||||
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
|
||||
echo(' | ');
|
||||
echo $paginator->numbers();
|
||||
echo(' | ');
|
||||
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
|
||||
echo('</div>' . "\n");
|
||||
}
|
||||
?>
|
||||
95
views/maps/image.ctp
Normal file
95
views/maps/image.ctp
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
// Create the image
|
||||
$image=imagecreate($info['width'], $info['depth']);
|
||||
|
||||
// Allocate our color palate
|
||||
foreach ($info['palate'] AS &$area) {
|
||||
foreach ($area AS &$type) {
|
||||
foreach ($type AS &$rgb) {
|
||||
if (is_array($rgb)
|
||||
&& isset($rgb['red'])
|
||||
&& isset($rgb['green'])
|
||||
&& isset($rgb['blue'])) {
|
||||
$rgb['color'] = imagecolorallocatealpha($image,
|
||||
$rgb['red'],
|
||||
$rgb['green'],
|
||||
$rgb['blue'],
|
||||
isset($rgb['alpha']) ? $rgb['alpha'] : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($info['border']) {
|
||||
// Create border around image
|
||||
imageline($image,
|
||||
0, 0,
|
||||
0, $info['depth'],
|
||||
$info['palate']['main']['layout']['border']['color']);
|
||||
imageline($image,
|
||||
0, 0,
|
||||
$info['width'], 0,
|
||||
$info['palate']['main']['layout']['border']['color']);
|
||||
imageline($image,
|
||||
$info['width']-1, 0,
|
||||
$info['width']-1, $info['depth']-1,
|
||||
$info['palate']['main']['layout']['border']['color']);
|
||||
imageline($image,
|
||||
0, $info['depth']-1,
|
||||
$info['width']-1, $info['depth']-1,
|
||||
$info['palate']['main']['layout']['border']['color']);
|
||||
}
|
||||
|
||||
// Go through each unit, placing it on the map
|
||||
foreach ($info['units'] AS $unit) {
|
||||
// Draw the unit borders
|
||||
imageline($image,
|
||||
$unit['left'], $unit['top'],
|
||||
$unit['right'], $unit['top'],
|
||||
$info['palate']['main']['layout']['wall']['color']);
|
||||
imageline($image,
|
||||
$unit['right'], $unit['top'],
|
||||
$unit['right'], $unit['bottom'],
|
||||
$info['palate']['main']['layout']['wall']['color']);
|
||||
imageline($image,
|
||||
$unit['right'], $unit['bottom'],
|
||||
$unit['left'], $unit['bottom'],
|
||||
$info['palate']['main']['layout']['wall']['color']);
|
||||
imageline($image,
|
||||
$unit['left'], $unit['bottom'],
|
||||
$unit['left'], $unit['top'],
|
||||
$info['palate']['main']['layout']['wall']['color']);
|
||||
|
||||
// Fill the unit according to its status
|
||||
imagefilledrectangle($image,
|
||||
$unit['left']+1, $unit['top']+1, $unit['right']-1, $unit['bottom']-1,
|
||||
$info['palate']['unit'][$unit['status']]['bg']['color']);
|
||||
|
||||
// If the unit is wide enough, run the text horizontal,
|
||||
// otherwise, we'll have to run it vertical.
|
||||
if ($unit['width'] > 100) {
|
||||
imagestring($image, 1,
|
||||
$unit['left']+3, $unit['top']+3,
|
||||
$unit['name'],
|
||||
$info['palate']['unit'][$unit['status']]['fg']['color']);
|
||||
}
|
||||
else {
|
||||
imagestringup($image, 1,
|
||||
$unit['left']+3, $unit['bottom']-3,
|
||||
$unit['name'],
|
||||
$info['palate']['unit'][$unit['status']]['fg']['color']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
header("Content-type: image/png");
|
||||
if (! imagepng($image)) {
|
||||
die("Couldn't output image!");
|
||||
}
|
||||
|
||||
// Clear image from memory
|
||||
imagedestroy($image);
|
||||
|
||||
// Closing PHP tag intentionally omitted
|
||||
3
views/maps/index.ctp
Normal file
3
views/maps/index.ctp
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="maps index">
|
||||
<?php echo $this->element('maps') ?>
|
||||
</div>
|
||||
25
views/maps/view.ctp
Normal file
25
views/maps/view.ctp
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<DIV>
|
||||
<?php
|
||||
echo $html->image(array('controller' => 'maps',
|
||||
'action' => 'map',
|
||||
$map['Map']['id']),
|
||||
array('alt' => 'Site Map',
|
||||
'class' => 'imagemap',
|
||||
'usemap' => '#mapimg'));
|
||||
?>
|
||||
</DIV>
|
||||
|
||||
<DIV>
|
||||
<?php
|
||||
/*
|
||||
$html->image(array('controller' => 'maps',
|
||||
'action' => 'legend',
|
||||
$map['Map']['id']),
|
||||
array('alt' => 'Site Map Legend'));
|
||||
*/
|
||||
?>
|
||||
</DIV>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user