jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [HTML_ImageMap.class.php] - Diff between revs 1 and 85

Show entire file Ignore whitespace

Rev 1 Rev 85
Line 15... Line 15...
{ {
var $href; var $href;
var $name; var $name;
var $id; var $id;
var $alt; var $alt;
  var $z;
var $extrahtml; var $extrahtml;
   
function common_html() function common_html()
{ {
$h = ""; $h = "";
if($this->name != "") if($this->name != "")
{ {
$h .= " alt=\"".$this->name."\" "; // $h .= " alt=\"".$this->name."\" ";
$h .= " id=\"".$this->name."\" "; $h .= " id=\"".$this->name."\" ";
} }
if($this->href != "") if($this->href != "")
{ {
$h .= " href=\"".$this->href."\" "; $h .= " href=\"".$this->href."\" ";
} }
  else { $h .= " nohref "; }
if($this->extrahtml != "") if($this->extrahtml != "")
{ {
$h .= " ".$this->extrahtml." "; $h .= " ".$this->extrahtml." ";
} }
return $h; return $h;
Line 58... Line 60...
return '<area'.$this->common_html().' shape="poly" coords="'.$coordstring.'" />'; return '<area'.$this->common_html().' shape="poly" coords="'.$coordstring.'" />';
} }
   
function asJSON() function asJSON()
{ {
$json = "{ shape:'poly', npoints:".$this->npoints.", name:'".$this->name."',"; $json = "{ \"shape\":'poly', \"npoints\":".$this->npoints.", \"name\":'".$this->name."',";
   
$xlist = ''; $xlist = '';
$ylist = ''; $ylist = '';
foreach ($this->points as $point) foreach ($this->points as $point)
{ {
$xlist .= $point[0].","; $xlist .= $point[0].",";
$ylist .= $point[1].","; $ylist .= $point[1].",";
} }
$xlist = rtrim($xlist,", "); $xlist = rtrim($xlist,", ");
$ylist = rtrim($ylist,", "); $ylist = rtrim($ylist,", ");
$json .= " x: [ $xlist ], y:[ $ylist ], minx: ".$this->minx.", miny: ".$this->miny.", maxx:".$this->maxx.", maxy:".$this->maxy."}"; $json .= " \"x\": [ $xlist ], \"y\":[ $ylist ], \"minx\": ".$this->minx.", \"miny\": ".$this->miny.", \"maxx\":".$this->maxx.", \"maxy\":".$this->maxy."}";
   
return($json); return($json);
} }
   
function hitTest($x,$y) function hitTest($x,$y)
Line 120... Line 122...
die("Odd number of points!"); die("Odd number of points!");
} }
   
for ($i=0; $i<count($c); $i+=2) for ($i=0; $i<count($c); $i+=2)
{ {
$x = intval($c[$i]); $x = round($c[$i]);
$y = intval($c[$i+1]); $y = round($c[$i+1]);
$point = array($x,$y); $point = array($x,$y);
$xlist[] = $x; // these two are used to get the bounding box in a moment $xlist[] = $x; // these two are used to get the bounding box in a moment
$ylist[] = $y; $ylist[] = $y;
$this->points[] = $point; $this->points[] = $point;
} }
Line 147... Line 149...
function HTML_ImageMap_Area_Rectangle ( $name="", $href="",$coords) function HTML_ImageMap_Area_Rectangle ( $name="", $href="",$coords)
{ {
   
$c = $coords[0]; $c = $coords[0];
   
$x1 = $c[0]; $x1 = round($c[0]);
$y1 = $c[1]; $y1 = round($c[1]);
$x2 = $c[2]; $x2 = round($c[2]);
$y2 = $c[3]; $y2 = round($c[3]);
   
// sort the points, so that the first is the top-left // sort the points, so that the first is the top-left
if($x1>$x2) if($x1>$x2)
{ {
$this->x1=$x2; $this->x1=$x2;
Line 193... Line 195...
   
} }
   
function asJSON() function asJSON()
{ {
$json = "{ shape:'rect', "; $json = "{ \"shape\":'rect', ";
   
$json .= " x1:".$this->x1.", y1:".$this->y1.", x2:".$this->x2.", y2:".$this->y2.",name:'".$this->name."'}"; $json .= " \"x1\":".$this->x1.", \"y1\":".$this->y1.", \"x2\":".$this->x2.", \"y2\":".$this->y2.", \"name\":'".$this->name."'}";
   
return($json); return($json);
} }
   
} }
Line 229... Line 231...
{ {
$c = $coords[0]; $c = $coords[0];
   
$this->name = $name; $this->name = $name;
$this->href = $href; $this->href = $href;
$this->centx = $c[0]; $this->centx = round($c[0]);
$this->centy = $c[1]; $this->centy = round($c[1]);
$this->edgex = $c[2]; $this->edgex = round($c[2]);
$this->edgey = $c[3]; $this->edgey = round($c[3]);
} }
} }
   
