PageRenderTime 105ms CodeModel.GetById 22ms RepoModel.GetById 16ms app.codeStats 0ms

/src/com/google/maps/extras/arcgislink/GeometryService.as

http://gmaps-utility-library-flash.googlecode.com/
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. package com.google.maps.extras.arcgislink
  10. {
  11. import flash.events.Event;
  12. import flash.events.EventDispatcher;
  13. import flash.events.IEventDispatcher;
  14. /**
  15. This class represent an
  16. * <a href="http://resources.esri.com/help/9.3/arcgisserver/apis/rest/geometryserver.html">Geometry</a>
  17. * service.
  18. */
  19. public class GeometryService implements IEventDispatcher
  20. {
  21. public var url:String;
  22. public function GeometryService(url:String)
  23. {
  24. dispatcher_= new EventDispatcher(this);
  25. this.url = url;
  26. }
  27. /**
  28. * This resource projects an array of input geometries from an input spatial reference
  29. * to an output spatial reference
  30. * @param {ProjectParameters} params
  31. * @param {Function} callback
  32. */
  33. public function project (params:*, callbackFn:Function=null, failedFn:Function=null):void{
  34. if (!params) {
  35. return;
  36. }
  37. params.f = params.f || 'json';
  38. if (!ArcGISUtil.isString(params.geometries)) {
  39. // problem: REST seems do not like esriGeometryEnvelope
  40. var gt:String = ArcGISConstants.GEOMETRY_POINT;
  41. var json:Array = [];
  42. for (var i:int = 0, c:int = params.geometries.length; i < c; i++) {
  43. var g:* = params.geometries[i];
  44. if (i === 0) {
  45. if (g.points) {
  46. gt = ArcGISConstants.GEOMETRY_MULTIPOINT;
  47. } else if (g.paths) {
  48. gt = ArcGISConstants.GEOMETRY_POLYLINE;
  49. } else if (g.rings) {
  50. gt = ArcGISConstants.GEOMETRY_POLYGON;
  51. }
  52. }
  53. json.push(ArcGISUtil.fromGeometryToJSON(g, false));
  54. }
  55. params.geometries = '{ geometryType:' + gt + ', geometries:[' + json.join(',') + ']}';
  56. }
  57. ArcGISUtil.restRequest(this.url + '/project', params, this, callbackFn, failedFn);
  58. };
  59. private var dispatcher_:EventDispatcher ;
  60. public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void{
  61. dispatcher_.addEventListener(type, listener, useCapture, priority);
  62. }
  63. public function dispatchEvent(evt:Event):Boolean{
  64. return dispatcher_.dispatchEvent(evt);
  65. }
  66. public function hasEventListener(type:String):Boolean{
  67. return dispatcher_.hasEventListener(type);
  68. }
  69. public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void{
  70. dispatcher_.removeEventListener(type, listener, useCapture);
  71. }
  72. public function willTrigger(type:String):Boolean {
  73. return dispatcher_.willTrigger(type);
  74. }
  75. }
  76. }