예제 #1
0
 /**
  * Get all map posts in a collection, including proximity.
  *
  * @param WP      $wp Wordpress object.
  * @param integer $collection_id Collection ID.
  * @param float   $lat Latitude.
  * @param float   $lon Longitude.
  * @return boolean True if the request was handled.
  */
 private static function get_all_map_posts_in_collection_with_proximity($wp, $collection_id, $lat, $lon)
 {
     $posts = XMapsDatabase::get_collection_map_objects($collection_id);
     $results = array();
     foreach ($posts as $post) {
         $geo = $post[1];
         $post = $post[0];
         $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, 'location_wkt' => $geo->location);
         $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;
             }
         }
         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;
             }
         }
         $results[] = $obj;
     }
     header('Content-Type: application/json');
     echo json_encode(array('data' => $results, 'request' => '/' . $wp->request . '?' . $_SERVER['QUERY_STRING']));
     return true;
 }
    ?>
		<div class="entry-meta">
			<?php 
    xmaps_posted_on();
    ?>
		</div><!-- .entry-meta -->
		<?php 
}
?>
	</header><!-- .entry-header -->

	<div class="entry-content">
		<?php 
the_content(sprintf(wp_kses(__('Continue reading %s <span class="meta-nav">&rarr;</span>', 'xmaps'), array('span' => array('class' => array()))), the_title('<span class="screen-reader-text">"', '"</span>', false)));
wp_link_pages(array('before' => '<div class="page-links">' . esc_html__('Pages:', 'xmaps'), 'after' => '</div>'));
$map_objects = XMapsDatabase::get_collection_map_objects(get_the_ID());
foreach ($map_objects as $mo) {
    $mo[0]->permalink = get_permalink($mo[0]->ID);
}
?>
		<div id="xmaps-map" style="height: 480px;"></div>
		<script>
		jQuery( function( $ ) {
				var conf = {
					"center": new google.maps.LatLng(0, 0),
					"streetViewControl": false,
					"zoom": 1,
					"minZoom": 1,
					"maxZoom": 20,
					"mapTypeId": google.maps.MapTypeId.TERRAIN,
					"panControl": true,
예제 #3
0
    /**
     * Searches for map collections within specified bounds.
     *
     * @param float $north Northmost bound.
     * @param float $east Eastmost bound.
     * @param float $south Southmost bound.
     * @param float $west Westmost bound.
     */
    public static function get_map_collections_in_bounds($north, $east, $south, $west)
    {
        global $wpdb;
        $tbl_name = $wpdb->get_blog_prefix(get_current_blog_id()) . self::LOCATION_TABLE_SUFFIX;
        $sql = 'SELECT l.reference_id
			FROM ' . $tbl_name . ' l
			WHERE l.reference_type = \'map-object\'
			AND ST_Intersects(l.location,
			ST_GeomFromText(\'POLYGON((%f %f, %f %f,
		%f %f, %f %f, %f %f))\'))';
        $results = $wpdb->get_results($wpdb->prepare($sql, array($west, $south, $east, $south, $east, $north, $west, $north, $west, $south)), OBJECT);
        $collections = array();
        foreach ($results as $result) {
            $tbl_name = $wpdb->get_blog_prefix(get_current_blog_id) . self::COLLECTION_TABLE_SUFFIX;
            $sql = 'SELECT c.collection_id, p.post_title
				FROM ' . $tbl_name . ' AS c
				LEFT JOIN ' . $wpdb->posts . ' p 
				ON p.id = c.collection_id
				WHERE map_object_id = %d';
            $results2 = $wpdb->get_results($wpdb->prepare($sql, array($result->reference_id)), OBJECT);
            foreach ($results2 as $r) {
                if (!array_key_exists($r->collection_id, $collections)) {
                    $collections[$r->collection_id] = $r;
                    $map_objects = XMapsDatabase::get_collection_map_objects($r->collection_id);
                    $locs = [];
                    foreach ($map_objects as $mo) {
                        $mo = $mo[1];
                        $locs[] = $mo->location;
                    }
                    $g = geoPHP::load('GEOMETRYCOLLECTION(' . implode(',', $locs) . ')');
                    $r->location = $g->centroid()->out('wkt');
                }
            }
        }
        foreach ($collections as $key => $collection) {
            $collection->permalink = get_permalink($collection->collection_id);
        }
        return $collections;
    }