. .
CREATE OR DIE Special Downloads Shop webinale

Schauplatz

Artikel

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

März 2010

Flash und Geodaten

Ich hier – du da

(Link zum Artikel: http://www.createordie.de/cod/artikel/2930)

Vorab gefragt: Was sind Geodaten überhaupt? Stark vereinfacht geantwortet, stellen Geodaten eine insbesondere durch Computer verarbeitungsfähige Form von Geoinformationen dar und sind digitale Informationen, denen auf der Erdoberfläche eine bestimmte räumliche Lage zugewiesen werden kann. Zweidimensional z. B. hat jeder Punkt eine x- und y-Koordinate, die sich auf einer Ebene, in unserem Fall einer normalen Kartendarstellung, abbilden lassen.

Text: Frank Reitberger

Der Quellcode steht auch als Download bereit.

Diese Kartendarstellung wiederum müssen wir nicht von der Pieke auf selbst entwickeln, sondern können an dieser Stelle bequem auf gängige APIs wie Virtual Earth von Microsoft oder Google Maps zurückgreifen.

Das Kartenmaterial

Ich habe mich kurzerhand für die Google Maps API entschieden, da diese gut dokumentiert ist und es eine Vielzahl an Arbeitsbeispielen und Tutorials für diese API gibt. Eine kleine Hürde gilt es allerdings vorab zu nehmen: Um die Google Maps API verwenden zu können, braucht man einen Maps-API-Schlüssel. Diesen erhält man zwar kostenlos, muss zuvor aber ein Google-Konto eröffnen. Dafür bekommt man letztlich jedoch eine wirklich ausgereifte Anwendung, mit der sich auch sofort arbeiten lässt.

Geographische Länge und Breite bestimmen

Ist man in Besitz des Maps-API-Schlüssels, kann direkt mit dem Setup von Kartenmaterial und GUI losgelegt werden. Hierzu initialisiert man zuerst über new Map() eine neue Karte, verifiziert sich per Maps-API-Schlüssel und richten Basisfunktionalitäten wie den Kartengeländetyp (Karte, Satellit, Hybrid, Gelände) und voreingestellte Zoomstufe ein (Listing 1).

  1. package {
  2. ///////////////////////////////////
  3. // import used classes
  4. ///////////////////////////////////
  5. import flash.display.BitmapData;
  6. import flash.display.Sprite;
  7. import flash.display.MovieClip;
  8. import flash.display.Bitmap;
  9. import flash.geom.Rectangle;
  10. import flash.geom.Point;
  11. import fl.controls.ComboBox;
  12. import fl.controls.TextInput;
  13. import fl.controls.Button;
  14. import fl.data.DataProvider;
  15. import flash.events.Event;
  16. import flash.events.MouseEvent;
  17. import flash.events.KeyboardEvent;
  18. import GeoMapper;
  19. import com.google.maps.LatLng;
  20. import com.google.maps.Map;
  21. import com.google.maps.MapEvent;
  22. import com.google.maps.MapType;
  23. import com.google.maps.MapMouseEvent;
  24. import com.google.maps.services.ClientGeocoder;
  25. import com.google.maps.services.GeocodingEvent;
  26. import com.google.maps.styles.*;
  27. import com.google.maps.overlays.*;
  28. import com.google.maps.controls.*;
  29. import com.google.maps.wrappers.*;
  30. import caurina.transitions.Tweener;
  31. import caurina.transitions.properties.FilterShortcuts;
  32. import caurina.transitions.properties.DisplayShortcuts;
  33. ///////////////////////////////////
  34. // class
  35. ///////////////////////////////////
  36. public class CoreCanvas {
  37. [Embed(source = '../lib/markerLogo.png')] private var markerLogo:Class;
  38. private var container :Sprite;
  39. private var mapNode :Sprite;
  40. private var canvas :BitmapData;
  41. private var tp_surface :BitmapData;
  42. private var lm_surface :BitmapData;
  43. private var rm_surface :BitmapData;
  44. private var bm_surface :BitmapData;
  45. private var markerCanvas :Bitmap = new markerLogo();
  46. private var naviNode :MovieClip = new naviBgClip();
  47. private var infoNode :MovieClip = new infoWindowClip();
  48. public var comboNode :ComboBox;
  49. public var typesProvider :DataProvider;
  50. public var searchNode :TextInput;
  51. public var searchBtn :Button;
  52. private var mapper :GeoMapper;
  53. public var map :Map;
  54. private var geocoder :ClientGeocoder;
  55. private var geoDataPool :Array;
  56. private var marker :Marker;
  57. public var zoomFactor :Number = 10;
  58. ///////////////////////////////
  59. // class constructor
  60. ///////////////////////////////
  61. public function CoreCanvas():void { }
  62. ///////////////////////////////////
  63. // launch
  64. ///////////////////////////////////
  65. public function launch(container:Sprite):void {
  66. this.container = container;
  67. this.mapNode = new Sprite();
  68. this.tp_surface = new BitmapData( 800, 213, false, 0x000000 );
  69. this.lm_surface = new BitmapData( 400, 213, false, 0x000000 );
  70. this.rm_surface = new BitmapData( 400, 213, false, 0x000000 );
  71. this.bm_surface = new BitmapData( 800, 213, false, 0x000000 );
  72. this.canvas = new BitmapData( 800, 640, false, 0x000000 );
  73. FilterShortcuts.init();
  74. DisplayShortcuts.init();
  75. ///////////////////////////////////
  76. // setup
  77. ///////////////////////////////////
  78. setup();
  79. ///////////////////////////////////
  80. // paint
  81. ///////////////////////////////////
  82. paint();
  83. }
  84. ///////////////////////////////////
  85. // setup
  86. ///////////////////////////////////
  87. private function setup():void {
  88. initMaps();
  89. initNavigation();
  90. }
  91. ///////////////////////////////////
  92. // initialize maps
  93. ///////////////////////////////////
  94. private function initMaps():void {
  95. ///////////////////////////////////
  96. // initialize google.map
  97. ///////////////////////////////////
  98. this.map = new Map();
  99. this.map.key = "euer google maps api key hier"
  100. this.map.setSize( new Point( 800, 640 ) );
  101. this.map.y = 0.0;
  102. ///////////////////////////////////
  103. // add
  104. ///////////////////////////////////
  105. this.container.addChild( this.mapNode );
  106. this.mapNode.addChild( map );
  107. this.mapNode.alpha = 0.05;
  108. }
  109. private function onMapReady(event:Event):void {
  110. this.map.setCenter( new LatLng( 51.26, 6.80 ), this.zoomFactor, MapType[ this.comboNode.selectedItem.data ]);
  111. this.geocoder = new ClientGeocoder();
  112. this.map.addEventListener( MouseEvent.MOUSE_WHEEL, mapZoom );
  113. }
  114. ///////////////////////////////////
  115. // initialize navigation
  116. ///////////////////////////////////
  117. private function initNavigation():void {
  118. ///////////////////////////////////
  119. // get component.assets
  120. ///////////////////////////////////
  121. this.searchNode = TextInput( this.naviNode.getChildByName( "searchTxt" ) );
  122. this.searchBtn = Button( this.naviNode.getChildByName( "searchBtn" ) );
  123. this.comboNode = ComboBox( this.naviNode.getChildByName( "mapTypes" ) );
  124. ///////////////////////////////////
  125. // initialize text.input
  126. ///////////////////////////////////
  127. this.searchNode.x = 10.0;
  128. this.searchNode.y = 8.0;
  129. this.searchNode.setSize( 180, 22 );
  130. this.searchNode.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler );
  131. ///////////////////////////////////
  132. // initialize search.button
  133. ///////////////////////////////////
  134. this.searchBtn.x = 200.0;
  135. this.searchBtn.y = 8.0;
  136. this.searchBtn.label = "Suche starten."
  137. this.searchBtn.setSize( 100, 22 );
  138. this.searchBtn.addEventListener( MouseEvent.CLICK, initSearch );
  139. ///////////////////////////////////
  140. // initialize combo.box data
  141. ///////////////////////////////////
  142. this.typesProvider = new DataProvider();
  143. this.typesProvider.addItem( { label: "Karte", data: "NORMAL_MAP_TYPE" } );
  144. this.typesProvider.addItem( { label: "Satellit", data: "SATELLITE_MAP_TYPE" } );
  145. this.typesProvider.addItem( { label: "Hybrid", data: "HYBRID_MAP_TYPE" } );
  146. this.typesProvider.addItem( { label: "Gelände", data: "PHYSICAL_MAP_TYPE" } );
  147. ///////////////////////////////////
  148. // initialize combo.box
  149. ///////////////////////////////////
  150. this.comboNode.x = 650.0;
  151. this.comboNode.y = 8.0;
  152. this.comboNode.setSize( 140, 22 );
  153. this.comboNode.addEventListener( Event.CHANGE, mapTypeSelect );
  154. this.comboNode.dataProvider = this.typesProvider;
  155. ///////////////////////////////////
  156. // initialize info.node
  157. ///////////////////////////////////
  158. this.infoNode.visible = false;
  159. this.infoNode.alpha = 0;
  160. }
  161. ///////////////////////////////////
  162. // zoom map(s)
  163. ///////////////////////////////////
  164. private function mapZoom( event:MouseEvent ):void {
  165. if ( event.delta > 0 ) {
  166. this.map.zoomIn();
  167. } else {
  168. this.map.zoomOut();
  169. }
  170. }
  171. ///////////////////////////////////
  172. // paint map
  173. ///////////////////////////////////
  174. private function paint():void {
  175. this.mapper = new GeoMapper();
  176. this.mapper.surface_tp = this.tp_surface;
  177. this.mapper.surface_lm = this.lm_surface;
  178. this.mapper.surface_rm = this.rm_surface;
  179. this.mapper.surface_bm = this.bm_surface;
  180. ///////////////////////////////////
  181. // add
  182. ///////////////////////////////////
  183. this.mapper.mouseEnabled = false;
  184. this.container.addChild( this.mapper );
  185. this.container.addChild( this.naviNode );
  186. this.mapNode.addChild( this.infoNode );
  187. ///////////////////////////////////
  188. // event(s)
  189. ///////////////////////////////////
  190. this.map.addEventListener( MapEvent.MAP_READY, onMapReady );
  191. this.container.addEventListener( Event.ENTER_FRAME, onUpdateFrame );
  192. }
  193. ///////////////////////////////////
  194. // change: map material
  195. ///////////////////////////////////
  196. private function mapTypeSelect( event:Event ):void {
  197. this.map.setMapType( MapType[ this.comboNode.selectedItem.data ] );
  198. }
  199. }
  200. }

Der Quellcode steht auch als Download bereit.

 

Kommentare
Bisher keine Kommentare
Neuer Kommentar
  • Gute Kommentare werden belohnt.
  •   (optional)
  •   (Kommentar abonnieren/Gravatar - wird nicht veröffentlicht)
  •    Benachrichtige mich bei nachfolgenden Kommentaren per E-Mail
  • -+
Tags
Werbung
geodaten