Created
April 9, 2013 17:45
-
-
Save jpdevries/5347775 to your computer and use it in GitHub Desktop.
Pow Pass Map JavaScript
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
| <script type="text/javascript"> | |
| function initialize() { | |
| $.address.state('/'); | |
| var _pins = []; | |
| $('#map-canvas li').each(function(){ | |
| var _title = $(this).find('h3').html(); | |
| var _lat = $(this).find('.lat').html(); | |
| var _lng = $(this).find('.lng').html(); | |
| _pins.push({title:_title,lat:_lat,lng:_lng,href:$(this).data('href'),ajax:$(this).data('ajax'),ridden:$(this).data('ridden'),id:$(this).data('id')}); | |
| }); | |
| var mapOptions = { | |
| center: new google.maps.LatLng(39.333315, -120.350784), | |
| zoom: 10, | |
| minZoom:5, | |
| mapTypeId: google.maps.MapTypeId.TERRAIN | |
| }; | |
| var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions); | |
| var _openWindow; | |
| var _showRidden = ($('body').data('highlight-ridden') == '1') ? true : false; | |
| var _markers = []; | |
| var _circles = []; | |
| var _clickedMarker; | |
| var l = _pins.length; | |
| for(var i = 0; i < l; i++) { | |
| var infowindow = new google.maps.InfoWindow({ | |
| content: '<div class="infowindow"><h1>' + _pins[i].title + '!!!</h1></div>' | |
| }); | |
| var marker = new google.maps.Marker({ | |
| position:new google.maps.LatLng(_pins[i].lat,_pins[i].lng), | |
| map: map, | |
| title: _pins[i].title, | |
| pid:i, | |
| href:_pins[i].href, | |
| ajax:_pins[i].ajax, | |
| zIndex:(_pins[i].ridden) ? 1000 + i : i, | |
| icon:'/assets/img/' + ((_showRidden && _pins[i].ridden) ? 'icon_snowboarding_ridden.png' : 'icon_snowboarding.png') | |
| }); | |
| if(marker.pid == 20) _clickedMarker = marker; | |
| _markers.push(marker); | |
| var populationOptions = { | |
| strokeColor: (_pins[i].ridden) ? "#f5f375" : "#f5f375", | |
| strokeOpacity: 0.6, | |
| strokeWeight: 2, | |
| fillColor: (_pins[i].ridden) ? "#f5f375" : "#f5f375", | |
| fillOpacity: 0.6, | |
| pid:i, | |
| center: new google.maps.LatLng(_pins[i].lat,_pins[i].lng), | |
| radius: 5600, | |
| map:(_pins[i].id == 20) ? map : null | |
| }; | |
| cityCircle = new google.maps.Circle(populationOptions); | |
| _circles.push(cityCircle); | |
| // process multiple info windows | |
| (function(marker, i, _clickedMarker) { | |
| // add click event | |
| google.maps.event.addListener(marker, 'click', function() { | |
| if(!'') { | |
| document.location = marker.href; | |
| return; | |
| } | |
| var k = _circles.length; | |
| for(var j = 0; j < k; j++) { | |
| _circles[j].setMap((_circles[j].pid == marker.pid) ? map : null); | |
| } | |
| $.ajax({ | |
| type:"GET", | |
| url:marker.ajax, | |
| success:function(data){ | |
| $('.map-side .content').empty().html(data); | |
| $.address.value(marker.href); | |
| $.address.title($('body').data('site-name') + ' - ' + marker.title); | |
| asideListeners(); | |
| if(window.innerWidth <= 768) { | |
| $("html, body").animate({ scrollTop: $('.map-side').offset().top }, 240); | |
| } | |
| } | |
| }); | |
| _clickedMarker = marker; | |
| }); | |
| })(marker, i); | |
| } | |
| // support jumping past map using sm URL param | |
| if(window.innerWidth <= 768 && $('body').data('skip-map')) $("html, body").animate({ scrollTop: $('.map-side').offset().top }, 240); | |
| function asideListeners(){ | |
| $('h1 span').click(function(e){ | |
| if(_clickedMarker) { | |
| map.setCenter(marker.getPosition()); | |
| map.setZoom(10); | |
| } | |
| }); | |
| } | |
| asideListeners(); | |
| } // end initialize | |
| $('document').ready(function(){ | |
| initialize(); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment