Hi,
ich wollte mal fragen, also hier der Code:
Die Klasse:
Hier das Skript zum aufrufen der Klasse:
Nun meine Frage, wie kann ich diese Karte draggable machen, also so einstellen das man die Karte mit der Maus umherziehen kann?
Mfg Minecrafter001
ich wollte mal fragen, also hier der Code:
Die Klasse:
PHP-Code:
class MyMap { private $map_width; private $map_height; private $field_width_px; private $field_height_px; private $window_width; private $window_height; private $window_topleft_x; private $window_topleft_y; private $fields; private $x; private $y; public function setFields($fields) { $this->fields = $fields; } public function setField($x, $y, $field) { if (($x < 0) || ($y < 0) || ($x >= $this->map_width) || ($y >= $this->map_height)) return false; $this->fields[$x][$y] = $field; } public function getField($x, $y) { if (@isset($this->fields[$x][$y])) return $this->fields[$x][$y]; else return false; } public function setSize($width, $height) { $this->map_width = intval($width); $this->map_height = intval($height); } public function setFieldSize($width_px, $height_px) { $this->field_width_px = intval($width_px); $this->field_height_px = intval($height_px); } public function setPosition($x, $y) { if ($x < 0) $x = 0; if ($y < 0) $y = 0; if ($x >= $this->map_width) $x = $this->map_width - 1; if ($y >= $this->map_height) $y = $this->map_height - 1; $this->x = $x; $this->y = $y; $this->setWindowPosition($x - ($this->window_width >> 1), $y - ($this->window_height >> 1)); } public function setWindowSize($width, $height) { $this->window_width = intval($width); $this->window_height = intval($height); } public function setWindowPosition($x, $y) { if ($x < 0) $x = 0; if ($y < 0) $y = 0; if ($x+$this->window_width > $this->map_width) $x = $this->map_width - $this->window_width; if ($y+$this->window_height > $this->map_height) $y = $this->map_height - $this->window_height; $this->window_topleft_x = intval($x); $this->window_topleft_y = intval($y); } public function getWindowHtml() { $code = '<div id="mymapwindow">'; $window_bottomright_x = ($this->window_topleft_x + ($this->window_width-1) ); $window_bottomright_y = ($this->window_topleft_y + ($this->window_height-1) ); for($y=$this->window_topleft_y; $y <= $window_bottomright_y; $y++) { for($x=$this->window_topleft_x; $x <= $window_bottomright_x; $x++) { $field = $this->getField($x, $y); if ($field) { $color = $field['color']; $caption = $field['caption']; } else { $color = '#009933'; $caption = ''; }; $code .= '<div style="float: left; width: '.($this->field_width_px-1).'px; height: '.($this->field_height_px-1).'px; margin-right: 1px; margin-bottom: 1px; background-color: '.$color.'; text-align: center;" title=" '.$caption.' ">('.$x.'|'.$y.')</div>'; }; $code .= '<div style="clear:both;"></div>'; }; $code .= '</div>'; return $code; } public function showWindow() { echo $this->getWindowHtml(); } public function getHtml() { $code = '<div id="mymap">'; for($y=0; $y < $this->map_height; $y++) { for($x=0; $x < $this->map_width; $x++) { $field = $this->getField($x, $y); if ($field) { $color = $field['color']; $caption = $field['caption']; } else { $color = '#009933'; $caption = ''; }; $code .= '<div style="float: left; width: '.($this->field_width_px-1).'px; height: '.($this->field_height_px-1).'px; margin-right: 1px; margin-bottom: 1px; background-color: '.$color.'; text-align: center;" title=" '.$caption.' ">('.$x.'|'.$y.')</div>'; }; $code .= '<div style="clear:both;"></div>'; }; $code .= '</div>'; return $code; } public function show() { echo $this->getHtml(); } };
PHP-Code:
$map = new MyMap(); $map->setSize(25, 25); $map->setFieldSize(50, 30); $map->setField(18, 12, array("color"=>'#006699', "caption"=>'Wasser') ); $map->setField(10, 10, array("color"=>'#CCCCCC', "caption"=>'Berge') ); $map->setWindowSize(9, 9); $map->setPosition(16, 7); $map->showWindow();
Mfg Minecrafter001
Kommentar