PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 122 lines | 62 code | 12 blank | 48 comment | 8 complexity | 8674ac30998429bb0baccb1190669346 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.LatLng;
  8. import com.google.maps.Map;
  9. import com.google.maps.MapMouseEvent;
  10. import com.google.maps.overlays.EncodedPolylineData;
  11. import com.google.maps.overlays.Polygon;
  12. import com.google.maps.overlays.PolygonOptions;
  13. /**
  14. * MultiPolygonWithValue is a wrapper class for Flash Maps API polygons
  15. * that associates a multipolygon geometry with a numerical value.
  16. *
  17. * @author Simon Ilyushchenko
  18. */
  19. public class MultiPolygonWithValue {
  20. // The id associated with the object - usually the geometrry name.
  21. public var id:String = "";
  22. // The numerical value associated with the object,
  23. // to be used in gradient calculations.
  24. public var amount:Number = NaN;
  25. // List of Polygon objects comprising this object.
  26. private var polygons:Array = [];
  27. public function MultiPolygonWithValue() {
  28. }
  29. /**
  30. * Add a Polygon to the current list of polygons.
  31. *
  32. * @param points Array of LatLng coordinates
  33. * @param options PolygonOptions
  34. */
  35. public function addPolygonFromLatLng(
  36. points:Array, options:PolygonOptions = null):void {
  37. var p:Polygon = new Polygon(points, options);
  38. polygons.push(p);
  39. }
  40. /**
  41. * Add a Polygon constructed from encoded polylines
  42. *
  43. * @param points Array of encoded polylines
  44. * @param options PolygonOptions
  45. */
  46. public function addPolygonFromEncoded(
  47. polylineList:Array, options:PolygonOptions = null):void {
  48. var p:Polygon = Polygon.fromEncoded(polylineList, options);
  49. polygons.push(p);
  50. }
  51. /**
  52. * Add a Polygon constructed from a geojson object
  53. *
  54. * @param geojsonMultiPolygon A geojson object
  55. * @param options PolygonOptions
  56. */
  57. public function fromGeojsonMultiPolygon(
  58. geojsonMultiPolygon:Object, options:PolygonOptions = null):void {
  59. for each(var geojsonPolygon:Array in geojsonMultiPolygon) {
  60. for each(var geojsonPoints:Array in geojsonPolygon) {
  61. var vertices:Array = [];
  62. for each (var geojsonPoint:Array in geojsonPoints) {
  63. vertices.push(new LatLng(geojsonPoint[1], geojsonPoint[0]));
  64. }
  65. addPolygonFromLatLng(vertices, options);
  66. }
  67. }
  68. }
  69. /**
  70. * Change polygon options on all constituent polygons
  71. */
  72. public function setOptions(options:PolygonOptions):void {
  73. for each(var polygon:Polygon in polygons) {
  74. polygon.setOptions(options);
  75. }
  76. }
  77. /**
  78. * Add an event listener to all constituent polygons
  79. */
  80. public function addEventListener(eventType:String, f:Function):void {
  81. for each(var p:Polygon in polygons) {
  82. p.addEventListener(eventType, f);
  83. }
  84. }
  85. /**
  86. * Remove an event listener from all constituent polygons
  87. */
  88. public function removeEventListener(eventType:String, f:Function):void {
  89. for each(var p:Polygon in polygons) {
  90. p.removeEventListener(eventType, f);
  91. }
  92. }
  93. /**
  94. * Add all constituent polygons to a map
  95. */
  96. public function addToMap(map:Map): void {
  97. for each(var p:Polygon in polygons) {
  98. map.addOverlay(p);
  99. }
  100. }
  101. /**
  102. * Remove all constituent polygons from a map
  103. */
  104. public function removeFromMap(map:Map): void {
  105. for each(var p:Polygon in polygons) {
  106. map.removeOverlay(p);
  107. }
  108. }
  109. }
  110. }