Commit a7763844 authored by theopolisme's avatar theopolisme
Browse files

Make processing thousands of times faster! Credit to @superphil0, you are amazing!

As seen in PR #2
parent 2d383c42
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/3.8.4/dropzone.min.js"></script>
<script src="lib/leaflet.heat.min.js"></script>
<script src="lib/stream.js"></script>
<script src="lib/prettysize.js"></script>
<script src="index.js"></script>

<!-- Google Analytics -->
+28 −29
Original line number Diff line number Diff line
( function ( $, L, oboe, FileReadStream, prettySize ) {
	var map;
( function ( $, L, prettySize ) {

	// Start at the beginning
	stageOne();
@@ -56,36 +55,36 @@
		}

		function processFile ( file ) {
			var pointNo = 0,
				fileSize = prettySize( file.size ),
				filestream = new FileReadStream( file );
			var fileSize = prettySize( file.size ),
				reader = new FileReader();

			status( 'Preparing to import file (' + fileSize + ')...' );

			oboe( filestream )
				.on( 'node', {
					'locations.*': function ( location ) {
						// Add the new point... prevent lots of redraws by writing to _latlngs
						pointNo += 1;
						status( 'Adding point #' + pointNo.toLocaleString() + ' (' + prettySize( filestream._offset ) + ' / ' + fileSize + ')' );
						heat._latlngs.push( [ location.latitudeE7 * SCALAR_E7, location.longitudeE7 * SCALAR_E7 ] );
					},
					'locations': function () {
						// Don't need any other data now
						this.abort();
						// Also, trigger the next step :D
						renderMap();
					}
				} )
				.on( 'fail', function () {
					status( 'Something went wrong reading your JSON file. Ensure you\'re uploading a "direct-from-Google" JSON file and try again, or create an issue on GitHub if the problem persists.' );
			reader.onprogress = function ( e ) {
				var percentLoaded = Math.round( ( e.loaded / e.total ) * 100 );
				status( percentLoaded + '% of ' + fileSize + ' loaded...' );
			};

			reader.onload = function ( e ) {
				var locations;

				status( 'Generating map...' );

				locations = JSON.parse( e.target.result ).locations;

				heat._latlngs = locations.map( function ( location ) {
					return [ location.latitudeE7 * SCALAR_E7, location.longitudeE7 * SCALAR_E7 ];
				} );

			function renderMap () {
				heat.redraw();
				// Stage 3!
				stageThree( /* numberProcessed */ pointNo );
			}
				stageThree( /* numberProcessed */ locations.length );
			};

			reader.onerror = function () {
				status( 'Something went wrong reading your JSON file. Ensure you\'re uploading a "direct-from-Google" JSON file and try again, or create an issue on GitHub if the problem persists. (error: ' + reader.error + ')' );
			};

			reader.readAsText( file );
		}
	}

@@ -109,4 +108,4 @@
		} );
	}

}( jQuery, L, oboe, FileReadStream, prettySize ) );
}( jQuery, L, prettySize ) );

lib/prettysize.js

0 → 100644
+2 −0
Original line number Diff line number Diff line
/* https://github.com/davglass/prettysize */
(function(){var sizes=["Bytes","kB","MB","GB","TB","PB","EB"];window.prettySize=function(e,s,i){var t,n;return sizes.forEach(function(n,o){i&&(n=n.slice(0,1));var r,B=Math.pow(1024,o);B>e||(r=(e/B).toFixed(1)+"",r.indexOf(".0")===r.length-2&&(r=r.slice(0,-2)),t=r+(s?"":" ")+n)}),t||(n=i?sizes[0].slice(0,1):sizes[0],t="0"+(s?"":" ")+n),t};}());
 No newline at end of file

lib/stream.js

deleted100644 → 0
+0 −714

File deleted.

Preview size limit exceeded, changes collapsed.