How can I display a different icon for markers that fit wthin different categories?

后端 未结 1 1500
时光取名叫无心
时光取名叫无心 2021-01-20 09:01

I\'m attempting to make a Google Map which allows the user to check off a category and have those specific locations display. I\'ve got that part working:

http://the

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-20 09:50

    Make an object var iconSrc = {}

    Then, match categories to icon images to it.

    iconSrc['Dial-a-ride'] = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconSrc['American Legion'] = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
    ...
    

    when adding a marker, replace the icon image source with the new variable:

    icon: iconSrc[locations[i][2]]
    

    Here's a jsfiddle, the navigation is tough in the small pane so I moved the checkboxes to the top. http://jsfiddle.net/DA92S/1/

    0 讨论(0)
提交回复
热议问题