[英]Filtering Markers Google Maps API V3
在以下方面,我需要您的幫助:
目前,我在Google地圖電子表格中有一組數據。 我需要過濾這些數據。 例如類別和類型。
這些是使用JSON收集的:
/**
* Called when JSON is loaded. Creates sidebar if param_sideBar is true.
* Sorts rows if param_rankColumn is valid column. Iterates through worksheet rows,
* creating marker and sidebar entries for each row.
* @param {JSON} json Worksheet feed
*/
function cm_loadMapJSON(json) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
if(entry["gsx$" + param_latColumn]) {
var lat = parseFloat(entry["gsx$" + param_latColumn].$t);
var lng = parseFloat(entry["gsx$" + param_lngColumn].$t);
var point = new google.maps.LatLng(lat,lng);
var html = "<div class='infoscherm' style='font-size:12px'>";
html += "<h2>" + entry["gsx$"+param_titleColumn].$t
+ "</h2>";
var label = entry["gsx$"+param_titleColumn].$t;
if(entry["gsx$" + param_screenCategory]) {
html += "<h3>" + "Screen Category/Purpose: " + "</h3>" + "<p>" + entry["gsx$"+param_screenCategory].$t + "</p>";
}
var screentype = entry["gsx$"+param_screenType].$t;
if(entry["gsx$" + param_screenType]) {
html += "<h3>" + "Screen Type: " + "</h3>" + "<p>" + entry["gsx$"+param_screenType].$t + "</p>";
}
if(entry["gsx$" + param_publicSpace]) {
html += "<h3>" + "Type of Public Space: " + "</h3>" + "<p>" + entry["gsx$"+param_publicSpace].$t + "</p>";
}
var space = entry["gsx$"+param_publicSpace].$t;
if(entry["gsx$" + param_screenInteraction]) {
html += "<h3>" + "Type of interaction: " + "</h3>" + "<p>" + entry["gsx$"+param_screenInteraction].$t + "</p>";
}
if(entry["gsx$" + param_descriptionColumn]) {
html += "<h3>" + "Description: " + "</h3>" + "<p>" + entry["gsx$"+param_descriptionColumn].$t + "</p>";
}
if(entry["gsx$" + param_screenAddress]) {
html += "<h3>" + "Screen Location: " + "</h3>" + "<p>" + entry["gsx$"+param_screenAddress].$t + "</p>";
}
html += "</div>";
// create the marker
var marker = cm_createMarker(kaart,point,label,html,screentype,space);
// cm_map.addOverlay(marker);
cm_mapMarkers.push(marker);
cm_mapHTMLS.push(html);
bounds.extend(point);
}
}
kaart.fitBounds(bounds);
kaart.setCenter(bounds.getCenter());
}
現在,我希望能夠過濾位於數組中的標記。 因此,僅顯示適合過濾器的標記。
此功能從地圖上刪除所有標記。 我當時正在考慮修改此功能,以便為標記創建一個有效的動態過濾器。 但我無法弄清楚。 有幫助嗎? 或想法甚至其他更好的工作方式?
function clearOverlays() {
if (cm_mapMarkers) {
for (i in cm_mapMarkers) {
cm_mapMarkers[i].setMap(null);
}
}
}
提前感謝
您需要並行數組或鍵值數組,例如:
cm_mapMarkers.push({ point: marker, category: 'something' });
接着
function showSome(categoryName) {
if (cm_mapMarkers) {
for (var i = 0, marker; marker = cm_mapMarkers[++i]; ) {
if(marker.category == categoryName){
// do something with this marker
}else{
// do or do not with others.
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.