var map; function initMap() { // https://developers.google.com/maps/documentation/javascript/examples/ var mapOptions = { zoom: 14, center: new google.maps.LatLng(-34.397, 150.644), scrollwheel: false, streetViewControl: true, disableDefaultUI: true }; map = new google.maps.Map(document.getElementById('google-map'), mapOptions); <?php echo tt_mapMarkers(); ?> // https://developers.google.com/maps/documentation/javascript/geocoding var address = '<?php echo $address; ?> '; geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map,
function tt_google_maps_api_multiple_properties() { // Check For Property Search Template if (is_page_template('template-property-search.php')) { // Build Property Search Query $query_properties_args = array(); $query_properties_args = apply_filters('property_search_args', $query_properties_args); $query_properties_args['posts_per_page'] = -1; } else { global $post, $realty_theme_option; $properties_homepage_quantity = intval($realty_theme_option['map-properties-quantity']); // Property Map Settings $property_map_location = get_post_meta($post->ID, 'estate_property_map_location', false); $property_map_status = get_post_meta($post->ID, 'estate_property_map_status', false); $property_map_type = get_post_meta($post->ID, 'estate_property_map_type', false); $property_map_custom_zoom_level = get_post_meta($post->ID, 'estate_property_map_custom_zoom_level', true); if (!$properties_homepage_quantity) { $properties_homepage_quantity = -1; } // Property Query if (is_front_page()) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $query_properties_args = array('post_type' => 'property', 'posts_per_page' => $properties_homepage_quantity, 'paged' => $paged); $tax_query = array(); if ($property_map_location) { $tax_query[] = array('taxonomy' => 'property-location', 'field' => 'id', 'terms' => $property_map_location); } if ($property_map_status) { $tax_query[] = array('taxonomy' => 'property-status', 'field' => 'id', 'terms' => $property_map_status); } if ($property_map_type) { $tax_query[] = array('taxonomy' => 'property-type', 'field' => 'id', 'terms' => $property_map_type); } // Count Taxonomy Queries + set their relation for property query $tax_count = count($tax_query); if ($tax_count > 1) { $tax_query['relation'] = 'AND'; } if ($tax_count > 0) { $query_properties_args['tax_query'] = $tax_query; } } $query_properties = new WP_Query($query_properties_args); //if ( $query_properties->have_posts() ) : $property_string = ''; $i = 0; while ($query_properties->have_posts()) { $query_properties->the_post(); global $post; $google_maps = get_post_meta($post->ID, 'estate_property_location', true); // Check For Map Coordinates if ($google_maps) { $coordinate = explode(',', $google_maps); $property_string .= '{ '; $property_string .= 'permalink:"' . urlencode(get_permalink()) . '", '; $property_string .= 'title:"' . get_the_title() . '", '; $property_string .= 'price:"' . tt_property_price() . '", '; $property_string .= 'latLng: new google.maps.LatLng(' . $coordinate[0] . ', ' . $coordinate[1] . '), '; if (has_post_thumbnail()) { $property_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); $property_string .= 'thumbnail: "' . $property_thumbnail[0] . '"'; } else { $property_string .= 'thumbnail: "//placehold.it/300x100/eee/ccc/&text=.."'; } $property_string .= ' },' . "\n"; } $i++; } ?> <script> <?php // No Properties Found - Hide Map if ($i == 0) { ?> jQuery('#map-wrapper').hide(); <?php } ?> var map = null, markers = [], newMarkers = [], markerCluster = null, bounds = [], infobox = []; <?php echo tt_mapMarkers(); ?> var mapOptions = { center: new google.maps.LatLng(0, 0), zoom: 14, scrollwheel: false, streetViewControl: true, disableDefaultUI: true, }; function initMap() { map = new google.maps.Map(document.getElementById("google-map"), mapOptions); bounds = new google.maps.LatLngBounds(); markers = initMarkers(map, [ <?php echo $property_string; ?> ]); markerCluster = new MarkerClusterer(map, newMarkers, markerClusterOptions); // Maps Fully Loaded: Hide + Remove Spinner google.maps.event.addListenerOnce(map, 'idle', function() { jQuery('.spinner').fadeTo(800, 0.5); setTimeout(function() { jQuery('.spinner').remove(); }, 800); }); // Spiderfier var oms = new OverlappingMarkerSpiderfier(map, { markersWontMove: true, markersWontHide: true, keepSpiderfied: true, legWeight: 5 }); function omsMarkers( markers ) { for ( var i = 0; i < markers.length; i++ ) { oms.addMarker( markers[i] ); } } omsMarkers(markers); } google.maps.event.addDomListener(window, 'load', initMap); //google.maps.event.addDomListener(window, 'resize', initMap); function initMarkers(map, markerData) { for( var i = 0; i < markerData.length; i++ ) { marker = new google.maps.Marker({ map: map, position: markerData[i].latLng, icon: customIcon, //animation: google.maps.Animation.DROP }), bounds.extend(markerData[i].latLng); infoboxOptions = { content: '<div class="map-marker-wrapper">'+ '<div class="map-marker-container">'+ '<div class="arrow-down"></div>'+ '<img src="'+markerData[i].thumbnail+'" />'+ '<div class="content">'+ '<a href="'+markerData[i].permalink+'">'+ '<h5 class="title">'+markerData[i].title+'</h5>'+ '</a>'+ markerData[i].price+ '</div>'+ '</div>'+ '</div>', disableAutoPan: false, pixelOffset: new google.maps.Size(-33, -90), zIndex: null, isHidden: true, alignBottom: true, closeBoxURL: "<?php echo TT_LIB_URI . '/images/close.png'; ?> ", infoBoxClearance: new google.maps.Size(25, 25) }; newMarkers.push(marker); newMarkers[i].infobox = new InfoBox(infoboxOptions); newMarkers[i].infobox.open(map, marker); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { if ( newMarkers[i].infobox.getVisible() ) { newMarkers[i].infobox.setVisible(false); } else { jQuery('.infoBox').hide(); newMarkers[i].infobox.setVisible(true); } newMarkers[i].infobox.open(map, this); map.panTo(markerData[i].latLng); } })( marker, i ) ); google.maps.event.addListener(map, 'click', function() { jQuery('.infoBox').hide(); }); } // Set Map Bounds And Max. Zoom Level google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) { map.fitBounds(bounds); <?php if (isset($property_map_custom_zoom_level) && !empty($property_map_custom_zoom_level)) { ?> this.setZoom(<?php echo $property_map_custom_zoom_level; ?> ); <?php } else { ?> if (this.getZoom() > 13) { this.setZoom(13); } <?php } ?> }); return newMarkers; } // initMarkers(); </script> <?php }
function tt_map($atts, $content = null) { extract(shortcode_atts(array('address' => '', 'zoomlevel' => '14', 'height' => '500px', 'width' => '100%'), $atts)); ob_start(); // Property Query if (is_front_page()) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $query_properties_args = array('post_type' => 'property', 'posts_per_page' => -1, 'paged' => $paged); $query_properties = new WP_Query($query_properties_args); if ($query_properties->have_posts()) { $property_string = ''; $random = rand(); while ($query_properties->have_posts()) { $query_properties->the_post(); global $post; $google_maps = get_post_meta($post->ID, 'estate_property_location', true); $coordinate = explode(',', $google_maps); // Check If We Have LatLng Coordinates From Google Maps if ($google_maps) { $property_string .= '{ '; $property_string .= 'permalink:"' . get_the_permalink() . '", '; $property_string .= 'title:"' . get_the_title() . '", '; $property_string .= 'price:"' . tt_property_price() . '", '; $property_string .= 'latLng: new google.maps.LatLng(' . $coordinate[0] . ', ' . $coordinate[1] . '), '; if (has_post_thumbnail()) { $property_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); $property_string .= 'thumbnail: "' . $property_thumbnail[0] . '"'; } else { $property_string .= 'thumbnail: "//placehold.it/300x100/eee/ccc/&text=.."'; } $property_string .= ' },' . "\n"; } } ?> <script> var map = null, markers = [], newMarkers_<?php echo $random; ?> = [], markerCluster = null, infobox = []; function initMap() { <?php echo tt_mapMarkers(); ?> var mapOptions = { center: new google.maps.LatLng(0, 0), zoom: <?php echo $zoomlevel; ?> , scrollwheel: false, streetViewControl: true, disableDefaultUI: true }; map = new google.maps.Map(document.getElementById("google-map-<?php echo $random; ?> "), mapOptions); markers = initMarkers(map, [ <?php echo $property_string; ?> ]); function initMarkers(map, markerData) { for( var i = 0; i < markerData.length; i++ ) { marker = new google.maps.Marker({ map: map, position: markerData[i].latLng, icon: customIcon, animation: google.maps.Animation.DROP }), infoboxOptions = { content: '<div class="map-marker-wrapper">'+ '<div class="map-marker-container">'+ '<div class="arrow-down"></div>'+ '<img src="'+markerData[i].thumbnail+'" />'+ '<div class="content">'+ '<a href="'+markerData[i].permalink+'">'+ '<h5 class="title">'+markerData[i].title+'</h5>'+ '</a>'+ markerData[i].price+ '</div>'+ '</div>'+ '</div>', disableAutoPan: false, pixelOffset: new google.maps.Size(-33, -90), zIndex: null, isHidden: true, alignBottom: true, closeBoxURL: "<?php echo TT_LIB_URI . '/images/close.png'; ?> ", infoBoxClearance: new google.maps.Size(25, 25) }; newMarkers_<?php echo $random; ?> .push(marker); newMarkers_<?php echo $random; ?> [i].infobox = new InfoBox(infoboxOptions); newMarkers_<?php echo $random; ?> [i].infobox.open(map, marker); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { if ( newMarkers_<?php echo $random; ?> [i].infobox.getVisible() ) { newMarkers_<?php echo $random; ?> [i].infobox.hide(); } else { jQuery('.infoBox').hide(); newMarkers_<?php echo $random; ?> [i].infobox.show(); } newMarkers_<?php echo $random; ?> [i].infobox.open(map, this); map.panTo(markerData[i].latLng); } })( marker, i ) ); google.maps.event.addListener(map, 'click', function() { jQuery('.infoBox').hide(); }); } var markerCluster_<?php echo $random; ?> = new MarkerClusterer(map, newMarkers_<?php echo $random; ?> , markerClusterOptions); return newMarkers_<?php echo $random; ?> ; } // Spiderfier var oms = new OverlappingMarkerSpiderfier(map, { markersWontMove: true, markersWontHide: true, keepSpiderfied: true, legWeight: 5 }); function omsMarkers( markers ) { for ( var i = 0; i < markers.length; i++ ) { oms.addMarker( markers[i] ); } } omsMarkers(markers); <?php if ($address) { ?> var address = '<?php echo $address; ?> '; // Get latLng from property address and grab it with callback, as geocode calls asynchonous function getLatLng(callback) { var geocoder = new google.maps.Geocoder(); if ( geocoder ) { geocoder.geocode( { 'address': address}, function(results, status ) { if (status == google.maps.GeocoderStatus.OK) { latLng = results[0].geometry.location; callback(latLng); } else { alert("Geocoder failed due to: " + status); } }); } } getLatLng(function(latLng) { map.setCenter(latLng); }); <?php } ?> } google.maps.event.addDomListener(window, 'load', initMap); google.maps.event.addDomListener(window, 'resize', initMap); </script> <div id="map-wrapper"> <div id="map-controls"> <a href="#" class="control" id="zoom-in" data-toggle="tooltip" title="<?php _e('Zoom In', 'tt'); ?> "><i class="fa fa-plus"></i></a> <a href="#" class="control" id="zoom-out" data-toggle="tooltip" title="<?php _e('Zoom Out', 'tt'); ?> "><i class="fa fa-minus"></i></a> <a href="#" class="control" id="map-type" data-toggle="tooltip" title="<?php _e('Map Type', 'tt'); ?> "> <i class="fa fa-image"></i> <ul class="list-unstyled"> <li id="map-type-roadmap"><?php _e('Roadmap', 'tt'); ?> </li> <li id="map-type-satellite"><?php _e('Satellite', 'tt'); ?> </li> <li id="map-type-hybrid"><?php _e('Hybrid', 'tt'); ?> </li> <li id="map-type-terrain"><?php _e('Terrain', 'tt'); ?> </li> </ul> </a> <a href="#" class="control" id="current-location" data-toggle="tooltip" title="<?php _e('Radius: 1000m', 'tt'); ?> "><i class="fa fa-crosshairs"></i><?php _e('Current Location', 'tt'); ?> </a> </div> <div id="google-map-<?php echo $random; ?> " style="height: <?php echo $height; ?> "> <div class="spinner"> <div class="bounce1"></div> <div class="bounce2"></div> <div class="bounce3"></div> </div> </div> </div> <?php wp_reset_query(); } else { ?> <div id="map-no-properties-found"> <p class="lead text-center"><?php _e('No Properties Found.', 'tt'); ?> </p> </div> <?php } return ob_get_clean(); }
function tt_google_maps_api_single_property() { global $post, $realty_theme_option; $property_id = $post->ID; // Check For Property Submit Page Template if (is_page_template('template-property-submit.php') && isset($_GET['edit']) && !empty($_GET['edit'])) { $property_id = $_GET['edit']; } $address = get_post_meta($property_id, 'estate_property_address', true); $google_maps = get_post_meta($property_id, 'estate_property_location', true); $coordinate = explode(',', $google_maps); if (has_post_thumbnail($property_id)) { $property_thumbnail = get_the_post_thumbnail($property_id, 'medium'); } else { $property_thumbnail = '<img src="//placehold.it/300x150/eee/ccc/&text=.." />'; } if (empty($realty_theme_option['property-submit-default-address-latitude'])) { $latitude = '51.5286416'; } else { $latitude = $realty_theme_option['property-submit-default-address-latitude']; } if (empty($realty_theme_option['property-submit-default-address-longitude'])) { $longitude = '-0.1015987'; } else { $longitude = $realty_theme_option['property-submit-default-address-longitude']; } ?> <script> var map, marker; function initMap() { var mapOptions = { center: new google.maps.LatLng( <?php echo $latitude . ',' . $longitude; ?> ), zoom: 12, scrollwheel: false, streetViewControl: true, disableDefaultUI: true }; map = new google.maps.Map(document.getElementById('google-map'), mapOptions); <?php echo tt_mapMarkers(); ?> var marker = new google.maps.Marker({ map: map, position: new google.maps.LatLng( <?php echo $latitude . ',' . $longitude; ?> ), icon: customIcon, title: '<?php the_title(); ?> ', <?php if (is_page_template('template-property-submit.php')) { ?> draggable: true <?php } ?> }); var propertyThumbnail = '<?php echo $property_thumbnail; ?> '; var propertyPrice = '<?php echo tt_property_price(); ?> '; var propertyTitle = '<?php echo '<h5 class="title">' . get_the_title($property_id) . '</h5>'; ?> '; // http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html var infobox = new InfoBox({ content: '<div class="map-marker-wrapper">'+ '<div class="map-marker-container">'+ '<div class="arrow-down"></div>'+ propertyThumbnail+ '<div class="content">'+ propertyTitle+ propertyPrice+ '</div>'+ '</div>'+ '</div>', disableAutoPan: false, pixelOffset: new google.maps.Size(-33, -90), zIndex: null, alignBottom: true, closeBoxURL: "<?php echo TT_LIB_URI . '/images/close.png'; ?> ", infoBoxClearance: new google.maps.Size(50, 50) }); <?php // Check If We Have LatLng Coordinates From Google Maps if ($google_maps) { ?> //alert("got latlng"); function getLatLng(callback) { latLng = new google.maps.LatLng(<?php echo $coordinate[0]; ?> , <?php echo $coordinate[1]; ?> ); callback(latLng); } <?php } else { ?> //alert("no latlng"); <?php if (is_page_template('template-property-submit.php')) { ?> var address = jQuery('input#property-address').value; <?php } else { ?> var address = '<?php echo $address; ?> '; <?php } ?> // Get latLng from property address and grab it with callback, as geocode calls asynchonous function getLatLng(callback) { var geocoder = new google.maps.Geocoder(); if ( geocoder ) { geocoder.geocode( { 'address': address}, function(results, status ) { if (status == google.maps.GeocoderStatus.OK) { latLng = results[0].geometry.location; callback(latLng); } <?php if (!is_page_template('template-property-submit.php')) { ?> else { //alert("Geocoder failed due to: " + status); } <?php } ?> }); } } <?php } ?> getLatLng(function(latLng) { marker.setPosition(latLng); map.setCenter(latLng); <?php global $realty_theme_option; if ($realty_theme_option['map-default-zoom-level']) { echo 'map.setZoom(' . $realty_theme_option['map-default-zoom-level'] . ');'; } else { echo 'map.setZoom(14);'; } ?> google.maps.event.addListener(marker, 'click', function() { infobox.open(map, marker); map.panTo(latLng); }); }); // Maps Fully Loaded: Hide + Remove Spinner google.maps.event.addListenerOnce(map, 'idle', function() { jQuery('.spinner').fadeTo(800, 0.5); setTimeout(function() { jQuery('.spinner').remove(); }, 800); }); <?php // User Property Submit if (is_page_template('template-property-submit.php')) { ?> // https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete var autocompleteInput = document.getElementById('property-address'); var autocomplete = new google.maps.places.Autocomplete(autocompleteInput); // Autocomplete google.maps.event.addListener(autocomplete, 'place_changed', function() { infobox.close(); marker.setVisible(false); var place = autocomplete.getPlace(); if (!place.geometry) { return; } // If the place has a geometry, then present it on a map. if (place.geometry.viewport) { map.fitBounds(place.geometry.viewport); } else { map.setCenter(place.geometry.location); map.setZoom(17); // Why 17? Because it looks good. } marker.setPosition(place.geometry.location); marker.setVisible(true); // Update Property Coordinates var newCoordinates = String( place.geometry.location ); newCoordinates = newCoordinates.substring( 1, newCoordinates.length-1 ); //alert( newCoordinates ); jQuery('#property-coordinates').val(newCoordinates); }); // After Marker Has Been Dragged To Exact Location google.maps.event.addListener(marker, 'dragend', function() { var newCoordinatesAfterDragging = String( marker.getPosition() ); newCoordinatesAfterDragging = newCoordinatesAfterDragging.substring( 1, newCoordinatesAfterDragging.length-1 ); //alert( newCoordinatesAfterDragging ); jQuery('#property-coordinates').val(newCoordinatesAfterDragging); }); <?php } ?> } google.maps.event.addDomListener(window, 'load', initMap); google.maps.event.addDomListener(window, 'resize', initMap); </script> <?php }