/src/com/google/maps/extras/arcgislink/GeometryService.as
ActionScript | 83 lines | 56 code | 7 blank | 20 comment | 10 complexity | d2f91161e6cb794e0ad65828f46f8263 MD5 | raw file
1/* 2 * ArcGIS for Google Maps Flash API 3 * 4 * License http://www.apache.org/licenses/LICENSE-2.0 5 */ 6 /** 7 * @author nianwei at gmail dot com 8 */ 9 10package com.google.maps.extras.arcgislink 11{ 12 import flash.events.Event; 13 import flash.events.EventDispatcher; 14 import flash.events.IEventDispatcher; 15/** 16This class represent an 17 * <a href="http://resources.esri.com/help/9.3/arcgisserver/apis/rest/geometryserver.html">Geometry</a> 18 * service. 19 */ 20 public class GeometryService implements IEventDispatcher 21 { 22 public var url:String; 23 public function GeometryService(url:String) 24 { 25 dispatcher_= new EventDispatcher(this); 26 this.url = url; 27 } 28/** 29 * This resource projects an array of input geometries from an input spatial reference 30 * to an output spatial reference 31 * @param {ProjectParameters} params 32 * @param {Function} callback 33 */ 34 public function project (params:*, callbackFn:Function=null, failedFn:Function=null):void{ 35 if (!params) { 36 return; 37 } 38 params.f = params.f || 'json'; 39 if (!ArcGISUtil.isString(params.geometries)) { 40 // problem: REST seems do not like esriGeometryEnvelope 41 var gt:String = ArcGISConstants.GEOMETRY_POINT; 42 var json:Array = []; 43 for (var i:int = 0, c:int = params.geometries.length; i < c; i++) { 44 var g:* = params.geometries[i]; 45 if (i === 0) { 46 if (g.points) { 47 gt = ArcGISConstants.GEOMETRY_MULTIPOINT; 48 } else if (g.paths) { 49 gt = ArcGISConstants.GEOMETRY_POLYLINE; 50 } else if (g.rings) { 51 gt = ArcGISConstants.GEOMETRY_POLYGON; 52 } 53 } 54 json.push(ArcGISUtil.fromGeometryToJSON(g, false)); 55 } 56 params.geometries = '{ geometryType:' + gt + ', geometries:[' + json.join(',') + ']}'; 57 } 58 ArcGISUtil.restRequest(this.url + '/project', params, this, callbackFn, failedFn); 59 }; 60 private var dispatcher_:EventDispatcher ; 61 public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void{ 62 63 dispatcher_.addEventListener(type, listener, useCapture, priority); 64 } 65 66 public function dispatchEvent(evt:Event):Boolean{ 67 return dispatcher_.dispatchEvent(evt); 68 } 69 70 public function hasEventListener(type:String):Boolean{ 71 return dispatcher_.hasEventListener(type); 72 } 73 74 public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void{ 75 dispatcher_.removeEventListener(type, listener, useCapture); 76 } 77 78 public function willTrigger(type:String):Boolean { 79 return dispatcher_.willTrigger(type); 80 } 81 82 } 83}