gpt4 book ai didi

javascript - Google map API v3 使叠加层显示在单独的 DOM 元素街景上

转载 作者:行者123 更新时间:2023-11-27 23:58:39 25 4
gpt4 key购买 nike

当街景(全景)显示在 map 元素以外的 DOM 元素中时,有什么方法可以使叠加层(标记)显示出来?

尝试了几个小时,但无法使其正常工作。

jsFiddle http://jsfiddle.net/o3a2rfgz/1/

enter image description here

var start_lat_long = {lat: 34.0330675, lng: -117.9679802};

function load_map() {

var map = new google.maps.Map(document.getElementById('map'), {
center: start_lat_long,
zoom: 17,

backgroundColor: "#b3d1ff",
disableDoubleClickZoom: 1,
keyboardShortcuts: 0,
disableDefaultUI: 1,
minZoom: 9
});

var marker1 = new google.maps.Marker({
position: start_lat_long,
map: map
});


//PANORAMA INTERNAL
panorama = map.getStreetView();
panorama.setPosition(start_lat_long);


//PANORAMA EXTERNAL
var sv = new google.maps.StreetViewService();
panorama_external = new google.maps.StreetViewPanorama(document.getElementById('pano'));
sv.getPanorama({location: start_lat_long, radius: 100}, processSVData);

}


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


//PANORAMA INTERNAL
function toggleStreetView() {
if (panorama.getVisible() == false) {
panorama.setVisible(true);
} else {
panorama.setVisible(false);
}
}


//PANORAMA EXTERNAL
function processSVData(data) {
panorama_external.setPano(data.location.pano);
panorama_external.setVisible(true);
}

最佳答案

您需要向第二个全景图中添加不同标记:

//PANORAMA EXTERNAL
function processSVData(data) {
panorama_external.setPano(data.location.pano);
panorama_external.setVisible(true);
var marker2 = new google.maps.Marker({
position: start_lat_long,
map: panorama_external
});
}

updated fiddle

代码片段:

var start_lat_long = {
lat: 34.0330675,
lng: -117.9679802
};

function load_map() {

var map = new google.maps.Map(document.getElementById('map'), {
center: start_lat_long,
zoom: 17,

backgroundColor: "#b3d1ff",
disableDoubleClickZoom: 1,
keyboardShortcuts: 0,
disableDefaultUI: 1,
minZoom: 9
});

var marker1 = new google.maps.Marker({
position: start_lat_long,
map: map
});


//PANORAMA INTERNAL
panorama = map.getStreetView();
panorama.setPosition(start_lat_long);


//PANORAMA EXTERNAL
var sv = new google.maps.StreetViewService();
panorama_external = new google.maps.StreetViewPanorama(document.getElementById('pano'));
sv.getPanorama({
location: start_lat_long,
radius: 100
}, processSVData);

}


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


//PANORAMA INTERNAL
function toggleStreetView() {
if (panorama.getVisible() == false) {
panorama.setVisible(true);
} else {
panorama.setVisible(false);
}
}


//PANORAMA EXTERNAL
function processSVData(data) {
panorama_external.setPano(data.location.pano);
panorama_external.setVisible(true);
var marker2 = new google.maps.Marker({
position: start_lat_long,
map: panorama_external
});
}
<script src="https://maps.googleapis.com/maps/api/js?signed_in=true"></script>
<input type="button" value="Toggle Street View" onclick="toggleStreetView();" style="background:#0a0; color:#fff" />
<br />

<div id="map" style="width: 48%; height: 300px; display: inline-block;"></div>

<div id="pano" style="width:48%; height: 300px; display: inline-block;"></div>

关于javascript - Google map API v3 使叠加层显示在单独的 DOM 元素街景上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033578/

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