3
我有下面的內容,想按照cat: dataMarkers.cat
下拉的各種類別標記對標記進行排序。我有點失落,因爲如何以最好的方式實際做到這一點。我在爲每個類別考慮markerManager?我需要每個類別都在自己的markerManager數組中嗎?這與markerClusterer有什麼關係?按類別切換打開/關閉Google地圖標記
var map;
function initialize() {
var center = new google.maps.LatLng(39.632906,-106.524591);
var options = {
'zoom': 8,
'center': center,
'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
<!--Load Markers-->
var markers = [];
for (var i = 0, dataMarkers; dataMarkers = data.markers[i]; i++) {
var latLng = new google.maps.LatLng(dataMarkers.lat, dataMarkers.lng);
var marker = new google.maps.Marker({
position: latLng,
title: dataMarkers.title,
date: dataMarkers.date,
time: dataMarkers.time,
desc: dataMarkers.desc,
img: dataMarkers.img,
add: dataMarkers.address,
cat: dataMarkers.cat,
map: map
});
<!--Display InfoWindows-->
var infowindow = new google.maps.InfoWindow({
content: " "
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div id="mapCont"><img class="mapImg" src="'+this.img+'"/>' +
'<div class="mapTitle">'+this.title+'</div>' +
'<div class="mapHead">Date: <div class="mapInfo">'+this.date+'</div>' +
'<div class="mapHead">Time: <div class="mapInfo">'+this.time+'</div>' +
'<p>'+this.desc+'</p></div>');
infowindow.open(map, this);
});
markers.push(marker);
}
<!--Cluster Markers-->
var markerClusterer = new MarkerClusterer(map, markers, {
maxZoom: 15,
gridSize: 50
});
}
dataMarkers.cat在JSON數據中包含5個不同的類別。仍然不知道如何marker.category = THE_CATEGORY_IT_BELONGS_TO;區分類別。 – RonnieT 2011-04-30 14:36:07
每個標記可以有多個類別嗎?我寫的內容爲每個標記分配一個類別,然後您可以循環顯示您的標記數組,並只顯示具有當前所選類別的標記 – 2011-04-30 15:22:33
每個標記可以有多個類別。結束這樣做,但我最終只從一個類別排序.. marker.mycategory = category; marker.myname = name; gmarkers.push(marker);是否像投入更多marker.mycategories一樣簡單? – RonnieT 2011-05-01 15:02:49