|
<?php |
|
defined('C5_EXECUTE') or die("Access Denied."); |
|
class GoogleMapBlockController extends Concrete5_Controller_Block_GoogleMap |
|
{ |
|
public function on_page_view() { |
|
// Insert Google Map API Key here |
|
// ここに Google Map API Key を入れてください |
|
$apikey = 'XXXXXXXXXXX'; |
|
|
|
$balloonHtml = ''; |
|
if($this->balloonShow) { |
|
$balloonHtml = '<div style="overflow:hidden;white-space:nowrap;">'; |
|
if(strlen($this->balloonContent)) { |
|
$balloonHtml .= Loader::helper('content')->translateFrom($this->balloonContent); |
|
} |
|
if($this->balloonWithLinkToMaps) { |
|
$balloonHtml .= '<div style="font-size: smaller"><a href="//maps.google.com?' . h('ll=' . $this->latitude . ',' . $this->longitude . '&daddr=' . $this->latitude . ',' . $this->longitude . '&z=' . $this->zoom) . '" target="blank">' . h(t('Get Directions')) . '</a> </div>'; |
|
} |
|
$balloonHtml .= '</div>'; |
|
$this->set('balloonHtml', $balloonHtml); |
|
} |
|
$html = Loader::helper('html'); |
|
$c = Page::getCurrentPage(); |
|
if (!$c->isEditMode()) { |
|
$this->addFooterItem('<script type="text/javascript" src="//maps.google.com/maps/api/js?key=' . $apikey . '&sensor=true&language=' . rawurlencode(str_replace('_', '-', Localization::activeLocale())) . '"></script>'); |
|
$this->addFooterItem('<script type="text/javascript"> |
|
function googleMapInit' . $this->bID . '() { |
|
try{ |
|
var latlng = new google.maps.LatLng(' . $this->latitude . ', ' . $this->longitude . '), balloonHtml = ' . Loader::helper('json')->encode($balloonHtml) . ', balloon; |
|
var mapOptions = { |
|
zoom: ' . $this->zoom . ', |
|
center: latlng, |
|
mapTypeId: google.maps.MapTypeId.ROADMAP, |
|
streetViewControl: false, |
|
mapTypeControl: false |
|
}; |
|
var map = new google.maps.Map(document.getElementById(\'googleMapCanvas' . $this->bID . '\'), mapOptions); |
|
var marker = new google.maps.Marker({ |
|
position: latlng, |
|
map: map |
|
}); |
|
if(balloonHtml) { |
|
balloon = new google.maps.InfoWindow({content: balloonHtml}); |
|
google.maps.event.addListener(marker, "click", function() { |
|
balloon.open(map, marker); |
|
}); |
|
setTimeout(function() { |
|
balloon.open(map, marker); |
|
}, 500); |
|
} |
|
}catch(e){ |
|
$("#googleMapCanvas'. $this->bID .'").replaceWith("<p>Unable to display map: "+e.message+"</p>")} |
|
} |
|
$(function() { |
|
var t; |
|
var startWhenVisible = function (){ |
|
if ($("#googleMapCanvas'. $this->bID .'").is(":visible")){ |
|
window.clearInterval(t); |
|
googleMapInit' . $this->bID . '(); |
|
return true; |
|
} |
|
return false; |
|
}; |
|
if (!startWhenVisible()){ |
|
t = window.setInterval(function(){startWhenVisible();},100); |
|
} |
|
}); |
|
</script>'); |
|
} |
|
} |
|
} |