class HTML_ImageMap class HTML_ImageMap
{ {
Line 263... Line 265...
if (is_object($element) && is_subclass_of($element, 'html_imagemap_area')) { if (is_object($element) && is_subclass_of($element, 'html_imagemap_area')) {
$elementObject = &$element; $elementObject = &$element;
} else { } else {
$args = func_get_args(); $args = func_get_args();
$className = "HTML_ImageMap_Area_".$element; $className = "HTML_ImageMap_Area_".$element;
$elementObject =& new $className($args[1],$args[2],array_slice($args, 3)); $elementObject = new $className($args[1],$args[2],array_slice($args, 3));
} }
   
$this->shapes[] =& $elementObject; $this->shapes[] =& $elementObject;
$this->nshapes++; $this->nshapes++;
// print $this->nshapes." shapes\n"; // print $this->nshapes." shapes\n";
Line 295... Line 297...
// update a property on all elements in the map that match a name // update a property on all elements in the map that match a name
// (use it for retro-actively adding in link information to a pre-built geometry before generating HTML) // (use it for retro-actively adding in link information to a pre-built geometry before generating HTML)
// returns the number of elements that were matched/changed // returns the number of elements that were matched/changed
function setProp($which, $what, $where) function setProp($which, $what, $where)
{ {
   
$count = 0; $count = 0;
for($i=0; $i<count($this->shapes); $i++) for($i=0; $i<count($this->shapes); $i++)
{ {
// this USED to be a substring match, but that broke some things // this USED to be a substring match, but that broke some things
// and wasn't actually used as one anywhere. // and wasn't actually used as one anywhere.
Line 310... Line 311...
case 'href': case 'href':
$this->shapes[$i]->href= $what; $this->shapes[$i]->href= $what;
break; break;
case 'extrahtml': case 'extrahtml':
$this->shapes[$i]->extrahtml= $what; $this->shapes[$i]->extrahtml= $what;
  #print "IMAGEMAP: Found $where and adding $which\n";
break; break;
} }
$count++; $count++;
} }
} }
return $count; return $count;
} }
   
  // update a property on all elements in the map that match a name as a substring
  // (use it for retro-actively adding in link information to a pre-built geometry before generating HTML)
  // returns the number of elements that were matched/changed
  function setPropSub($which, $what, $where)
  {
   
  $count = 0;
  for($i=0; $i<count($this->shapes); $i++)
  {
  if( ($where == "") || ( strstr($this->shapes[$i]->name,$where)!=FALSE ) )
  {
  switch($which)
  {
  case 'href':
  $this->shapes[$i]->href= $what;
  break;
  case 'extrahtml':
  $this->shapes[$i]->extrahtml= $what;
  break;
  }
  $count++;
  }
  }
  return $count;
  }
   
// Return the imagemap as an HTML client-side imagemap for inclusion in a page // Return the imagemap as an HTML client-side imagemap for inclusion in a page
function asHTML() function asHTML()
{ {
$html = '<map'; $html = '<map';
Line 329... Line 357...
$html .= ' name="'.$this->name.'"'; $html .= ' name="'.$this->name.'"';
} }
$html .=">\n"; $html .=">\n";
foreach ($this->shapes as $shape) foreach ($this->shapes as $shape)
{ {
$html .= $shape->asHTML(); $html .= $shape->asHTML()."\n";
$html .= "\n"; $html .= "\n";
} }
$html .= "</map>\n"; $html .= "</map>\n";
   
return $html; return $html;
Line 365... Line 393...
} }
   
// return HTML for a subset of the map, specified by the filter string // return HTML for a subset of the map, specified by the filter string
// (suppose you want some partof your UI to have precedence over another part // (suppose you want some partof your UI to have precedence over another part
// - the imagemap is checked from top-to-bottom in the HTML) // - the imagemap is checked from top-to-bottom in the HTML)
function subHTML($namefilter="",$reverseorder=false) // - skipnolinks -> in normal HTML output, we don't need areas for things with no href
  function subHTML($namefilter="",$reverseorder=false, $skipnolinks=false)
{ {
$html = ""; $html = "";
$preg = '/'.$namefilter.'/'; $preg = '/'.$namefilter.'/';
   
foreach ($this->shapes as $shape) foreach ($this->shapes as $shape)
{ {
if( ($namefilter == "") || ( preg_match($preg,$shape->name) )) # if( ($namefilter == "") || ( preg_match($preg,$shape->name) ))
  if( ($namefilter == "") || ( strstr($shape->name, $namefilter) !== FALSE ))
{ {
if($reverseorder) if(!$skipnolinks || $shape->href != "" || $shape->extrahtml != "" )
{  
$html = $shape->asHTML()."\n".$html;  
}  
else  
{ {
$html .= $shape->asHTML()."\n"; if($reverseorder)
  {
  $html = $shape->asHTML()."\n".$html;
  }
  else
  {
  $html .= $shape->asHTML()."\n";
  }
} }
   
} }
} }
return $html; return $html;

Powered by WebSVN 2.2.1