我已經設置了122個標記,多個類別(12)的Google地圖。我可以根據每個標記使用的圖像創建一個過濾器,以打開/關閉表單中的標記嗎? 將另一個變量定義爲「類別」變量會更好嗎? 如果我使用JQuery,如何重構代碼才能使其工作?谷歌地圖多標記簡單過濾
任何想法,將不勝感激。
JScript中看起來是這樣的:
function initialize() {
var myOptions = {
center: new google.maps.LatLng(,),
zoom: 12,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
var image = []; //define an array to store category images
image['church']='icons/chapel-2.png'
image['monastery']='icons/convent-2.png'
image['archaeo']='icons/monument.png'
image['wild']='icons/wildlife.png'
image['museum']='icons/museum_openair.png'
image['beach']='icons/beach.png'
image['must']='icons/star.png'
image['summit']='icons/peak.png'
image['cave']='icons/cave-2.png'
image['forest']='icons/palmTree.png'
image['gorge']='icons/canyon-2.png'
image['village']='icons/smallcity.png'
//define 122 markers as below until var marker122 (no comments here I am trying to keep it simple..
var marker = new google.maps.Marker({
position: new google.maps.LatLng(,),
map: map,
title: 'placeName',
clickable: true,
icon: image['must']
});
HTML看起來像這樣:
<form action="#">
Must Visit: <input type="checkbox" id="mustbox" onclick="boxclick(this,'must')" />
Beaches: <input type="checkbox" id="beachbox" onclick="boxclick(this,'beach')" />
Archaeology: <input type="checkbox" id="archaeobox" onclick="boxclick(this,'archaeo')" />
Church: <input type="checkbox" id="religionnbox" onclick="boxclick(this,'church')" />
Monastery: <input type="checkbox" id="conventbox" onclick="boxclick(this,'convent')" />
Gorge: <input type="checkbox" id="gorgebox" onclick="boxclick(this,'gorge')" />
Cave: <input type="checkbox" id="cavetbox" onclick="boxclick(this,'cave')" />
Forest: <input type="checkbox" id="forestbox" onclick="boxclick(this,'forest')" />
Wildlife: <input type="checkbox" id="wildbox" onclick="boxclick(this,'wild')" />
Museum: <input type="checkbox" id="museumbox" onclick="boxclick(this,'museum')" />
Villages: <input type="checkbox" id="villagebox" onclick="boxclick(this,'village')" /><br />
Mountain Summit: <input type="checkbox" id="summitbox" onclick="boxclick(this,'summit')" /><br />
此外,我剛剛找到了一個簡單的搜索示例,完成了jsfiddle示例:http://stackoverflow.com/questions/11682069/how-to-show-hide-google-maps-markers-by-group- and-trigger-the-event-from-un-ht – dKen
@dKen是我的良好狀態嗎? 因爲我已經將標記存儲在分類數組中,所以我不應該在我的表單中寫入:onclick =「boxclick(this,'ArrayName')」?? – giannis
你可以添加你擁有的一切JSFiddle,我會看看嗎?將它放在JSFiddle中意味着我不必查看與該問題無關的代碼,但也可以幫助您在構建問題的同時解決問題。 – dKen