gpt4 book ai didi

javascript - Google Maps API v3 - 可点击文本以缩放至标记并打开信息窗口

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

我正在开展一个项目,该项目使用带有 127 个标记的 map 标记集群。我需要帮助的是在访问者单击标记列表中的文本链接时打开一个信息窗口。目前,单击文本会缩放到标记,但不会同时打开信息窗口。单击标记确实会打开信息窗口。我在代码中添加了注释以指出生成标记列表的位置。评论是//可点击标记的文本列表。

很遗憾,该网站正在开发中,无法公开显示。让我知道是否有任何其他信息可以帮助您帮助我。提前致谢。

var globalMarker = [];
var map;

function initialize() {
var center = new google.maps.LatLng(35.4214, -15.6919);
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 1,
center: center,
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
var infowindow = new google.maps.InfoWindow();
for (i = 0; i < 127; i++) {
var dataChapters = data.chapters[i];
var latLng = new google.maps.LatLng(dataChapters.latitude, dataChapters.longitude);
marker = new MarkerWithLabel({
position: latLng,
draggable: true,
raiseOnDrag: true,
map: map,
labelContent: "<strong>" + dataChapters.name + "<\/strong>" + "<br />" + dataChapters.description + "<br /><br />", // label for cluster view.
labelAnchor: new google.maps.Point(30, 0),
labelVisible: false,
labelClass: "labels", // the CSS class for the label
labelStyle: {
opacity: 0.75
}
});
markers.push(marker);
// text list of clickable markers
makeDiv(i, 15, dataChapters.rank + ")&nbsp;" + "<span class=\"chapterlink\">" + dataChapters.name + "<\/span>" + "<br />");
google.maps.event.addListener(markers[i], 'click', function (e) {
infowindow.setContent(this.labelContent); // label for pin.
infowindow.open(map, this);
});
}
var clusterOptions = {
zoomOnClick: true
};
var markerCluster = new MarkerClusterer(map, markers, clusterOptions);
globalMarker = markers.slice();
google.maps.event.addListener(markerCluster, 'clusterclick', function (cluster) {
var content = '';
// Convert lat/long from cluster object to a usable MVCObject
var info = new google.maps.MVCObject;
info.set('position', cluster.center_);
//----
//Get markers
var markers = cluster.getMarkers();
var titles = "";
//Get all the titles
for (var i = 0; i < markers.length; i++) {
titles += markers[i].labelContent + "\n";
}
//---
infowindow.close();
infowindow.setContent(titles); //set infowindow content to titles
infowindow.open(map, info);
google.maps.event.addListener(map, 'zoom_changed', function () {
infowindow.close();
});
});
}

function makeDiv(index, zoomLevel, content) {
document.getElementById("sidebar").innerHTML += '<div class="child" onclick="zoomIn(' + index + ',' + zoomLevel + ')">' + content + ' </div>';
}

function zoomIn(index, zoomLevel) {
map.setCenter(globalMarker[index].getPosition());
map.setZoom(zoomLevel);
}

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

最佳答案

尝试将此添加到 zoomIn() :

google.maps.event.trigger(globalMarker[index],'click');

关于javascript - Google Maps API v3 - 可点击文本以缩放至标记并打开信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18475217/

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