【发布时间】:2015-09-18 08:35:12
【问题描述】:
我正在尝试触发对标记的点击,但在将数据传递到 google.maps.event.trigger() 时遇到问题。我从 map.data 获取一个功能并将其传递给 google.maps.event.trigger(),但信息窗口未打开。
google.maps.event.trigger(map.data, 'click') 有效,但这并不针对特定标记。
任何建议或解决方案都会有所帮助。
谢谢
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(-16.166667, 33.60000000000002),
zoom: 4,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(mapCanvas, mapOptions)
map.data.loadGeoJson('locations.geojson');
function setProps(){
map.data.setStyle(function(feature) {
var color = false;
if (feature.getProperty('propVisible')) {
color = feature.getProperty('propVisible');
}
return {
icon: feature.getProperty('icon').iconUrl,
category: feature.getProperty('projectCat'),
visible: color,
};
});
}
setProps();
var infoWindow = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0, -50)});
map.data.addListener('click', function(event) {
console.log(event);
map.setCenter(event.latLng);
map.setZoom(15);
var projectTitle = event.feature.getProperty("projectTitle");
var imgStr = event.feature.getProperty("projectImages");
var projectImages = new Array();
projectImages = imgStr.split(',');
var projectCat = event.feature.getProperty("projectCat");
var projectPhase = event.feature.getProperty("projectPhase");
var projectSDate = event.feature.getProperty("projectSDate");
var projectEDate = event.feature.getProperty("projectEDate");
var projectDeveloper = event.feature.getProperty("projectDeveloper");
var projectInvestor = event.feature.getProperty("projectInvestor");
var projectTeam = event.feature.getProperty("projectTeam");
var projectTenants = event.feature.getProperty("projectTenants");
var projectWebsite = event.feature.getProperty("projectWebsite");
var thePopup = '<div class="leaflet-popup-content-wrapper">';
thePopup += '<h5>'+projectTitle+'</h5>';
for (i = 0; i < projectImages.length; i++) {
thePopup += '<img src="' + projectImages[i] + '" alt="" style="width:100px;height:100px;cursor:pointer;" data-lity />';
}
thePopup += '<div>Project Category: '+projectCat+'</div>';
thePopup += '<div>Project Phase: ' + projectPhase + '</div>';
thePopup += '<div>Start Date: ' + projectSDate + '</div>';
thePopup += '<div>End Date: ' + projectEDate + '</div>';
thePopup += '<div>Project Developer: ' + projectDeveloper + '</div>';
thePopup += '<div>Project Investor: ' + projectInvestor + '</div>';
thePopup += '<div>Professional Team: ' + projectTeam + '</div>';
thePopup += '<div>Key Tenants: ' + projectTenants + '</div>';
thePopup += '<div>Website: <a href="' + projectWebsite + '" target="_blank">Click Here</a></div>';
thePopup += '</div>';
//console.log(event);
infoWindow.setContent(thePopup);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
});
var listings = document.getElementById('film_roll');
setTimeout(function() {
map.data.forEach(function (feature) {
var projectTitle = feature.getProperty('projectTitle');
var listIcon = feature.getProperty('listIcon');
var projectCountry = feature.getProperty('projectCountry');
var listing = listings.appendChild(document.createElement('div'));
listing.className = 'item col-xs-2';
var notifImg = listing.appendChild(document.createElement('div'));
var notifMeta = listing.appendChild(document.createElement('div'));
var notifIcon = notifImg.appendChild(document.createElement('img'));
var link = notifMeta.appendChild(document.createElement('a'));
var Noticountry = notifMeta.appendChild(document.createElement('div'));
link.href = '#';
link.className = 'title';
notifImg.className = 'notification-img';
notifMeta.className = 'notification-meta';
notifIcon.src = notifImg.innHTML = listIcon;
link.innerHTML = projectTitle;
Noticountry.innerHTML = projectCountry;
});
fr = new FilmRoll({ container: '#film_roll', pager: false, next: false, prev: false, hover: false, start_height: '40px', configure_load: true, vertical_center: true });
}, 500);
filterMarkers = function (category) {
map.setZoom(4);
infoWindow.close();
map.data.forEach(function (feature) {
if (feature.getProperty('projectCat') == category || category == 'all') {
feature.setProperty('propVisible', true);
}
else {
feature.setProperty('propVisible', false);
}
});
setProps();
}
showPopupbox = function (link) {
var popupID = link.getAttribute("data-id");
var ourMarker = map.data.getFeatureById(popupID);
//console.log(map.data);
google.maps.event.trigger(ourMarker,'click');
}
}
google.maps.event.addDomListener(window, 'load', initialize);
<a id="map-link" data-id="35" onclick="showPopupbox(this);">test</a>
【问题讨论】:
标签: javascript jquery google-maps google-maps-api-3