コード例 #1
0
 public function promo2Action()
 {
     header("Content-type: image/png");
     $im = imagecreatefromjpeg('images/continental.jpg');
     imagealphablending($im, true);
     imagesavealpha($im, true);
     $textcolor = imagecolorallocatealpha($im, 0, 0, 0, 0);
     $shadowcolor = imagecolorallocatealpha($im, 255, 255, 255, 64);
     $icon = imagecreatefrompng('images/small_green_ball.png');
     $icon_width = 10;
     $icon_height = 10;
     $model = new Facilities();
     $smodel = new Site();
     $sites = $smodel->getgroupby("facility_id");
     $markers = array();
     foreach ($model->get() as $facility) {
         $site = $sites[$facility->id][0];
         //pick the first site
         //create acronym
         $name = $facility->name;
         $name2 = str_replace("_", " ", $name);
         $tokens = explode(" ", $name2);
         $acro = "";
         foreach ($tokens as $token) {
             if ($token == "The") {
                 continue;
             }
             if ($token == "of") {
                 continue;
             }
             if ($token == "at") {
                 continue;
             }
             $acro .= $token[0];
         }
         $lat = $site->latitude;
         $long = $site->longitude;
         //merge to a site nearby
         $merged = false;
         if (isset($_REQUEST["acro"])) {
             foreach ($markers as &$m) {
                 if (abs($m["longitude"] - $long) < 2.5 and abs($m["latitude"] - $lat) < 0.5) {
                     $m["name"] .= "/" . $name;
                     $m["acronym"] .= "/" . $acro;
                     $m["longitude"] = ($m["longitude"] + $long) / 2;
                     $m["latitude"] = ($m["latitude"] + $lat) / 2;
                     $merged = true;
                     break;
                 }
             }
         } else {
             $acro = "";
         }
         //draw mark
         if (!$merged) {
             $marker = array("name" => $name, "acronym" => $acro, "longitude" => $long, "latitude" => $lat, "sites" => $sites[$facility->id]);
             $markers[] = $marker;
         }
     }
     //draw all markers
     $font = "images/verdanab.ttf";
     $font_size = 9;
     foreach ($markers as $marker) {
         list($x, $y) = $this->ll2xy($marker["longitude"], $marker["latitude"]);
         imagecopy($im, $icon, $x, $y, 0, 0, $icon_width, $icon_height);
         imagettftext($im, $font_size, 0, $x + $icon_width + 1, $y + $icon_height + 1, $shadowcolor, $font, $marker["acronym"]);
         imagettftext($im, $font_size, 0, $x + $icon_width, $y + $icon_height, $textcolor, $font, $marker["acronym"]);
     }
     imagepng($im);
     imagedestroy($im);
     $this->render("none", null, true);
 }