示例#1
0
function alt_inline_js_tabbed_map()
{
    global $epl_settings;
    $epl_am_single_map_height = isset($epl_settings['epl_am_single_map_height']) ? intval($epl_settings['epl_am_single_map_height']) : 400;
    $position = isset($epl_settings['epl_am_infobox_position']) ? $epl_settings['epl_am_infobox_position'] : 'top';
    $coordinates = epl_am_get_position_coordinates($position);
    $coord_left = $coordinates[0];
    $coord_top = $coordinates[1];
    if (!is_epl_post()) {
        return;
    }
    global $property;
    if ($property->get_property_meta('property_address_display') == 'yes') {
        $property_address_coordinates = $property->get_property_meta('property_address_coordinates');
    } else {
        $property_address_coordinates = '';
    }
    // if coordinates are not present than geocode address to get coordinates
    if (trim($property_address_coordinates) == '') {
        if ($property->get_property_meta('property_address_display') == 'yes') {
            $address = epl_property_get_the_full_address();
        } else {
            $address = $property->get_property_meta('property_address_suburb') . ', ';
            $address .= $property->get_property_meta('property_address_state') . ', ';
            $address .= $property->get_property_meta('property_address_postal_code');
        }
        $address = apply_filters('epl_map_address', $address);
        $address = urlencode(strtolower(trim($address)));
        $geourl = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($address) . "&sensor=false";
        $response = epl_remote_url_get($geourl);
        if (!empty($response)) {
            $geocoordinates = $response[0]->geometry->location->lat . ',' . $response[0]->geometry->location->lng;
            update_post_meta($property->post->ID, 'property_address_coordinates', $geocoordinates);
            $property_address_coordinates = $property->get_property_meta('property_address_coordinates');
        }
    }
    $title = $property->post->post_title;
    $zoom = apply_filters('epl_am_tabbed_map_zoom', 16);
    $zoom_sat = $zoom + 2;
    $content = epl_am_make_infobox();
    $map_start = isset($epl_settings['epl_am_default_map_type']) ? $epl_settings['epl_am_default_map_type'] : 'SATELLITE';
    $marker_icon = apply_filters('epl_am_marker_icon', epl_am_get_property_image($property));
    ?>
	<style>
		#map-alt { position:relative; top:0; bottom:0;height:400px; max-width:800px; width:100%; }
	</style>
	<script>
        jQuery(document).ready(function(){
	  L.mapbox.accessToken = 'pk.eyJ1IjoianNvbnd1IiwiYSI6ImNpa3YwZnpzMzAwZTN1YWtzYWcwNXg2ZzMifQ.v6YZ9axqDwZSlzbjmMOfTg';
          var latlng = <?php 
    echo '"' . $property_address_coordinates . '"';
    ?>
;
          var latlngArry = latlng.split(",");
          var lat = 0;
          var lng = 0;
          if(latlngArry.length == 2){
              var lat = parseFloat(latlngArry[0]);
              var lng = parseFloat(latlngArry[1]);
          }
	  var map = L.mapbox.map('map-alt', null, {
	      maxZoom: 18
	  }).setView([lat, lng], 16);
	
	  var layers = {
	      Satellite: L.mapbox.tileLayer('mapbox.streets-satellite'),
	      Streets: L.mapbox.tileLayer('mapbox.streets'),
	      Outdoors: L.mapbox.tileLayer('mapbox.outdoors')
	  };
	  featureLayer = L.mapbox.featureLayer({
    	      // this feature is in the GeoJSON format: see geojson.org
              // for the full specification
              type: 'Feature',
              geometry: {
                 type: 'Point',
                 // coordinates here are in longitude, latitude order because
                 // x, y is the standard for GeoJSON and many formats
                 coordinates: [
		     lng,
                     lat
                 ]
              },
              properties: {
                 title: <?php 
    echo '"' . $title . '"';
    ?>
,
                 //description: '',
                 // one can customize markers by adding simplestyle properties
                 // https://www.mapbox.com/guides/an-open-platform/#simplestyle
                 'marker-size': 'large',
                 'marker-color': '#BE9A6B',
                 'marker-symbol': 'building'
              }
          }).addTo(map);
	  layers.Satellite.addTo(map);
	  L.control.layers(layers).addTo(map);
          L.control.scale().addTo(map);
          featureLayer.on('click', function(e) {
              map.panTo(e.layer.getLatLng());
          });
        });
	</script> 

	<?php 
}
示例#2
0
/**
 * Map Shortcode
 * @since 1.0
**/
function epl_advanced_map($atts)
{
    global $property, $post;
    if (is_null($post)) {
        return;
    }
    extract(shortcode_atts(array('post_type' => epl_all_post_types(), 'limit' => '30', 'coords' => '', 'display' => 'card', 'zoom' => '17', 'height' => '', 'cluster' => false, 'property_status' => '', 'home_open' => false, 'location' => ''), $atts));
    if (!is_array($post_type)) {
        if (!empty($post_type)) {
            $post_type = explode(",", $post_type);
        }
    }
    $args = array('post_type' => $post_type, 'posts_per_page' => $limit, 'paged' => '1', 'epl_nopaging' => 'true', 'meta_query' => array(array('key' => 'property_address_coordinates', 'value' => '', 'compare' => '!=')));
    if (!empty($property_status)) {
        if (!is_array($property_status)) {
            if (!empty($property_status)) {
                $property_status = explode(",", $property_status);
                $property_status = array_filter($property_status);
            }
        }
        if (($key = array_search('withdrawn', $property_status)) !== false) {
            unset($property_status[$key]);
        }
        if (($key = array_search('offmarket', $property_status)) !== false) {
            unset($property_status[$key]);
        }
        $args['meta_query'][] = array('key' => 'property_status', 'value' => $property_status, 'compare' => 'IN');
    }
    if (!empty($home_open)) {
        if (true == $home_open) {
            $args['meta_query'][] = array('key' => 'property_inspection_times', 'value' => '', 'compare' => '!=');
        }
    }
    // if user has specified location , use that
    if (!empty($location)) {
        if (!is_array($location)) {
            $location = explode(",", $location);
            $location = array_map('trim', $location);
            $args['tax_query'][] = array('taxonomy' => 'location', 'field' => 'slug', 'terms' => $location);
        }
    }
    // if user has not specified location fetch property's location
    if (!is_null($property)) {
        if (empty($location) && !is_archive() && !in_array($property->post_type, apply_filters('epl_am_skip_location_filter', array('epl_office')))) {
            $location = wp_get_object_terms($property->post->ID, 'location', array('fields' => 'slugs'));
            $args['tax_query'][] = array('taxonomy' => 'location', 'field' => 'slug', 'terms' => $location);
        }
    }
    $results = new Wp_Query($args);
    global $property, $epl_settings;
    $cluster = $cluster == 'true' || $cluster == 'on' ? 'true' : 'false';
    $infobox_class = isset($epl_settings['epl_am_infobox_style']) ? $epl_settings['epl_am_infobox_style'] : 'rounded';
    $return = '';
    $return .= "<div id='epl-advanced-map' class='epl-am-infobox-{$infobox_class}'>";
    $return .= '
				<input type="hidden" name="slider[zoom]" value="' . $zoom . '" />
				<input type="hidden" name="slider[height]" value="' . $height . '" />
				<input type="hidden" name="slider[cluster]" value="' . $cluster . '" />
				<input type="hidden" name="slider[display]" value="' . $display . '" />
			
				<div  class="slider-map"></div>
				<div  class="slider-map-zoom-in"></div>	
				<div  class="slider-map-zoom-out"></div>';
    if ($display == 'slider') {
        $return .= '
						<div class="slider-map-featured">
							<div class="slider-map-featured-left" ></div>
							<div  class="slider-map-featured-right"></div>
		
							<ul>';
        if ($results->have_posts()) {
            while ($results->have_posts()) {
                $results->the_post();
                if (has_post_thumbnail()) {
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
                    $epl_am_prop_image = $image[0];
                } else {
                    $epl_am_prop_image = EPL_AM_PLUGIN_URL_IMAGES . 'no-image.jpg';
                }
                $return .= '
										<li id="marker_featured_' . get_the_ID() . '" class="marker-featured-slide ">
											<img src="' . $epl_am_prop_image . '" alt="' . get_the_title() . '" title="' . get_the_title() . '" />
											<span class="slider-title">' . get_the_title() . '</span>
											<p>' . get_the_excerpt() . '</p>';
                if (!in_array(get_post_type(), apply_filters('epl_am_no_price', array('location_profile')))) {
                    $return .= '
														<div class="slider-price">
															<span class="page-price">';
                    $return .= '<span class="price_class">' . epl_get_property_price() . '</span>';
                    //$return .= '<span class="price_sticker">'.epl_get_price_sticker().'</span>';
                    $return .= '
															</span>
														</div>
													';
                }
                $return .= '
											<div class="property-info">';
                //$return .= '<div class="epl-adv-popup-meta">'.epl_get_property_icons().'</div>';
                $return .= '<a href="' . get_permalink() . '" title="' . get_the_title() . '" class="view">View Property</a>
											</div>
										</li>
									';
            }
        }
        wp_reset_postdata();
        $return .= '
							</ul>
						</div>
						<div class="clear"></div>
					';
    } else {
        if ($display == 'popup') {
            $return .= '
						<div class="bpopup" id="bpopup-epl-am">
							<span class="b-close"><span>X</span></span>
							<div class="bpopup-inner" id="bpopup-inner"><!-- Ajax Loaded Data --></div>
						</div>
					';
        } else {
        }
    }
    $return .= '
			</div>

			<script type="text/javascript">
				jQuery(document).ready(function() { ';
    if ($results->have_posts()) {
        $post_counter = 1;
        while ($results->have_posts()) {
            $results->the_post();
            $property_address_coordinates = $property->get_property_meta('property_address_coordinates');
            $property_address_coordinates = explode(',', $property_address_coordinates);
            $epl_am_lat = trim($property_address_coordinates[0]);
            $epl_am_long = trim($property_address_coordinates[1]);
            if ($post_counter == 1) {
                $center_lat = $epl_am_lat;
                $center_long = $epl_am_long;
            }
            if (has_post_thumbnail()) {
                $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
                $epl_am_prop_image = $image[0];
            } else {
                $epl_am_prop_image = EPL_AM_PLUGIN_URL_IMAGES . 'no-image.jpg';
            }
            $image_pin = epl_am_get_property_image($property);
            $content = epl_get_property_icons();
            $price_content = '';
            $price_content .= '
								<div class="slider-price">
									<span class="page-price">';
            $price_content .= '<span class="price_class">' . epl_get_property_price() . '</span>';
            //$price_content .= '<span class="price_sticker">'.epl_get_price_sticker().'</span>';
            $price_content .= '
									</span>
								</div>
							';
            $content = '<div class="property-info"><span class="property_address_suburb">' . epl_property_get_the_full_address() . '</span>' . $price_content . '<div class="epl-adv-popup-meta">' . $content . '</div></div>';
            $content = preg_replace('~[\\r\\n]+~', '', $content);
            $return .= '
								myGmap.addFeaturedMarker(\'' . get_the_ID() . '\', \'' . addslashes(epl_property_get_the_full_address()) . '\', \'' . $epl_am_lat . '\', \'' . $epl_am_long . '\', \'' . $image_pin . '\', \'' . get_permalink() . '\', \'' . $epl_am_prop_image . '\', \'' . addslashes(get_the_title()) . '\', \'' . addslashes($content) . '\');
							';
            $post_counter++;
        }
    }
    wp_reset_postdata();
    if ($coords != '') {
        $center_coordinates = explode(',', $coords);
        $center_lat = trim($center_coordinates[0]);
        $center_long = trim($center_coordinates[1]);
    } else {
        if (!is_null($property)) {
            $center_coordinates = $property->get_property_meta('property_address_coordinates');
            $center_coordinates = explode(',', $center_coordinates);
            $center_lat = trim($center_coordinates[0]);
            $center_long = trim($center_coordinates[1]);
        }
    }
    $return .= '
					set_markers( "' . EPL_AM_PLUGIN_URL_IMAGES . '" );
					var latlng = new google.maps.LatLng(' . trim($center_lat) . ', ' . trim($center_long) . ');
					myGmap.gmap3("get").setCenter(latlng);
					
				});
			</script>
		';
    return $return;
}