/src/com/google/maps/extras/gradients/ThematicOverlay.as

http://gmaps-utility-library-flash.googlecode.com/ · ActionScript · 75 lines · 41 code · 11 blank · 23 comment · 5 complexity · 797d2c0240d453f428ab5e3057ed8237 MD5 · raw file

  1. /**
  2. * Copyright 2009 Google Inc.
  3. * Licensed under the Apache License, Version 2.0:
  4. * http://www.apache.org/licenses/LICENSE-2.0
  5. */
  6. package com.google.maps.extras.gradients {
  7. import com.google.maps.Color;
  8. import com.google.maps.Map;
  9. import com.google.maps.MapMouseEvent;
  10. import com.google.maps.overlays.Polygon;
  11. import com.google.maps.overlays.PolygonOptions;
  12. /**
  13. * ThematicOverlay is a convenience class for drawing thematic maps.
  14. *
  15. * @author Simon Ilyushchenko
  16. */
  17. public class ThematicOverlay {
  18. // Default transparency factor to use when drawing geometries.
  19. public var alpha: Number = 0.7;
  20. // Gradient rule to use for calculating colors.
  21. public var gradientRule:GradientRule;
  22. private var map:Map;
  23. private var polygonsWithValues:Object;
  24. /**
  25. * Class constructor
  26. *
  27. * @param map A Flash API Map object
  28. * @param gradientRule The gradient rule or list of rules to use
  29. * @param polygonsWithValues The list of MultiPolygonWithValues to draw
  30. */
  31. public function ThematicOverlay(
  32. map:Map, gradientRule:GradientRule, polygonsWithValues:Object) {
  33. this.map = map;
  34. this.gradientRule = gradientRule;
  35. this.polygonsWithValues = polygonsWithValues;
  36. for each(var p:MultiPolygonWithValue in this.polygonsWithValues) {
  37. p.addToMap(map);
  38. }
  39. }
  40. /**
  41. * Draw this overlay on the map, coloring all geometries
  42. * in appropriate colors
  43. */
  44. public function draw():void {
  45. var values:Array = [];
  46. for each(var p:MultiPolygonWithValue in polygonsWithValues) {
  47. values.push(p.amount);
  48. }
  49. var gradientControl:GradientControl =
  50. gradientRule.applyGradientToValueList(values);
  51. for each(p in polygonsWithValues) {
  52. var options:Object = {};
  53. if (isNaN(p.amount)) {
  54. options.alpha = 0.0;
  55. } else {
  56. var color:Number = gradientControl.colorForValue(p.amount);
  57. options.color = color;
  58. options.alpha = alpha;
  59. }
  60. p.setOptions(new PolygonOptions({fillStyle: options}));
  61. }
  62. }
  63. }
  64. }