Created
December 1, 2010 21:06
-
-
Save gonz/724223 to your computer and use it in GitHub Desktop.
Filter/group google maps markers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Map #} | |
<script type="text/javascript"> | |
var map = new google.maps.Map(document.getElementById("map"), { | |
zoom: 6, | |
center: new google.maps.LatLng(-32.574592,-55.20605), | |
mapTypeControl: true, | |
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, | |
scrollwheel: false, | |
streetViewControl: false, | |
mapTypeId: google.maps.MapTypeId.TERRAIN | |
}); | |
{# Markers #} | |
var markers = {}; | |
{% for project in project_list %} | |
{% if project.latitude and project.longitude %} | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng({{ project.latitude }}, {{ project.longitude }}), | |
map: map, | |
title: "{{ project.title }}" | |
}); | |
{# Marker filter #} | |
category = '{{ project.category.slug }}' | |
if (typeof markers[category] == "undefined") { | |
markers[category] = [marker] | |
} else { | |
markers[category].push(marker) | |
} | |
{# Marker info window #} | |
{% url project_detail project.slug as url %} | |
var infowindow = new google.maps.InfoWindow({ | |
content: '<h2><a href="{{ url }}">{{ project.title }}</a></h2><p>{{ project.short_description }}</p><p>{{ project.location }}</p><p><a href="{{ url }}">{% trans "View details" %} »</a></p>', | |
}); | |
google.maps.event.addListener(marker, 'click', function() { | |
infowindow.open(map, marker); | |
}); | |
{% endif %} | |
{% endfor %} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment