Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sb_map() {
- global $add_my_script;
- $add_my_script = true;
- // Background image
- $image_id = get_field("beach_background", 'option');
- $thumb_size = 'full';
- $image = wp_get_attachment_image( $image_id, $thumb_size );
- $image_meta = wp_get_attachment_metadata( $image_id );
- $image_width = $image_meta['width'];
- $image_height = $image_meta['height'];
- // Data points
- $rows = get_field('neighbor_points', 'option');
- if ( $rows ) {
- $mapdata[$spots] = $spots;
- foreach($rows as $row) {
- $point = $row['y-axis'] . ',' . $row['x-axis'];
- if ( array_key_exists($point, $row) ) {
- $points[$point][] = $row;
- } else {
- $points[$point] = array($row);
- }
- }
- foreach($points as $point => $this_points_rows) {
- $tooltip = '';
- foreach($this_points_rows as $row) {
- $tooltip .= '<h4>' . $row['neighbor_name'] . '</h4>' . $row['neighbor_description'] .'';
- }
- $y = $this_points_rows[0]['y-axis'];
- $x = $this_points_rows[0]['x-axis'];
- // do math I guess
- $y_percent = $y/$image_height*100;
- $x_percent = $x/$image_width*100;
- $mapdata["spots"][] = array(
- "top" => $y_percent .'%',
- "left" => $x_percent.'%',
- "content" => $tooltip,
- "tooltipPosition" => 'tc'
- );
- }
- }
- $assembled = "<figure class='pictip' data-points='". json_encode($mapdata) . "'>";
- if( $image ) {
- $assembled .= $image;
- }
- $assembled .= '</figure>';
- return $assembled;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement