gpt4 book ai didi

javascript - 让 Google Virtual Tour 嵌入自动旋转?

转载 作者:行者123 更新时间:2023-11-29 17:17:05 25 4
gpt4 key购买 nike

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"       src="https://maps.google.com/maps?hl=en&amp;sll=37.936424,-107.814144&amp;layer=c&amp;cid=12115290478932730695&amp;panoid=YY_tNFWmbOaOJDV_zlAZ0A&amp;cbp=13,40.7,,0,5.57&amp;gl=US&amp;t=m&amp;cbll=37.936374,-107.814213&amp;ie=UTF8&amp;hq=&amp;hnear=&amp;ll=37.935914,-107.813505&amp;spn=0.004595,0.010568&amp;source=embed&amp;output=svembed"></iframe><br /><small><a href="https://maps.google.com/maps?hl=en&amp;sll=37.936424,-107.814144&amp;layer=c&amp;cid=12115290478932730695&amp;panoid=YY_tNFWmbOaOJDV _zlAZ0A&amp;cbp=13,40.7,,0,5.57&amp;gl=US&amp;t=m&amp;cbll=37.936374,-107.814213&amp;ie=UTF8&amp;hq=&amp;hnear=&amp;ll=37.935914,-107.813505&amp;spn=0.004595,0.010568&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>

所以有嵌入代码。我想知道如何强制生成的内容自动旋转?我可以使用 JS 吗?

最佳答案

iframe访问组件

不,您将无法从 Javascript 访问 iframe 中的内容。

Javascript 安全策略不允许跨域访问嵌入式 (i) 框架的文档。

它被称为 Same Orgin Policy .

In computing, the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. The policy permits scripts running on pages originating from the same site – a combination of scheme, hostname, and port number[1] – to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.[1] Same origin policy also applies to XMLHttpRequest and to robots.txt.[2]


使用谷歌 API

解决方案是使用 Google API可以将您的应用程序与他们的服务(在本例中为街景 View )连接起来。

我认为您需要 panControl

A panControl provides a way to rotate the panorama. This control appears by default as a standard integrated compass and pan control. You may alter the control's position by providing PanControlOptions within the panControlOptions field.

(在 API 中搜索“街景控件”)

示例

即使这不是最好的解决方案,我也认为这会对您有所帮助。这将更新全景图的标题

<DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<title>Street View service</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var panorama;

function initialize() {
var fenway = new google.maps.LatLng(42.345573,-71.098326);
var panoramaOptions = {
position: fenway,
pov: {
heading: 4,
pitch: 10
}
};
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);

var i = 0;
window.setInterval(function () {
panorama.setPov({
heading: i,
pitch: 10,
zoom: 1
});
i += 0.1;
}, 10);
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas" style="width: 400px; height: 300px"></div>
<div id="pano" style="position:absolute; left:410px; top: 8px; width: 400px; height: 300px;"></div>
</body>
</html>

此外,如果您想停止旋转,请使用 on() 为 #pano 添加 mouseentermouseleave 的处理程序 jQuery 函数。

参见 JSFIDDLE

关于javascript - 让 Google Virtual Tour 嵌入自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16592832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com