use google loader jsapi to load gmaps api later

This commit is contained in:
wlx 2011-11-08 06:13:09 +00:00
parent baf713eaed
commit b7f39f466f
1 changed files with 20 additions and 6 deletions

View File

@ -8,7 +8,7 @@
$this->breadcrumb('<a href="/data">'.$this->config->title->data.'</a>');
$this->breadcrumb('查看元数据');
$this->breadcrumb()->setSeparator(' > ');
$this->headScript()->appendFile('http://maps.google.cn/maps?file=api&v=2&key='.$this->config->google->maps->api);
//$this->headScript()->appendFile('https://maps.google.cn/maps?file=api&v=2&key='.$this->config->google->maps->api);
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/js/theme/default/style.css');
@ -224,7 +224,7 @@ endforeach;
<ul>
<?php foreach ($this->literature as $r) :
$u=parse_url($r->url);
if ($u['host']=='hdl.handle.net')
if (@$u['host']=='hdl.handle.net')
$url=$this->config->seekspace->handleurl.$u['path'];
else
$url=$r->url;
@ -281,7 +281,18 @@ echo '</li>';
</div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});});
$(window).bind("load", function() { var timeout = setTimeout(function() { initLoader(); }, 100);});
//$(window).bind("load", function() { var timeout = setTimeout(function() { gmaploaded(); }, 1000);});
function loadMaps() {
google.load("maps", "2", {"callback" : gmaploaded,"base_domain": "ditu.google.cn"});
}
function initLoader() {
var script = document.createElement("script");
script.src = "https://www.google.com/jsapi?key=<?php echo $this->config->google->maps->api; ?>&callback=loadMaps";
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
}
//ajax download
function todownload(ft)
{
@ -365,6 +376,8 @@ function getSubFileList(uuid,id,depth){
}
});
}
function gmaploaded()
{
//google map
var map = new GMap2(document.getElementById("watermap"));
var plotbounds=new GLatLngBounds(new GLatLng(<?= $md->south; ?>,<?= $md->west; ?>),new GLatLng(<?= $md->north; ?>,<?= $md->east; ?>));
@ -375,7 +388,7 @@ zoomlevel--;
<?php endif; ?>
if (zoomlevel>16) zoomlevel=16;
map.setCenter(new GLatLng(<?= ($md->south+$md->north)/2; ?>,<?= ($md->east+$md->west)/2; ?>), zoomlevel);
map.setMapType(G_SATELLITE_MAP);
map.setMapType(G_HYBRID_MAP);
map.setUIToDefault();
<?php if ($md->north==$md->south) : ?>
var marker=new GMarker(new GLatLng(<?= $md->north; ?>,<?= $md->east; ?>));
@ -390,6 +403,7 @@ zoomlevel--;
],"#f33f00",5,1,"#ff0000",0.2);
map.addOverlay(polygon);
<?php endif; ?>
}
</script>
<?php else: ?>
<p>Cannot find the metadata.</p>