<?php /** * Display fragment for Map Object post edit screen. * * @package xmaps * @author Dominic Price <*****@*****.**> * @license http://www.gnu.org/licenses/agpl-3.0.en.html * @link https://github.com/horizon-institute/xmaps */ $locations = XMapsDatabase::get_map_object_locations(get_the_ID(), 'map-object'); $location = ''; if (!empty($locations)) { $location = $locations[0]; } ?> <div id="xmaps-controls"> Drawing mode: <select id="xmaps-controls-mode"> <option value="point">Point</option> <option value="area">Area</option> </select> <button id="xmaps-controls-draw">Draw</button> <button id="xmaps-controls-clear">Clear Map</button> </div> <input type="hidden" name="xmaps-location-entry" id="xmaps-location-entry" value="<?php echo esc_attr($location->location); ?> " /> <div id="xmaps-map" style="height: 480px;"></div>
/** * Get a specific map post including proxity. * * @param WP $wp Wordpress object. * @param integer $post_id Post ID. * @param float $lat Latitude. * @param float $lon Longitude. * @return boolean True if the request was handled. */ private static function get_specific_map_post_with_proximity($wp, $post_id, $lat, $lon) { $post = get_post($post_id); if (!$post) { return false; } $user = get_userdata($post->post_author); $obj = array('ID' => $post->ID, 'post_title' => $post->post_title, 'author_id' => $post->post_author, 'display_name' => $user->display_name, 'post_date_gmt' => $post->post_date_gmt); $closest = null; $closest_dist = null; $locations = XMapsDatabase::get_map_object_locations($post->ID, 'map-object'); $origin = new Point($lon, $lat); $origin->setSRID(XMAPS_SRID); foreach ($locations as $location) { $dest = geoPHP::load($location->location); $dist = XMapsGeo::distance($origin, $dest); if (null == $closest_dist || $dist < $closest_dist) { $closest = $dest; $closest_dist = $dist; } } $wkt = ''; if (count($locations) > 0) { $obj->location_wkt = $locations[0]->location; } if (null != $closest) { $obj['distance'] = $closest_dist; $obj['bearing'] = XMapsGeo::bearing($origin, $closest); $obj['type'] = $closest->geometryType(); } if (isset($wp->query_vars['user-id']) && isset($wp->query_vars['period'])) { $found = XMapsDatabase::has_post_been_found($post_id, $wp->query_vars['user-id'], $wp->query_vars['period']); if ($found) { $obj['found'] = $found; } } header('Content-Type: application/json'); echo json_encode(array('data' => $obj, 'request' => '/' . $wp->request . '?' . $_SERVER['QUERY_STRING'])); return true; }