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