/** * Composites visible Feature/Event markers, regions, and labels onto * image. * * @param object $imagickImage An Imagick object * * @return void */ private function _addEventLayer($imagickImage) { if ($this->width < 200 || $this->height < 200) { return; } $markerPinPixelOffsetX = 12; $markerPinPixelOffsetY = 38; require_once HV_ROOT_DIR . '/../src/Event/HEKAdapter.php'; $hek = new Event_HEKAdapter(); // Query the HEK $events = $hek->getEvents($this->date, array()); if ($events === false) { return false; } // Lay down all relevant event REGIONS first $allowedFRMs = $this->events->toArray(); foreach ($events as $index => $event) { $found = false; foreach ($allowedFRMs as $j => $frm) { if ($event['event_type'] == $frm['event_type'] && ($frm['frm_name'] == 'all' || $frm['frm_name'] == str_replace(' ', '_', $event['frm_name']) || strpos($frm['frm_name'], str_replace(' ', '_', $event['frm_name'])) !== false)) { $found = true; break; } } if ($found === false) { continue; } if (array_key_exists('hv_poly_width_max_zoom_pixels', $event)) { $width = round($event['hv_poly_width_max_zoom_pixels'] * ($this->maxPixelScale / $this->roi->imageScale())); $height = round($event['hv_poly_height_max_zoom_pixels'] * ($this->maxPixelScale / $this->roi->imageScale())); if ($width >= 1 && $height >= 1) { $region_polygon = new IMagick(HV_ROOT_DIR . '/' . urldecode($event['hv_poly_url'])); $x = ($event['hv_poly_hpc_x_final'] - $this->roi->left()) / $this->roi->imageScale(); $y = ($event['hv_poly_hpc_y_final'] - $this->roi->top()) / $this->roi->imageScale(); $region_polygon->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); $imagickImage->compositeImage($region_polygon, IMagick::COMPOSITE_DISSOLVE, $x, $y); } } } if (isset($region_polygon)) { $region_polygon->destroy(); } // Now lay down the event MARKERS foreach ($events as $index => $event) { $found = false; $allowedFRMs = $this->events->toArray(); foreach ($allowedFRMs as $j => $frm) { if ($event['event_type'] == $frm['event_type'] && ($frm['frm_name'] == 'all' || $frm['frm_name'] == str_replace(' ', '_', $event['frm_name']) || strpos($frm['frm_name'], str_replace(' ', '_', $event['frm_name'])) !== false)) { $found = true; continue; } } if ($found === false) { continue; } $marker = new IMagick(HV_ROOT_DIR . '/resources/images/eventMarkers/' . $event['event_type'] . '.png'); $x = ($event['hv_hpc_x_final'] - $this->roi->left()) / $this->roi->imageScale() - $markerPinPixelOffsetX; $y = (-$event['hv_hpc_y_final'] - $this->roi->top()) / $this->roi->imageScale() - $markerPinPixelOffsetY; $imagickImage->compositeImage($marker, IMagick::COMPOSITE_DISSOLVE, $x, $y); if ($this->eventsLabels == true) { $x = ($event['hv_hpc_x_final'] - $this->roi->left()) / $this->roi->imageScale() + 11; $y = (-$event['hv_hpc_y_final'] - $this->roi->top()) / $this->roi->imageScale() - 24; $count = 0; if (!array_key_exists('hv_labels_formatted', $event) || count($event['hv_labels_formatted']) < 1) { $event['hv_labels_formatted'] = array('Event Type' => $event['concept']); } foreach ($event['hv_labels_formatted'] as $key => $value) { //Fix unicode $value = str_replace(array('u03b1', 'u03b2', 'u03b3', 'u00b1', 'u00b2'), array('α', 'β', 'γ', '±', '²'), $value); // Outline words in black $text = new IMagickDraw(); $text->setTextEncoding('utf-8'); $text->setFont(HV_ROOT_DIR . '/../resources/fonts/DejaVuSans.ttf'); $text->setFontSize(10); $text->setStrokeColor('#000C'); $text->setStrokeAntialias(true); $text->setStrokeWidth(3); $text->setStrokeOpacity(0.3); $imagickImage->annotateImage($text, $x, $y + $count * 12, 0, $value); // Write words in white over outline $text = new IMagickDraw(); $text->setTextEncoding('utf-8'); $text->setFont(HV_ROOT_DIR . '/../resources/fonts/DejaVuSans.ttf'); $text->setFontSize(10); $text->setFillColor('#ffff'); $text->setTextAntialias(true); $text->setStrokeWidth(0); $imagickImage->annotateImage($text, $x, $y + $count * 12, 0, $value); $count++; } // Cleanup $text->destroy(); } } if (isset($marker)) { $marker->destroy(); } }
/** * Gets a JSON-formatted list of Features/Events for the requested time * range and FRMs * * Example Query: * * http://www.lmsal.com/hek/her * ?cosec=2&cmd=search&type=column&event_type=** * &event_starttime=2010-07-01T00:00:00 * &event_endtime=2010-07-02T00:00:00&event_coordsys=helioprojective * &x1=-1200&x2=1200&y1=-1200&y2=1200&result_limit=200 * &return=kb_archivid,concept,frm_institute,obs_observatory,frm_name, * event_starttime,event_endtime,hpc_x,hpc_y,hpc_bbox * * QUERYING A SINGLE EVENT: * * http://www.lmsal.com/hek/her * ?cosec=2&cmd=search&type=column&event_type=** * &event_starttime=0001-01-01T00:00:00 * &event_endtime=9999-01-01T00:00:00 * &event_coordsys=helioprojective&x1=-1200&x2=1200&y1=-1200&y2=1200 * ¶m0=kb_archivid&op0== * &value0=ivo://helio-informatics.org/FA1550_YingnaSu_20090415_154655 * &return=required * * @return void */ public function getEvents() { include_once HV_ROOT_DIR . '/../src/Event/HEKAdapter.php'; $hek = new Event_HEKAdapter(); // Query the HEK $events = $hek->getEvents($this->_params['startTime'], $this->_options); header('Content-Type: application/json'); echo json_encode($events); }