Select Link or Checkbox to Display Category Markers

前端 未结 2 1656
旧巷少年郎
旧巷少年郎 2021-01-25 19:00

I am somewhat stuck at trying to tell Javascript to do what I want it to do.

I have an example map http://calwestcultural.com/sgs/backup/example-map.html and I have cate

2条回答
  •  猫巷女王i
    2021-01-25 19:45

    If you would like to keep markers in separate categories, create an array for each category of marker and use them to store each set of markers. Then do the following:

    To hide markers on load, create the markers but leave the marker map property set to null:

    var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var myOptions = {
        zoom: 4,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: null,
        title:"Hello World!"
    });
    

    To show only the markers in a given category, listen for the event that should trigger display of the markers and then set the markers' map property:

    for ( var i = 0; i < markerCategoryArray.length; i++ ) {
        markerCategoryArray[i].setMap( map );
    }
    

提交回复
热议问题