layer-data-quakes-advanced.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  5. <script src="https://maps.google.com/maps/api/js?sensor=false"></script>
  6. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.js"></script>
  7. <!-- build:js scripts/ng-map.min.js -->
  8. <script src="../app/scripts/app.js"></script>
  9. <script src="../app/scripts/directives/map_controller.js"></script>
  10. <script src="../app/scripts/directives/map.js"></script>
  11. <script src="../app/scripts/directives/marker.js"></script>
  12. <script src="../app/scripts/directives/shape.js"></script>
  13. <script src="../app/scripts/directives/map-data.js"></script>
  14. <script src="../app/scripts/services/geo_coder.js"></script>
  15. <script src="../app/scripts/services/navigator_geolocation.js"></script>
  16. <script src="../app/scripts/services/attr2_options.js"></script>
  17. <!-- endbuild -->
  18. <script>
  19. var app = app || angular.module('myApp', ['ngMap']);
  20. app.controller('LayerDataQuakesAdvCtrl', function($scope) {
  21. function interpolateHsl(lowHsl, highHsl, fraction) {
  22. var color = [];
  23. for (var i = 0; i < 3; i++) {
  24. // Calculate color based on the fraction.
  25. color[i] = (highHsl[i] - lowHsl[i]) * fraction + lowHsl[i];
  26. }
  27. return 'hsl(' + color[0] + ',' + color[1] + '%,' + color[2] + '%)';
  28. }
  29. $scope.styleFunc = function(feature) {
  30. var low = [151, 83, 34]; // color of mag 1.0
  31. var high = [5, 69, 54]; // color of mag 6.0 and above
  32. var minMag = 1.0;
  33. var maxMag = 6.0;
  34. // fraction represents where the value sits between the min and max
  35. var fraction = (Math.min(feature.getProperty('mag'), maxMag) - minMag) /
  36. (maxMag - minMag);
  37. var color = interpolateHsl(low, high, fraction);
  38. return {
  39. icon: {
  40. path: google.maps.SymbolPath.CIRCLE,
  41. strokeWeight: 0.5,
  42. strokeColor: '#fff',
  43. fillColor: color,
  44. fillOpacity: 2 / feature.getProperty('mag'),
  45. // while an exponent would technically be correct, quadratic looks nicer
  46. scale: Math.pow(feature.getProperty('mag'), 2)
  47. },
  48. zIndex: Math.floor(feature.getProperty('mag'))
  49. };
  50. };
  51. });
  52. </script>
  53. </head>
  54. <body>
  55. <div ng-controller="LayerDataQuakesAdvCtrl">
  56. <map zoom="3" center="20, -160"
  57. styles="[{
  58. 'featureType': 'all',
  59. 'elementType': 'all',
  60. 'stylers': [{'visibility': 'off'}]
  61. }, {
  62. 'featureType': 'landscape',
  63. 'elementType': 'geometry',
  64. 'stylers': [{'visibility': 'on'}, {'color': '#fcfcfc'}]
  65. }, {
  66. 'featureType': 'water',
  67. 'elementType': 'labels',
  68. 'stylers': [{'visibility': 'off'}]
  69. }, {
  70. 'featureType': 'water',
  71. 'elementType': 'geometry',
  72. 'stylers': [{'visibility': 'on'}, {'hue': '#5f94ff'}, {'lightness': 60}]
  73. }]">
  74. <map-data
  75. set-style="styleFunc"
  76. load-geo-json="scripts/quakes.geo.json"></map-data>
  77. </map>
  78. </div>
  79. </body>
  80. </html>