Blame view
examples/speed_test.js
4.03 KB
dbaadcdd8 Signed-off-by: To... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
/** * @fileoverview This demo is used for MarkerClusterer. It will show 100 markers * using MarkerClusterer and count the time to show the difference between using * MarkerClusterer and without MarkerClusterer. * @author Luke Mahe (v2 author: Xiaoxi Wu) */ function $(element) { return document.getElementById(element); } var speedTest = {}; speedTest.pics = null; speedTest.map = null; speedTest.markerClusterer = null; speedTest.markers = []; speedTest.infoWindow = null; speedTest.init = function() { var latlng = new google.maps.LatLng(39.91, 116.38); var options = { 'zoom': 2, 'center': latlng, 'mapTypeId': google.maps.MapTypeId.ROADMAP }; speedTest.map = new google.maps.Map($('map'), options); speedTest.pics = data.photos; var useGmm = document.getElementById('usegmm'); google.maps.event.addDomListener(useGmm, 'click', speedTest.change); var numMarkers = document.getElementById('nummarkers'); google.maps.event.addDomListener(numMarkers, 'change', speedTest.change); speedTest.infoWindow = new google.maps.InfoWindow(); speedTest.showMarkers(); }; speedTest.showMarkers = function() { speedTest.markers = []; var type = 1; if ($('usegmm').checked) { type = 0; } if (speedTest.markerClusterer) { speedTest.markerClusterer.clearMarkers(); } var panel = $('markerlist'); panel.innerHTML = ''; var numMarkers = $('nummarkers').value; for (var i = 0; i < numMarkers; i++) { var titleText = speedTest.pics[i].photo_title; if (titleText === '') { titleText = 'No title'; } var item = document.createElement('DIV'); var title = document.createElement('A'); title.href = '#'; title.className = 'title'; title.innerHTML = titleText; item.appendChild(title); panel.appendChild(item); var latLng = new google.maps.LatLng(speedTest.pics[i].latitude, speedTest.pics[i].longitude); var imageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=' + 'FFFFFF,008CFF,000000&ext=.png'; var markerImage = new google.maps.MarkerImage(imageUrl, new google.maps.Size(24, 32)); var marker = new google.maps.Marker({ 'position': latLng, 'icon': markerImage }); var fn = speedTest.markerClickFunction(speedTest.pics[i], latLng); google.maps.event.addListener(marker, 'click', fn); google.maps.event.addDomListener(title, 'click', fn); speedTest.markers.push(marker); } window.setTimeout(speedTest.time, 0); }; speedTest.markerClickFunction = function(pic, latlng) { return function(e) { e.cancelBubble = true; e.returnValue = false; if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } var title = pic.photo_title; var url = pic.photo_url; var fileurl = pic.photo_file_url; var infoHtml = '<div class="info"><h3>' + title + '</h3><div class="info-body">' + '<a href="' + url + '" target="_blank"><img src="' + fileurl + '" class="info-img"/></a></div>' + '<a href="http://www.panoramio.com/" target="_blank">' + '<img src="http://maps.google.com/intl/en_ALL/mapfiles/' + 'iw_panoramio.png"/></a><br/>' + '<a href="' + pic.owner_url + '" target="_blank">' + pic.owner_name + '</a></div></div>'; speedTest.infoWindow.setContent(infoHtml); speedTest.infoWindow.setPosition(latlng); speedTest.infoWindow.open(speedTest.map); }; }; speedTest.clear = function() { $('timetaken').innerHTML = 'cleaning...'; for (var i = 0, marker; marker = speedTest.markers[i]; i++) { marker.setMap(null); } }; speedTest.change = function() { speedTest.clear(); speedTest.showMarkers(); }; speedTest.time = function() { $('timetaken').innerHTML = 'timing...'; var start = new Date(); if ($('usegmm').checked) { speedTest.markerClusterer = new MarkerClusterer(speedTest.map, speedTest.markers); } else { for (var i = 0, marker; marker = speedTest.markers[i]; i++) { marker.setMap(speedTest.map); } } var end = new Date(); $('timetaken').innerHTML = end - start; }; |