Guest User

All JavaScipt Maps in Flash

a guest
Feb 22nd, 2013
1,102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 164.79 KB | None | 0 0
  1.  
  2. I had the same need and also could not find a good ready made solution so I coded and commented a test library below which can serve as the basis for any like project.
  3.  
  4. Rather than rely on a single provider I implemented the same functionality in Flash across Bing Maps V7 (http://msdn.microsoft.com/en-us/library/gg427610.aspx), Google Maps V3 (https://developers.google.com/maps/documentation/javascript/) and MapQuest Maps V7 (http://developer.mapquest.com/web/products/featured/javascript) JavaScript maps. The code creates lines, dynamic markers and shadows, etc. and also calls their elevation apis. The sample app creates two of each map type in one html page.
  5.  
  6. To do this you need to have Flash and JavaScript call each other with data and/or closure via registering functions which have names unique to that item.
  7.  
  8. First each map has a unique mapId and each map MXML component registers a set of external methods with their unique mapId (e.g. fname_mapId) and then creates a Flex-iFrame with a parameterized src HTML for one of the three map types passing mapId, application name, start position etc.
  9.  
  10. The HTML reads these parameters and gets the SWF object from the parent frame via the application name. It creates a map and registers listeners with the map and adds callbacks to the parent frame using its mapId (e.g. fname_mapId) that allow the creation of markers and lines, each of those with a unique id and again registering functions with the parent frame that now also include the marker-or-line id in their name (e.g. fname_mapId_[lineId|markerId]) that allow setting icons, shadows, line color and their position change or removal.
  11.  
  12. The HTML also registers functions by mapId to check elevation of a position or a path in general. These call the ajax or routine to request the elevation(s), calling back to the JavaScript and then back to the AS3 registered functions.
  13.  
  14. -C
  15.  
  16. Logic in the test actions & callbacks - designed to test all the implemented functionality:
  17.  
  18. Double click on map:
  19. Create pin:
  20. - Set to default name
  21. - Add to map
  22. - Set icon and shadow (note Bing does not take shadows; Google can take a marker mask for clicking - not implemented)
  23. - Call to map for elevation
  24. Remove previous marker
  25. Log current markers (should be only 1)
  26. Create black line from start to pin:
  27. - Change line color to blue
  28. - Call to map for path elevation
  29. Remove previous line
  30. Log current lines (should be only 1)
  31. Drag marker:
  32. Start:
  33. - only logs it was called
  34. Drag:
  35. - only logs it was called
  36. End:
  37. - Move line to new lat lng
  38. - Set line color to orange
  39. - Sets map to not accept double clicks
  40. Double click marker:
  41. - Sets map to accept double clicks again (so after you drag you need to double click a marker to have map accept double clicks again)
  42. Elevation callback:
  43. - Changes pin name to include elevation in name
  44. - Sets new icon and shadow for marker
  45. Elevation path callback - set to 300m & 500m - is balloon at 500m on path going to hit? - error if elevation of path >=500, warn if >=300
  46. - Sets line color if path max elevation as sampled is:
  47. Purple: elevation request error flag set
  48. Red: at or above error level
  49. Red-Yellow: at or above warning but requested distance not met
  50. Yellow: at or above warning level
  51. Yellow-Green: below warning level but requested distance not met
  52. Green: below warning level
  53.  
  54. Dependencies: Base64 (http://www.foxarc.com/blog/article/60.htm), Flex-iFrame (https://github.com/flex-users/flex-iframe) (modify and set overflow:none to get rid of Chrome scrollbars), jQuery (http://jquery.com/)
  55.  
  56. TestFloidJavaScriptMaps.mxml - Flash application - creates 2x3 maps:
  57.  
  58. <?xml version="1.0" encoding="utf-8"?>
  59. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  60. <s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
  61. xmlns:s = "library://ns.adobe.com/flex/spark"
  62. xmlns:mx = "library://ns.adobe.com/flex/mx"
  63. xmlns:flexiframe = "http://code.google.com/p/flex-iframe/"
  64. minWidth = "955"
  65. minHeight = "600"
  66. creationComplete = "creationCompleteHandler(event)"
  67. xmlns:local = "*"
  68. xmlns:maps = "com.faiglelabs.floid.maps.*">
  69. <fx:Script>
  70. <![CDATA[
  71. import mx.events.FlexEvent;
  72. protected function creationCompleteHandler(event:FlexEvent):void
  73. {
  74. // Put stuff here to do when application is created...
  75. }
  76. ]]>
  77. </fx:Script>
  78. <s:layout>
  79. <s:VerticalLayout/>
  80. </s:layout>
  81. <s:HGroup>
  82. <s:VGroup>
  83. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="Google"/>
  84. <maps:FloidGoogleMap id="floidGoogleMap_1" mapId="1" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  85. </s:VGroup>
  86. <s:VGroup>
  87. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="MapQuest"/>
  88. <maps:FloidMapQuestMap id="floidMapQuestMap_2" mapId="2" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  89. </s:VGroup>
  90. <s:VGroup>
  91. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="Bing"/>
  92. <maps:FloidBingMap id="floidBingMap_3" mapId="3" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  93. </s:VGroup>
  94. </s:HGroup>
  95. <s:HGroup>
  96. <s:VGroup>
  97. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="Google"/>
  98. <maps:FloidGoogleMap id="floidGoogleMap_4" mapId="4" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  99. </s:VGroup>
  100. <s:VGroup>
  101. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="MapQuest"/>
  102. <maps:FloidMapQuestMap id="floidMapQuestMap_5" mapId="5" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  103. </s:VGroup>
  104. <s:VGroup>
  105. <s:TextArea fontSize="14" width="400" height="24" borderVisible="false" text="Bing"/>
  106. <maps:FloidBingMap id="floidBingMap_6" mapId="6" height="400" width="400" latStart="39.885522" lngStart="3.096644"/>
  107. </s:VGroup>
  108. </s:HGroup>
  109. </s:Application>
  110.  
  111.  
  112. FloidMap.mxml - Map component:
  113.  
  114. <?xml version="1.0" encoding="utf-8"?>
  115. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  116. <s:Group xmlns:fx = "http://ns.adobe.com/mxml/2009"
  117. xmlns:s = "library://ns.adobe.com/flex/spark"
  118. xmlns:mx = "library://ns.adobe.com/flex/mx"
  119. width = "400"
  120. height = "400"
  121. creationComplete = "creationCompleteHandler(event)">
  122. <fx:Script>
  123. <![CDATA[
  124. import mx.events.FlexEvent;
  125. import com.google.code.flexiframe.IFrame;
  126. import com.faiglelabs.floid.testcode.FloidPinAlt;
  127. public var applicationName : String = "TestFloidJavaScriptMaps"; // The name to pass to the html frame to find the swf object
  128. public var mapId : int = 0;
  129. public var mapType : String = "NONE"; // No support for abstract classes in AS3
  130. public var latStart : Number = 39.885522; // Flat low area in ocean by Mallorca near mountains - decimal degrees
  131. public var lngStart : Number = 3.096644; // for line elevation color testing
  132. protected var floidMapFlexIFrame : IFrame = null;
  133. protected var nextMarkerId : int = 1;
  134. protected var nextLineId : int = 1;
  135. protected var currentMarkers : Object = new Object(); // This holds a reference by markerId to its pin
  136. protected var currentLines : Object = new Object(); // This just holds a reference to its own lineId
  137. public var testMaxMarkers : int = 50; // We do not want to flood the elevation service
  138. // Note: Bing says 1024 max here: http://msdn.microsoft.com/en-us/library/jj158961.aspx
  139. // but seems to stop responding with even less than this 50 total
  140. public var testRequestedDistance : int = 400; // We would like them spaced 400 meters apart = 20km total
  141. public var testErrorElevation : Number = 500; // In meters - above or equal is error
  142. public var testWarningElevation : Number = 300; // In meters - below this is ok, otherwise warning
  143. // Component is created:
  144. protected function creationCompleteHandler(event:FlexEvent):void
  145. {
  146. // Put stuff here you want to do when the component is initialized...
  147. trace("FloidMap Component initialized: [" + mapType + "]=" + mapId);
  148. // First, add our callbacks to the DOM now that we know our mapId and before the map is created:
  149. ExternalInterface.addCallback("floidMapInitialized_" + mapId, floidMapInitialized);
  150. ExternalInterface.addCallback("floidMapFrameUnloaded_" + mapId, floidMapFrameUnloaded);
  151. ExternalInterface.addCallback("floidMapDoubleClick_" + mapId, floidMapDoubleClick);
  152. ExternalInterface.addCallback("floidMapPathMaxElevationCallBack_" + mapId, floidMapPathMaxElevationCallBack);
  153. // Create the IFrame that loads the maps html:
  154. floidMapFlexIFrame = new IFrame("floidMapFrame_" + mapId);
  155. floidMapFlexIFrame.percentHeight = 100;
  156. floidMapFlexIFrame.percentWidth = 100;
  157. floidMapFlexIFrame.source = "Floid"+mapType+"MapFrame.html?mapId=" + mapId + "&obj="+applicationName+"&latStart="+latStart+"&lngStart="+lngStart;
  158. floidMapFlexIFrame.overlayDetection = true;
  159. floidMapFlexIFrame.scrollPolicy = IFrame.SCROLL_POLICY_OFF;
  160. floidMapFlexIFrame.addEventListener("frameLoad", floidMapFrameLoad);
  161. this.addElement(floidMapFlexIFrame);
  162. trace("FloidMap Component initialized: [" + mapType + "]=" + mapId + " completed.");
  163. }
  164. // Distance functions:
  165. // -------------------
  166. protected var rad :Object = function(x:*):Number {return x*Math.PI/180;}
  167. // Meters:
  168. protected function distanceHaversine(startLat:Number, startLng:Number, endLat:Number, endLng:Number):Number
  169. {
  170. var R : int = 6371; // earth's mean radius in km
  171. var dLat : Number = rad(endLat - startLat);
  172. var dLong : Number = rad(endLng - startLng);
  173. var a : Number = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(rad(startLat)) * Math.cos(rad(endLat)) * Math.sin(dLong/2) * Math.sin(dLong/2);
  174. var c : Number = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  175. var d : Number = R * c;
  176. return d*1000; // km to m
  177. }
  178. // Map functions & callbacks:
  179. // --------------------------
  180. protected function floidMapInitialized():void
  181. {
  182. // Put stuff here you want to do when the map is initialized...
  183. trace("FloidMap initialized: [" + mapType + "]=" + mapId);
  184. }
  185. protected function floidMapFrameLoad(event:Event):void
  186. {
  187. // Put stuff here you want to do when the frame is loaded
  188. trace("FloidMap frame loaded: [" + mapType + "]=" + mapId);
  189. }
  190. protected function floidMapFrameUnloaded():void
  191. {
  192. // Put stuff here you want to do when the underlying frame receives an unload
  193. trace("map frame unloaded: " + mapId);
  194. }
  195. protected function floidMapDoubleClick(lat:Number, lng:Number):void
  196. {
  197. trace("floidmapDoubleClick: " + mapId + " lat: " + lat + " lng: " + lng);
  198. var markerId : Number = nextMarkerId++;
  199. trace("create new map marker: " + markerId);
  200. trace("calling external interface: floidMapCreateNewMarker_" + mapId + " lat: " + lat + " lng: " + lng);
  201. ExternalInterface.call("floidMapCreateNewMarker_" + mapId, lat, lng, markerId);
  202. // Add callback handlers for this marker:
  203. ExternalInterface.addCallback("floidMapMarkerDoubleClick_" + mapId + "_" + markerId, floidMapMarkerDoubleClick);
  204. ExternalInterface.addCallback("floidMapMarkerDragStart_" + mapId + "_" + markerId, floidMapMarkerDragStart);
  205. ExternalInterface.addCallback("floidMapMarkerDragEnd_" + mapId + "_" + markerId, floidMapMarkerDragEnd);
  206. ExternalInterface.addCallback("floidMapMarkerDrag_" + mapId + "_" + markerId, floidMapMarkerDrag);
  207. ExternalInterface.addCallback("floidMapMarkerElevationResult_" + mapId + "_" + markerId, floidMapMarkerElevationResult);
  208. // The rest of ths routine is test code:
  209. // =====================================
  210. // Make a test call to create a marker icon for this:
  211. var floidPinAlt : FloidPinAlt = new FloidPinAlt();
  212. floidPinAlt.pinName = "Floid-"+mapId+"-"+markerId;
  213. currentMarkers[markerId] = floidPinAlt;
  214. var floidPinMarkerIconBase64String : String = floidPinAlt.makeIcon();
  215. trace("Setting marker icon: " + mapId + " " + markerId);
  216. trace("marker string: " + floidPinMarkerIconBase64String);
  217. ExternalInterface.call("floidMapMarkerSetIconString_" + mapId + "_" + markerId, floidPinMarkerIconBase64String);
  218. var floidPinMarkerIconShadowBase64String : String = floidPinAlt.makeIconShadow();
  219. trace("Setting marker shadow: " + mapId + " " + markerId);
  220. trace("marker shadow string: " + floidPinMarkerIconShadowBase64String);
  221. ExternalInterface.call("floidMapMarkerSetIconShadowString_" + mapId + "_" + markerId, floidPinMarkerIconShadowBase64String);
  222. // TEST CODE BELOW - remove previous marker - so we only have one on map at a time
  223. if(markerId >1)
  224. {
  225. trace("Removing previous marker: " + (markerId-1));
  226. var removePreviousMarkerCallName : String = "floidMapRemoveMarker_" + mapId + "_" + (markerId-1);
  227. ExternalInterface.call(removePreviousMarkerCallName);
  228. // Remove the marker from our associative array:
  229. delete currentMarkers[markerId-1];
  230. }
  231. // TEST CODE BELOW - add a line from latStart, lngStart to this point:
  232. var lineId : Number = nextLineId++;
  233. trace("create new map line: " + lineId);
  234. ExternalInterface.call("floidMapCreateNewLine_" + mapId, lineId, latStart, lngStart, lat, lng, 255, 0, 0, 0, 2); // Opaque Black 2 px line
  235. currentLines[lineId] = lineId;
  236. // TEST CODE BELOW - change the line to blue:
  237. trace("Setting line color to blue:" + lineId);
  238. ExternalInterface.call("floidMapSetLineColor_" + mapId + "_" + lineId, 255, 0, 0, 255, 2);
  239. // TEST CODE BELOW - check the line to see if its height is ok
  240. trace("Checking maxPathElevation:" + lineId);
  241. floidMapGetPathMaxElevation(lineId, latStart, lngStart, lat, lng, testMaxMarkers, testRequestedDistance, testErrorElevation, testWarningElevation);
  242. // TEST CODE BELOW - remove previous line
  243. if(lineId >1)
  244. {
  245. trace("Removing previous line: " + (lineId-1));
  246. var removePreviousLineCallName : String = "floidMapRemoveLine_" + mapId + "_" + (lineId-1);
  247. ExternalInterface.call(removePreviousLineCallName);
  248. // Remove the line from our associative array:
  249. delete currentLines[lineId-1];
  250. }
  251. // TEST CODE BELOW - get the elevation for the pin:
  252. trace("Call back and requesting Elevation: " + mapId + " " + markerId + " " + lat + " " + lng);
  253. ExternalInterface.call("floidMapMarkerRequestElevation_" + mapId + "_" + markerId, markerId, lat, lng);
  254. }
  255. // Marker double click:
  256. protected function floidMapMarkerDoubleClick(markerId:Number):void
  257. {
  258. trace("floidMapMarkerDoubleClick: " + markerId);
  259. // TEST CODE BELOW - RETURN THE MAP TO ACCEPTING DOUBLE CLICKS AFTER DOUBLE CLICKING ANY MARKER:
  260. trace("Turn the map to accept double clicks after double clicking any marker: " + mapId);
  261. ExternalInterface.call("floidMapAddDoubleClickListener_" + mapId, mapId);
  262. }
  263. // Marker drag start:
  264. protected function floidMapMarkerDragStart(markerId:Number, lat:Number, lng:Number):void
  265. {
  266. trace("floidMapMarkerDragStart: " + markerId + " " + lat + " " + lng);
  267. }
  268. // Marker drag end:
  269. protected function floidMapMarkerDragEnd(markerId:Number, lat:Number, lng:Number):void
  270. {
  271. trace("floidMapMarkerDragEnd: " + markerId + " " + lat + " " + lng);
  272. // TEST CODE BELOW:
  273. trace("Call back and requesting Elevation: " + mapId + " " + markerId + " " + lat + " " + lng);
  274. ExternalInterface.call("floidMapMarkerRequestElevation_" + mapId + "_" + markerId, markerId, lat, lng);
  275.  
  276. // Choose only one of the following two tests or you won't be able to click marker to reset map to accepting double clicks:
  277. // // TEST CODE BELOW - TURN THE MARKER TO NOT CLICKABLE AFTER DRAGGING:
  278. // trace("Turn the marker to not clickable after dragging: " + mapId);
  279. // ExternalInterface.call("floidMapMarkerSetClickable_" + mapId + "_" + markerId, false);
  280.  
  281. // This is the other one:
  282. // TEST CODE BELOW - TURN THE MAP TO NOT ACCEPT DOUBLE CLICKS AFTER DRAGGING:
  283. trace("Turn the map to not accept double clicks after dragging: " + mapId);
  284. ExternalInterface.call("floidMapRemoveDoubleClickListener_" + mapId, mapId);
  285.  
  286. // TEST CODE BELOW - SET THE POLYLINE TO MOVE TO THE NEW POSITION
  287. trace("Moving the last polyline to this new position.");
  288. // Note: The test code adds markers and lines 1-1 and only keeps one marker on map, which is why this works:
  289. ExternalInterface.call("floidMapMoveLine__" + mapId + "_" + (nextLineId - 1), latStart , lngStart, lat, lng);
  290. // TEST CODE BELOW - change the line to orange:
  291. trace("Setting line color to orange:" + (nextLineId - 1));
  292. ExternalInterface.call("floidMapSetLineColor_" + mapId + "_" + (nextLineId - 1), 255, 255, 127, 0, 2);
  293. // TEST CODE BELOW - check the line to see if its height is ok
  294. trace("Checking maxPathElevation:" + (nextLineId - 1)); // lineId sl sl el el ms rpdft errft warnft
  295. floidMapGetPathMaxElevation((nextLineId - 1), latStart, lngStart, lat, lng, testMaxMarkers, testRequestedDistance, testErrorElevation, testWarningElevation);
  296. // TEST CODE BELOW - PRINT OUT THE CURRENT MARKER LIST:
  297. trace("Current marker list: " + mapId);
  298. for (var markerIdString:String in currentMarkers)
  299. {
  300. trace("currentMarkers[" + markerIdString + "] = " + currentMarkers[markerIdString] + ";");
  301. }
  302. // TEST CODE BELOW - PRINT OUT THE CURRENT LINE LIST:
  303. trace("Current line list: " + mapId);
  304. for (var lineIdString:String in currentLines)
  305. {
  306. trace("currentLines[" + lineIdString + "] = " + currentLines[lineIdString]);
  307. }
  308. }
  309. // Marker drag:
  310. protected function floidMapMarkerDrag(markerId:Number, lat:Number, lng:Number):void
  311. {
  312. trace("floidMapMarkerDrag: " + markerId + " " + lat + " " + lng);
  313. }
  314. // Marker elevation result:
  315. protected function floidMapMarkerElevationResult(markerId:Number, elevation: Number):void
  316. {
  317. trace("floidMapMarkerElevationResult: " + markerId + " " + elevation);
  318.  
  319. // TEST CODE BELOW HERE - CHANGE THE ICON NAME TO INCLUDE THE STRING AND RE-SEND THE ICON AND SHADOW:
  320. var floidPinAlt:FloidPinAlt = FloidPinAlt(currentMarkers[markerId]);
  321. trace("floidMapMarkerElevationResult: " + markerId + " " + elevation + " retrieved marker:");
  322. floidPinAlt.pinName = "Floid-"+mapId+"-"+markerId + " [" + int(elevation) + "]";
  323. var floidPinMarkerIconBase64String : String = floidPinAlt.makeIcon();
  324. trace("Setting marker icon: " + mapId + " " + markerId);
  325. trace("marker string: " + floidPinMarkerIconBase64String);
  326. ExternalInterface.call("floidMapMarkerSetIconString_" + mapId + "_" + markerId, floidPinMarkerIconBase64String);
  327. var floidPinMarkerIconShadowBase64String : String = floidPinAlt.makeIconShadow();
  328. trace("Setting marker shadow: " + mapId + " " + markerId);
  329. trace("marker shadow string: " + floidPinMarkerIconShadowBase64String);
  330. }
  331. // Get maximum path elevation:
  332. protected function floidMapGetPathMaxElevation(lineId:int, startLat:Number, startLng:Number, endLat:Number, endLng:Number, maxSamples:int, requestedPathDistanceInMeters:Number, errorElevation:Number, warningElevation:Number):void
  333. {
  334. // Calculate the max actual max number of points:
  335. var distanceBetween : Number = distanceHaversine(startLat, startLng, endLat, endLng);
  336. var requiredSamples : int = Math.ceil(distanceBetween / requestedPathDistanceInMeters) + 1; // Note that for 10 evenly spaced slots we need 11 points because we always check both start and end
  337. var actualSamples : int = Math.min(maxSamples, requiredSamples);
  338. var actualPathDistanceInMeters : Number = distanceBetween / (actualSamples-1); // See note above - this is the opposite part...
  339. trace("floidMapGetPathMaxElevation: [" + startLat + ", " + startLng + "] -> [" + endLat + ", " + "] (" + distanceBetween + "m) samples: max " + maxSamples + " actual " + actualSamples + " dist: req " + requestedPathDistanceInMeters + " actual: " + actualPathDistanceInMeters + " level: err " + errorElevation + " warn " + warningElevation);
  340. ExternalInterface.call("floidMapGetPathMaxElevation_" + mapId, lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, actualSamples, actualPathDistanceInMeters);
  341. }
  342. // Callback for GetPathMaxElevation call:
  343. protected function floidMapPathMaxElevationCallBack(lineId:int, startLat:Number, startLng:Number, endLat:Number, endLng:Number, maxSamples:int, requestedPathDistanceInMeters:Number, errorElevation:Number, warningElevation:Number, maxElevation:Number, actualSamples:int, actualPathDistanceInMeters:Number, errorFlag:Boolean):void
  344. {
  345. trace("floidMapPathMaxElevation Callback: maxElevation " + maxElevation + " errorFlag " + errorFlag);
  346. if(errorFlag)
  347. {
  348. floidMapSetLineColor(lineId, 255, 255, 70, 255, 2); // Warning color - magenta
  349. trace("Could not check path");
  350. }
  351. else
  352. {
  353. if(maxElevation > errorElevation)
  354. {
  355. // Elevation is at error:
  356. floidMapSetLineColor(lineId, 255, 255, 70, 70, 2); // Error color - red
  357. trace("Path Elevation Below Error Elevation: " + maxElevation + "m vs " + errorElevation + "m");
  358. }
  359. else if(maxElevation > warningElevation)
  360. {
  361. // Elevation was good - how did we check:
  362. if(actualPathDistanceInMeters > requestedPathDistanceInMeters)
  363. {
  364. // Do not have enough info - warning
  365. floidMapSetLineColor(lineId, 255, 255, 200, 128, 2); // Warning color - red-yellow
  366. trace("Path was at warning but not checked to desired distance: " + actualPathDistanceInMeters + "m vs " + requestedPathDistanceInMeters + "m");
  367. }
  368. else
  369. {
  370. // Elevation is at warning:
  371. floidMapSetLineColor(lineId, 255, 255, 255, 70, 2); // Warning color - yellow
  372. trace("Path Elevation Below Warning Elevation: " + maxElevation + "m vs " + warningElevation + "m");
  373. }
  374. }
  375. else
  376. {
  377. // Elevation was good - how did we check:
  378. if(actualPathDistanceInMeters > requestedPathDistanceInMeters)
  379. {
  380. // Do not have enough info - warning
  381. floidMapSetLineColor(lineId, 255, 200, 255, 128, 2); // Warning color - yellow - green
  382. trace("Path was good but not checked to desired distance: " + actualPathDistanceInMeters + "m vs " + requestedPathDistanceInMeters + "m");
  383. }
  384. else
  385. {
  386. // All was good...
  387. floidMapSetLineColor(lineId, 255, 70, 255, 70, 2); // Good color - green
  388. trace("Elevation was good!");
  389. }
  390. }
  391. }
  392. // Put stuff here, like removing this from a list of path items we are waiting for to have a full mission check complete
  393. // Note some elevation apis as implemented in $.getJSON fail silently and should be redone using $.ajax
  394. trace("mapQuestMapsPathMaxElevation Callback complete");
  395. }
  396. protected function floidMapSetLineColor(lineId:Number, a:int, r:int, g:int, b:int, w:int):void
  397. {
  398. ExternalInterface.call("floidMapSetLineColor_" + mapId + "_" + lineId, a, r, g, b, w);
  399. }
  400. ]]>
  401. </fx:Script>
  402. </s:Group>
  403.  
  404.  
  405. FloidBingMap.mxml - Bing map component:
  406.  
  407. <?xml version="1.0" encoding="utf-8"?>
  408. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  409. <maps:FloidMap xmlns:fx = "http://ns.adobe.com/mxml/2009"
  410. xmlns:s = "library://ns.adobe.com/flex/spark"
  411. xmlns:mx = "library://ns.adobe.com/flex/mx"
  412. xmlns:maps = "com.faiglelabs.floid.maps.*"
  413. width = "400"
  414. height = "400">
  415. <fx:Script>
  416. <![CDATA[
  417. import mx.events.FlexEvent;
  418. // Component is created:
  419. override protected function creationCompleteHandler(event:FlexEvent):void
  420. {
  421. mapType = "Bing";
  422. super.creationCompleteHandler(event);
  423. }
  424. // Override and/or add functionality specific to this map type here...
  425. ]]>
  426. </fx:Script>
  427. </maps:FloidMap>
  428.  
  429.  
  430. FloidGoogleMap.mxml - Google map component:
  431.  
  432. <?xml version="1.0" encoding="utf-8"?>
  433. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  434. <maps:FloidMap xmlns:fx = "http://ns.adobe.com/mxml/2009"
  435. xmlns:s = "library://ns.adobe.com/flex/spark"
  436. xmlns:mx = "library://ns.adobe.com/flex/mx"
  437. xmlns:maps = "com.faiglelabs.floid.maps.*"
  438. width = "400"
  439. height = "400">
  440. <fx:Script>
  441. <![CDATA[
  442. import mx.events.FlexEvent;
  443. // Component is created:
  444. override protected function creationCompleteHandler(event:FlexEvent):void
  445. {
  446. mapType = "Google";
  447. super.creationCompleteHandler(event);
  448. }
  449. // Override and/or add functionality specific to this map type here...
  450. ]]>
  451. </fx:Script>
  452. </maps:FloidMap>
  453.  
  454.  
  455.  
  456. FloidMapQuestMap.mxml - MapQuest map component:
  457.  
  458. <?xml version="1.0" encoding="utf-8"?>
  459. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  460. <maps:FloidMap xmlns:fx = "http://ns.adobe.com/mxml/2009"
  461. xmlns:s = "library://ns.adobe.com/flex/spark"
  462. xmlns:mx = "library://ns.adobe.com/flex/mx"
  463. xmlns:maps = "com.faiglelabs.floid.maps.*"
  464. width = "400"
  465. height = "400">
  466. <fx:Script>
  467. <![CDATA[
  468. import mx.events.FlexEvent;
  469. // Component is created:
  470. override protected function creationCompleteHandler(event:FlexEvent):void
  471. {
  472. mapType = "MapQuest";
  473. super.creationCompleteHandler(event);
  474. }
  475. // Override and/or add functionality specific to this map type here...
  476. ]]>
  477. </fx:Script>
  478. </maps:FloidMap>
  479.  
  480.  
  481.  
  482. FloidBingMapFrame.html - Bing html component:
  483.  
  484. <!DOCTYPE html>
  485. <html>
  486. <head>
  487. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  488. <meta name="viewport"
  489. content="initial-scale=1.0, user-scalable=no" />
  490. <style type="text/css">
  491. html { height: 100% }
  492. body { height: 100%; margin: 0; padding: 0 }
  493. #map_canvas { height: 100% }
  494. </style>
  495. <script type ="text/javascript"
  496. src ="FloidMapUtilities.js">
  497. </script>
  498. <script type ="text/javascript"
  499. src ="jquery-1.9.1.min.js">
  500. </script>
  501. <script type ="text/javascript"
  502. src ="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
  503. </script>
  504. <script type="text/javascript">
  505. ///////////////////////////////////////////
  506. ///////////////////////////////////////////
  507. // Main Initialize - Magic starts here: //
  508. ///////////////////////////////////////////
  509. ///////////////////////////////////////////
  510. function initialize()
  511. {
  512. //------------------------------------------------------------------------------------//
  513. // We need to keep track of the map listeners so we can turn them on/off in routines //
  514. //------------------------------------------------------------------------------------//
  515. var mapDoubleClickListener = null;
  516. //----------------------------------//
  517. // Create the default map options: //
  518. //----------------------------------//
  519. var mapOptions = {
  520. credentials: "YOUR_API_KEY",
  521. center: new Microsoft.Maps.Location(latStart, lngStart),
  522. mapTypeId: Microsoft.Maps.MapTypeId.road,
  523. zoom: 12
  524. };
  525. //---------------------------------------//
  526. // Create the map: //
  527. //---------------------------------------//
  528. var map = new Microsoft.Maps.Map(document.getElementById("map_canvas"), mapOptions);
  529. //----------------------------------------------//
  530. // By default we add the double click listener: //
  531. //----------------------------------------------//
  532. addDoubleClickListener();
  533. //-------------------------------------------------------//
  534. // Make add and remove map double click event listeners: //
  535. //-------------------------------------------------------//
  536. function addDoubleClickListener()
  537. {
  538. log("Adding map double click listener: " + mapId);
  539. // Remove previous
  540. if(mapDoubleClickListener != null)
  541. {
  542. Microsoft.Maps.Events.removeHandler(mapDoubleClickListener);
  543. mapDoubleClickListener = null;
  544. }
  545. // Add new:
  546. try
  547. {
  548. mapDoubleClickListener = Microsoft.Maps.Events.addHandler(map,
  549. 'dblclick',
  550. function(event)
  551. {
  552. if(event.target==map)
  553. {
  554. var point = new Microsoft.Maps.Point(event.getX(), event.getY());
  555. var loc = event.target.tryPixelToLocation(point);
  556. mapDoubleClick(loc);
  557. event.handled = true;
  558. }
  559. });
  560. }
  561. catch(err)
  562. {
  563. log("addDoubleClickListener: " + err);
  564. mapDoubleClickListener = null;
  565. }
  566. }
  567. function removeDoubleClickListener()
  568. {
  569. log("Removing map double click listener: " + mapId);
  570. // Remove previous
  571. if(mapDoubleClickListener != null)
  572. {
  573. Microsoft.Maps.Events.removeHandler(mapDoubleClickListener);
  574. mapDoubleClickListener = null;
  575. }
  576. // Add new:
  577. try
  578. {
  579. mapDoubleClickListener = Microsoft.Maps.Events.addHandler(map,
  580. 'dblclick',
  581. function(event)
  582. {
  583. if(event.target==map)
  584. {
  585. event.handled = true;
  586. }
  587. });
  588. }
  589. catch(err)
  590. {
  591. log("removeDoubleClickListener: " + err);
  592. mapDoubleClickListener = null;
  593. }
  594. }
  595. //------------------------------------------//
  596. // Create handlers for map double click: //
  597. //------------------------------------------//
  598. // mapDoubleClick:
  599. function mapDoubleClick(latLng)
  600. {
  601. log("mapDoubleClick: " + latLng);
  602. log("calling flash routine: " + "floidMapDoubleClick_" + mapId);
  603. swfObject["floidMapDoubleClick_" + mapId](latLng.latitude, latLng.longitude);
  604. }
  605. //********************************//
  606. //********************************//
  607. // Calls from Flash to the map: //
  608. //********************************//
  609. //********************************//
  610. ////////////////////////////////////////////////
  611. // Function creators for flash calls to map: //
  612. ////////////////////////////////////////////////
  613. // -----------------------------
  614. // floidBingMapsCreateNewMarker:
  615. // -----------------------------
  616. function makeFloidBingMapsCreateNewMarkerFunction()
  617. {
  618. return function(lat, lng, markerId)
  619. {
  620. log("floidBingMapsCreateNewMarker: " + lat + " " + lng + " " + markerId);
  621. createNewMarker(lat, lng, markerId);
  622. }
  623. }
  624. // ---------------------------
  625. // floidBingMapsCreateNewLine:
  626. // ---------------------------
  627. function makeFloidBingMapsCreateNewLineFunction()
  628. {
  629. return function(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  630. {
  631. log("floidBingMapsCreateNewLine: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + a + " " + r + " " + g + " " + b);
  632. createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w);
  633. }
  634. }
  635. // ------------------------------------
  636. // floidBingMapsAddDoubleClickListener:
  637. // ------------------------------------
  638. function makeFloidBingMapsAddDoubleClickListenerFunction()
  639. {
  640. return function(mapId)
  641. {
  642. log("floidBingMapsAddDoubleClickListener: " + mapId);
  643. addDoubleClickListener();
  644. }
  645. }
  646. // ---------------------------------------
  647. // floidBingMapsRemoveDoubleClickListener:
  648. // ---------------------------------------
  649. function makeFloidBingMapsRemoveDoubleClickListenerFunction()
  650. {
  651. return function(mapId)
  652. {
  653. log("floidBingMapsRemoveDoubleClickListener: " + mapId);
  654. removeDoubleClickListener();
  655. }
  656. }
  657. // ----------------------------------
  658. // floidBingMapsGetPathMaxElevation:
  659. // ----------------------------------
  660. function makeFloidBingMapsGetPathMaxElevationFunction()
  661. {
  662. return function(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters)
  663. {
  664. log("floidBingMapsGetPathMaxElevation: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + maxMarkers + " " + requestedPathDistanceInMeters + " " + errorElevation + " " + warningElevation + " " + actualMarkers + " " + actualPathDistanceInMeters);
  665. getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters);
  666. }
  667. }
  668. //////////////////////////////////////////////////////////////////////////////
  669. // Make a set of function creation routines for the flash calls to the DOM: //
  670. //////////////////////////////////////////////////////////////////////////////
  671. // -----------------------------
  672. // floidBingMapsCreateNewMarker:
  673. // -----------------------------
  674. var floidBingMapsCreateNewMarkerFunctionName = "floidMapCreateNewMarker_" + mapId;
  675. this.parent[floidBingMapsCreateNewMarkerFunctionName] = makeFloidBingMapsCreateNewMarkerFunction();
  676. // ---------------------------
  677. // floidBingMapsCreateNewLine:
  678. // ---------------------------
  679. var floidBingMapsCreateNewLineFunctionName = "floidMapCreateNewLine_" + mapId;
  680. this.parent[floidBingMapsCreateNewLineFunctionName] = makeFloidBingMapsCreateNewLineFunction();
  681. // ------------------------------------
  682. // floidBingMapsAddDoubleClickListener:
  683. // ------------------------------------
  684. var floidBingMapsAddDoubleClickListenerFunctionName = "floidMapAddDoubleClickListener_" + mapId;
  685. this.parent[floidBingMapsAddDoubleClickListenerFunctionName] = makeFloidBingMapsAddDoubleClickListenerFunction();
  686. // ---------------------------------------
  687. // floidBingMapsRemoveDoubleClickListener:
  688. // ---------------------------------------
  689. var floidBingMapsRemoveDoubleClickListenerFunctionName = "floidMapRemoveDoubleClickListener_" + mapId;
  690. this.parent[floidBingMapsRemoveDoubleClickListenerFunctionName] = makeFloidBingMapsRemoveDoubleClickListenerFunction();
  691. // --------------------------------
  692. // floidBingMapsGetPathMaxElevation:
  693. // --------------------------------
  694. var floidBingMapsGetPathMaxElevationFunctionName = "floidMapGetPathMaxElevation_" + mapId;
  695. this.parent[floidBingMapsGetPathMaxElevationFunctionName] = makeFloidBingMapsGetPathMaxElevationFunction();
  696. /////////////////////////////
  697. // Map routines: //
  698. /////////////////////////////
  699. var clickable = true;
  700. // ----- MARKERS -----
  701. // ----------------
  702. // createNewMarker:
  703. // ----------------
  704. function createNewMarker(lat, lng, markerId)
  705. {
  706. log("Making new marker [" + mapId + "] ("+lat + ", " + lng + ")");
  707. var markerOptions = {
  708. draggable: true
  709. };
  710. var marker = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lng), markerOptions);
  711. var dragStarted = false;
  712. var dragged = false;
  713. map.entities.push(marker);
  714. ////////////////////////////////////////////////
  715. // Marker listeners that call back to flash: //
  716. ////////////////////////////////////////////////
  717. // ------------------------------------------------------
  718. // OK, here we want to add the listeners for this marker:
  719. // ------------------------------------------------------
  720. Microsoft.Maps.Events.addHandler( marker,
  721. 'dblclick',
  722. function(event)
  723. {
  724. log("*************** MARKER DOUBLE CLICK ************");
  725. dragStarted = false;
  726. dragged = false;
  727. if(clickable)
  728. {
  729. swfObject["floidMapMarkerDoubleClick_" + mapId+"_"+markerId](markerId);
  730. }
  731. event.handled = true;
  732. });
  733. Microsoft.Maps.Events.addHandler( marker,
  734. 'dragstart',
  735. function(event)
  736. {
  737. dragStarted = true;
  738. dragged = false;
  739. });
  740. Microsoft.Maps.Events.addHandler( marker,
  741. 'dragend',
  742. function(event)
  743. {
  744. if(dragged)
  745. {
  746. swfObject["floidMapMarkerDragEnd_" + mapId+"_"+markerId](markerId, event.entity.getLocation().latitude, event.entity.getLocation().longitude);
  747. }
  748. dragStarted = false;
  749. dragged = false;
  750. });
  751. Microsoft.Maps.Events.addHandler( marker,
  752. 'drag',
  753. function(event)
  754. {
  755. if(dragStarted)
  756. {
  757. dragStarted = false;
  758. dragged = true;
  759. swfObject["floidMapMarkerDragStart_" + mapId+"_"+markerId](markerId, event.entity.getLocation().latitude, event.entity.getLocation().longitude);
  760. }
  761. swfObject["floidMapMarkerDrag_" + mapId+"_"+markerId](markerId, event.entity.getLocation().latitude, event.entity.getLocation().longitude);
  762. });
  763. //***********************************//
  764. //***********************************//
  765. // Calls from Flash to the marker: //
  766. //***********************************//
  767. //***********************************//
  768. ///////////////////////////////////////////////////
  769. // Function creators for flash calls to marker: //
  770. ///////////////////////////////////////////////////
  771. // -----------------------------------------------------
  772. // floidBingMapsMarkerSetClickable: [function creator]
  773. // -----------------------------------------------------
  774. function makeFloidBingMapsMarkerSetClickableFunction(marker, markerId)
  775. {
  776. return function(isClickable)
  777. {
  778. clickable = isClickable;
  779. }
  780. }
  781. // -----------------------------------------------------
  782. // floidBingMapsMarkerSetDraggable: [function creator]
  783. // -----------------------------------------------------
  784. function makeFloidBingMapsMarkerSetDraggableFunction(marker, markerId)
  785. {
  786. return function(draggable)
  787. {
  788. log("floidBingMapsMarkerSettingDraggable: " + markerId + " to " + draggable);
  789. marker.setOptions({draggable: draggable});
  790. }
  791. }
  792. // -----------------------------------------------------
  793. // floidBingMapsMarkerSetIconString: [function creator]
  794. // -----------------------------------------------------
  795. function makeFloidBingMapsMarkerSetIconStringFunction(marker, markerId)
  796. {
  797. return function(iconString)
  798. {
  799. log("floidBingMapsMarkerSetIconString: " + markerId);
  800. log("marker icon string: " + iconString);
  801. var markerIcon = {icon: 'data:image/png;base64,'+iconString,
  802. height: 38,
  803. width: 100,
  804. anchor: new Microsoft.Maps.Point(0,38)
  805. };
  806. log("floidBingMapsMarkerSetIconString: " + markerId + " - markerIconMade");
  807. marker.setOptions(markerIcon);
  808. log("floidBingMapsMarkerSetIconString: " + markerId + " - markerIconSet");
  809. }
  810. }
  811. // ------------------------------------------------------------
  812. // floidBingMapsMarkerSetIconShadowString: [function creator]
  813. // ------------------------------------------------------------
  814. function makeFloidBingMapsMarkerSetIconShadowStringFunction(marker, markerId)
  815. {
  816. return function(iconShadowString)
  817. {
  818. log("floidBingMapsMarkerSetIconShadowString: " + markerId);
  819. log("marker shadow string: [NOT SUPPORTED BY BING?]" + iconShadowString);
  820. }
  821. }
  822. // ---------------------------------------------------------
  823. // floidBingMapsMarkerRequestElevation: [function creator]
  824. // ---------------------------------------------------------
  825. function makeFloidBingMapsMarkerRequestElevationFunction(marker, markerId)
  826. {
  827. return function(markerId, lat, lng)
  828. {
  829. log("floidBingMapsMarkerRequestElevation: " + markerId + " - Requesting Elevation for: " + lat + " " + lng);
  830. // Locations parameter:
  831. var bingElevationUrl = "http://dev.virtualearth.net/REST/v1/Elevation/List?points="+lat+","+lng+"&key=YOUR_API_KEY&jsonp=?";
  832. $.getJSON(bingElevationUrl, function(data) {
  833. log("requestElevationFunction: " + data );
  834. if( (data != null)
  835. && (data.resourceSets != null)
  836. && (data.resourceSets.length >0)
  837. && (data.resourceSets[0].resources != null)
  838. && (data.resourceSets[0].resources.length >0)
  839. && (data.resourceSets[0].resources[0] != null)
  840. && (data.resourceSets[0].resources[0].elevations != null)
  841. && (data.resourceSets[0].resources[0].elevations.length >0) )
  842. {
  843. var elevation = data.resourceSets[0].resources[0].elevations[0];
  844. log("Elevation of point: " + elevation);
  845. // call back into flash :)
  846. swfObject["floidMapMarkerElevationResult_" + mapId+"_"+markerId](markerId, elevation);
  847. log("elevation callback done:");
  848. }
  849. else
  850. {
  851. log("Error in requestElevationFunction results");
  852. }
  853. });
  854. log("floidBingMapsMarkerRequestElevation: " + markerId + " - Elevation Requested");
  855. }
  856. }
  857. // ---------------------------------------------
  858. // floidBingMapsRemoveMarker: [function creator]
  859. // ---------------------------------------------
  860. function makeFloidBingMapsRemoveMarkerFunction(marker, markerId)
  861. {
  862. return function()
  863. {
  864. log("floidBingMapsRemoveMarker: " + mapId + " " + markerId);
  865. try
  866. {
  867. // Remove the marker:
  868. map.entities.remove(marker);
  869. marker = null;
  870. // Remove the globally bound functions:
  871. delete this.parent[floidBingMapsMarkerSetClickableFunctionName];
  872. delete this.parent[floidBingMapsMarkerSetDraggableFunctionName];
  873. delete this.parent[floidBingMapsMarkerRequestElevationFunctionName];
  874. delete this.parent[floidBingMapsMarkerSetIconStringFunctionName];
  875. delete this.parent[floidBingMapsMarkerSetIconShadowStringFunctionName];
  876. // Don't forget me!
  877. delete this.parent[floidBingMapsRemoveMarkerFunctionName];
  878. }
  879. catch(err)
  880. {
  881. log("floidBingMapsRemoveMarker: error " + mapId + " " + markerId + " " + err);
  882. }
  883. log("Done removing marker.");
  884. }
  885. }
  886. ///////////////////////////////////////////////////////
  887. // Add the flash calls for this marker to the DOM: //
  888. ///////////////////////////////////////////////////////
  889. // -----------------------------------------------------
  890. // floidBingMapsMarkerSetClickable:
  891. // -----------------------------------------------------
  892. var floidBingMapsMarkerSetClickableFunctionName = "floidMapMarkerSetClickable_" + mapId + "_" + markerId;
  893. this.parent[floidBingMapsMarkerSetClickableFunctionName] = makeFloidBingMapsMarkerSetClickableFunction(marker, markerId);
  894. // -----------------------------------------------------
  895. // floidBingMapsMarkerSetDraggable:
  896. // -----------------------------------------------------
  897. var floidBingMapsMarkerSetDraggableFunctionName = "floidMapMarkerSetDraggable_" + mapId + "_" + markerId;
  898. this.parent[floidBingMapsMarkerSetDraggableFunctionName] = makeFloidBingMapsMarkerSetDraggableFunction(marker, markerId);
  899. // -----------------------------------------------------
  900. // floidBingMapsMarkerRequestElevation:
  901. // -----------------------------------------------------
  902. var floidBingMapsMarkerRequestElevationFunctionName = "floidMapMarkerRequestElevation_" + mapId + "_" + markerId;
  903. this.parent[floidBingMapsMarkerRequestElevationFunctionName] = makeFloidBingMapsMarkerRequestElevationFunction(marker, markerId);
  904. // -----------------------------------------------------
  905. // floidBingMapsMarkerSetIconString:
  906. // -----------------------------------------------------
  907. var floidBingMapsMarkerSetIconStringFunctionName = "floidMapMarkerSetIconString_" + mapId + "_" + markerId;
  908. this.parent[floidBingMapsMarkerSetIconStringFunctionName] = makeFloidBingMapsMarkerSetIconStringFunction(marker, markerId);
  909. // -----------------------------------------------------
  910. // floidBingMapsMarkerSetIconShadowString:
  911. // -----------------------------------------------------
  912. var floidBingMapsMarkerSetIconShadowStringFunctionName = "floidMapMarkerSetIconShadowString_" + mapId + "_" + markerId;
  913. this.parent[floidBingMapsMarkerSetIconShadowStringFunctionName] = makeFloidBingMapsMarkerSetIconShadowStringFunction(marker, markerId);
  914. // ----------------------------
  915. // floidBingMapsRemoveMarker:
  916. // ----------------------------
  917. var floidBingMapsRemoveMarkerFunctionName = "floidMapRemoveMarker_" + mapId + "_" + markerId;
  918. this.parent[floidBingMapsRemoveMarkerFunctionName] = makeFloidBingMapsRemoveMarkerFunction(marker, markerId);
  919.  
  920. }
  921. // ----- LINES -----
  922. // -----------------
  923. // createNewLine:
  924. // -----------------
  925. function createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  926. {
  927. var options = { strokeColor : new Microsoft.Maps.Color(a, r, g, b),
  928. strokeThickness : 1 };
  929. var line = new Microsoft.Maps.Polyline( [ new Microsoft.Maps.Location(startLat, startLng),
  930. new Microsoft.Maps.Location(endLat, endLng)
  931. ],
  932. options
  933. );
  934. map.entities.push(line);
  935. //////////////////////////////////////////////
  936. // Line listeners that call back to flash: //
  937. //////////////////////////////////////////////
  938. // ----------------------------------------------------
  939. // OK, here we want to add the listeners for this line:
  940. // ----------------------------------------------------
  941. // Default is no listeners for this line:
  942. //***********************************//
  943. //***********************************//
  944. // Calls from Flash to the line: //
  945. //***********************************//
  946. //***********************************//
  947. /////////////////////////////////////////////////
  948. // Function creators for flash calls to line: //
  949. /////////////////////////////////////////////////
  950. // -----------------------------------------------
  951. // floidBingMapsRemoveLine: [function creator]
  952. // -----------------------------------------------
  953. function makeFloidBingMapsRemoveLineFunction(line, lineId)
  954. {
  955. return function()
  956. {
  957. log("Removing line.");
  958. try
  959. {
  960. // Remove the line:
  961. map.entities.remove(line);
  962. line = null;
  963. // Remove the globally bound functions:
  964. // - empty
  965. // Don't forget me!
  966. delete this.parent[floidBingMapsRemoveLineFunctionName];
  967. }
  968. catch(err)
  969. {
  970. log("floidBingMapsRemoveMarker: error " + err);
  971. }
  972. log("Done removing line.");
  973. }
  974. }
  975. // -----------------------------------------------
  976. // floidBingMapsSetLineColor: [function creator]
  977. // -----------------------------------------------
  978. function makeFloidBingMapsSetLineColorFunction(line, lineId)
  979. {
  980. return function(a, r, g, b, w)
  981. {
  982. log("Changing line color.");
  983. try
  984. {
  985. var strokeOptions = { strokeColor: new Microsoft.Maps.Color(a, r, g, b), strokeThickness:w};
  986. line.setOptions(strokeOptions);
  987. }
  988. catch(err)
  989. {
  990. log("floidBingMapsSetLineColor: error " + err);
  991. }
  992. log("Done setting line color.");
  993. }
  994. }
  995. // -----------------------------------------
  996. // floidBingMapsMoveLine: [function creator]
  997. // -----------------------------------------
  998. function makeFloidBingMapsMoveLineFunction(line, lineId)
  999. {
  1000. return function(startLat, startLng, endLat, endLng)
  1001. {
  1002. log("Moving line [" + lineId + "] to: " + startLat + " " + startLng + " -> " + endLat + " " + endLng);
  1003. try
  1004. {
  1005. line.setLocations( [ new Microsoft.Maps.Location(startLat, startLng),
  1006. new Microsoft.Maps.Location(endLat, endLng)
  1007. ]);
  1008. }
  1009. catch(err)
  1010. {
  1011. log("floidBingMapsMoveLine: error " + err);
  1012. }
  1013. log("Done moving line.");
  1014. }
  1015. }
  1016. /////////////////////////////////////////////////////
  1017. // Add the flash calls for this line to the DOM: //
  1018. /////////////////////////////////////////////////////
  1019. // -----------------------------------------------------
  1020. // floidBingMapsRemoveLineFunction:
  1021. // -----------------------------------------------------
  1022. var floidBingMapsRemoveLineFunctionName = "floidMapRemoveLine_" + mapId + "_" + lineId;
  1023. this.parent[floidBingMapsRemoveLineFunctionName] = makeFloidBingMapsRemoveLineFunction(line, lineId);
  1024. // -----------------------------------------------------
  1025. // floidBingMapsSetLineColorFunction:
  1026. // -----------------------------------------------------
  1027. var floidBingMapsSetLineColorFunctionName = "floidMapSetLineColor_" + mapId + "_" + lineId;
  1028. this.parent[floidBingMapsSetLineColorFunctionName] = makeFloidBingMapsSetLineColorFunction(line, lineId);
  1029. // -----------------------------------------------------
  1030. // floidBingMapsMoveLineFunction:
  1031. // -----------------------------------------------------
  1032. var floidBingMapsMoveLineFunctionName = "floidMapMoveLine__" + mapId + "_" + lineId;
  1033. this.parent[floidBingMapsMoveLineFunctionName] = makeFloidBingMapsMoveLineFunction(line, lineId);
  1034. }
  1035. // ------ Paths -------
  1036. // --------------------
  1037. // getPathMaxElevation:
  1038. // --------------------
  1039. function getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, actualSamples, actualPathDistanceInMeters)
  1040. {
  1041. var sampleLocations = calculateSamples(startLat, startLng, endLat, endLng, actualSamples);
  1042. var sampleLatLngPointsString = "";
  1043. var firstLocation = true;
  1044. for(var i=0; i<sampleLocations.length; ++i)
  1045. {
  1046. if(firstLocation)
  1047. {
  1048. firstLocation = false;
  1049. }
  1050. else
  1051. {
  1052. sampleLatLngPointsString = sampleLatLngPointsString + ", ";
  1053. }
  1054. sampleLatLngPointsString = sampleLatLngPointsString + sampleLocations[i];
  1055. }
  1056. var bingElevationUrl = "http://dev.virtualearth.net/REST/v1/Elevation/List?points="+sampleLatLngPointsString+"&key=YOU_API_KEY&jsonp=?";
  1057. // TODO Add a timer here since this can fail silently or use jQuery $.ajax instead:
  1058. $.getJSON(bingElevationUrl, function(data) {
  1059. log( data );
  1060. var errorFlag = true;
  1061. var maxElevation = -100000; // Min value
  1062. if( (data != null)
  1063. && (data.resourceSets != null)
  1064. && (data.resourceSets.length >0)
  1065. && (data.resourceSets[0].resources != null)
  1066. && (data.resourceSets[0].resources.length >0)
  1067. && (data.resourceSets[0].resources[0] != null)
  1068. && (data.resourceSets[0].resources[0].elevations != null)
  1069. && (data.resourceSets[0].resources[0].elevations.length >0) )
  1070. {
  1071. maxElevation = data.resourceSets[0].resources[0].elevations[0];
  1072. errorFlag = false;
  1073. for(var i=0; i<data.resourceSets[0].resources[0].elevations.length; ++i)
  1074. {
  1075. var sampleElevation = data.resourceSets[0].resources[0].elevations[i];
  1076. if(sampleElevation > maxElevation) maxElevation = sampleElevation;
  1077. }
  1078. log("Max elevation of path: " + maxElevation);
  1079. // call back into flash :)
  1080. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  1081. log("elevation callback done:");
  1082. }
  1083. else
  1084. {
  1085. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  1086. log("Error in getPathMaxElevation results");
  1087. }
  1088. });
  1089. log("getMaxPathElevation: " + lineId + " - Elevation Requested");
  1090. }
  1091. // OK, the map is fully initialized - call back into flash:
  1092. swfObject["floidMapInitialized_" + mapId]();
  1093. }
  1094. function finalize()
  1095. {
  1096. // Remove global map functions - TODO: remove remaining marker & line functions
  1097. try
  1098. {
  1099. delete this.parent[floidBingMapsCreateNewMarkerFunctionName];
  1100. delete this.parent[floidBingMapsCreateNewLineFunctionName];
  1101. delete this.parent[floidBingMapsAddDoubleClickListenerFunctionName];
  1102. delete this.parent[floidBingMapsRemoveDoubleClickListenerFunctionName];
  1103. delete this.parent[floidBingMapsGetPathMaxElevationFunctionName];
  1104. }
  1105. catch(err)
  1106. {
  1107. log("Removing map methods error: " + err);
  1108. }
  1109. if(swfObject != null)
  1110. {
  1111. // call back into flash :)
  1112. swfObject["floidMapFrameUnloaded_" + mapId]();
  1113. }
  1114. }
  1115. </script>
  1116. </head>
  1117. <body onload="initialize()" onunload="finalize()">
  1118. <div id="map_canvas" style="width:100%; height:100%"></div>
  1119. </body>
  1120. </html>
  1121.  
  1122.  
  1123. FloidGoogleMapFrame.html - Google html component:
  1124.  
  1125. <!DOCTYPE html>
  1126. <html>
  1127. <head>
  1128. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  1129. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  1130. <style type="text/css">
  1131. html { height: 100% }
  1132. body { height: 100%; margin: 0; padding: 0 }
  1133. #map_canvas { height: 100% }
  1134. </style>
  1135. <script type ="text/javascript"
  1136. src ="FloidMapUtilities.js">
  1137. </script>
  1138. <script type="text/javascript"
  1139. src="https://maps.googleapis.com/maps/api/js?sensor=false"><!-- src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=false"> -->
  1140. </script>
  1141. <script type="text/javascript">
  1142. ///////////////////////////////////////////
  1143. ///////////////////////////////////////////
  1144. // Main Initialize - Magic starts here: //
  1145. ///////////////////////////////////////////
  1146. ///////////////////////////////////////////
  1147. function initialize()
  1148. {
  1149. //------------------------------------------------------------------------------------//
  1150. // We need to keep track of the map listeners so we can turn them on/off in routines //
  1151. //------------------------------------------------------------------------------------//
  1152. var mapDoubleClickListener = null;
  1153. //----------------------------------//
  1154. // Create the default map options: //
  1155. //----------------------------------//
  1156. var mapOptions = {
  1157. center : new google.maps.LatLng(latStart, lngStart),
  1158. zoom : 12,
  1159. mapTypeId : google.maps.MapTypeId.ROADMAP,
  1160. disableDoubleClickZoom : true,
  1161. disableDefaultUI : true,
  1162. panControl : true,
  1163. zoomControl : true,
  1164. mapTypeControl : true,
  1165. scaleControl : true,
  1166. streetViewControl : true,
  1167. overviewMapControl : true
  1168. };
  1169. //---------------------------------------//
  1170. // Create the map and elevator service: //
  1171. //---------------------------------------//
  1172. var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  1173. var elevator = new google.maps.ElevationService();
  1174. //----------------------------------------------//
  1175. // By default we add the double click listener: //
  1176. //----------------------------------------------//
  1177. addDoubleClickListener();
  1178. //-------------------------------------------------------//
  1179. // Make add and remove map double click event listeners: //
  1180. //-------------------------------------------------------//
  1181. function addDoubleClickListener()
  1182. {
  1183. if(mapDoubleClickListener != null)
  1184. {
  1185. log("addDoubleClickListener: mapDoubleClickListener was not null on mapId: " + mapId);
  1186. mapDoubleClickListener = null;
  1187. }
  1188. try
  1189. {
  1190. mapDoubleClickListener = google.maps.event.addListener( map,
  1191. 'dblclick',
  1192. function(event)
  1193. {
  1194. mapDoubleClick(event.latLng);
  1195. event.stop();
  1196. });
  1197. }
  1198. catch(err)
  1199. {
  1200. log("addDoubleClickListener: " + err);
  1201. }
  1202. }
  1203. function removeDoubleClickListener()
  1204. {
  1205. if(mapDoubleClickListener!=null)
  1206. {
  1207. try
  1208. {
  1209. google.maps.event.removeListener(mapDoubleClickListener);
  1210. }
  1211. catch(err)
  1212. {
  1213. log("removeDoubleClickListener: " + err);
  1214. }
  1215. mapDoubleClickListener = null;
  1216. }
  1217. else
  1218. {
  1219. log("removeDoubleClickListener: mapDoubleClickListener was already null on mapId: " + mapId);
  1220. }
  1221. }
  1222. //------------------------------------------//
  1223. // Create handlers for map double click: //
  1224. //------------------------------------------//
  1225. // mapDoubleClick:
  1226. function mapDoubleClick(latLng)
  1227. {
  1228. log("mapDoubleClick: " + latLng);
  1229. log("calling flash routine: " + "googleMapsDoubleClick_" + mapId);
  1230. swfObject["floidMapDoubleClick_" + mapId](latLng.lat(), latLng.lng());
  1231. }
  1232. //********************************//
  1233. //********************************//
  1234. // Calls from Flash to the map: //
  1235. //********************************//
  1236. //********************************//
  1237. ////////////////////////////////////////////////
  1238. // Function creators for flash calls to map: //
  1239. ////////////////////////////////////////////////
  1240. // -------------------------------
  1241. // floidGoogleMapsCreateNewMarker:
  1242. // -------------------------------
  1243. function makeFloidGoogleMapsCreateNewMarkerFunction()
  1244. {
  1245. return function(lat, lng, markerId)
  1246. {
  1247. log("floidGoogleMapsCreateNewMarker: " + lat + " " + lng + " " + markerId);
  1248. createNewMarker(new google.maps.LatLng(lat, lng, true), markerId);
  1249. }
  1250. }
  1251. // -----------------------------
  1252. // floidGoogleMapsCreateNewLine:
  1253. // -----------------------------
  1254. function makeFloidGoogleMapsCreateNewLineFunction()
  1255. {
  1256. return function(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  1257. {
  1258. log("floidGoogleMapsCreateNewLine: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + a + " " + r + " " + g + " " + b);
  1259. createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w);
  1260. }
  1261. }
  1262. // --------------------------------------
  1263. // floidGoogleMapsAddDoubleClickListener:
  1264. // --------------------------------------
  1265. function makeFloidGoogleMapsAddDoubleClickListenerFunction()
  1266. {
  1267. return function(mapId)
  1268. {
  1269. log("floidGoogleMapsAddDoubleClickListener: " + mapId);
  1270. addDoubleClickListener();
  1271. }
  1272. }
  1273. // -----------------------------------------
  1274. // floidGoogleMapsRemoveDoubleClickListener:
  1275. // -----------------------------------------
  1276. function makeFloidGoogleMapsRemoveDoubleClickListenerFunction()
  1277. {
  1278. return function(mapId)
  1279. {
  1280. log("floidGoogleMapsRemoveDoubleClickListener: " + mapId);
  1281. removeDoubleClickListener();
  1282. }
  1283. }
  1284. // ----------------------------------
  1285. // floidGoogleMapsGetPathMaxElevation:
  1286. // ----------------------------------
  1287. function makeFloidGoogleMapsGetPathMaxElevationFunction()
  1288. {
  1289. return function(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters)
  1290. {
  1291. log("floidGoogleMapsGetPathMaxElevation: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + maxMarkers + " " + requestedPathDistanceInMeters + " " + errorElevation + " " + warningElevation + " " + actualMarkers + " " + actualPathDistanceInMeters);
  1292. getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters);
  1293. }
  1294. }
  1295. //////////////////////////////////////////////////////////////////////////////
  1296. // Make a set of function creation routines for the flash calls to the DOM: //
  1297. //////////////////////////////////////////////////////////////////////////////
  1298. // -------------------------------
  1299. // floidGoogleMapsCreateNewMarker:
  1300. // -------------------------------
  1301. var floidGoogleMapsCreateNewMarkerFunctionName = "floidMapCreateNewMarker_" + mapId;
  1302. this.parent[floidGoogleMapsCreateNewMarkerFunctionName] = makeFloidGoogleMapsCreateNewMarkerFunction();
  1303. // -----------------------------
  1304. // floidGoogleMapsCreateNewLine:
  1305. // -----------------------------
  1306. var floidGoogleMapsCreateNewLineFunctionName = "floidMapCreateNewLine_" + mapId;
  1307. this.parent[floidGoogleMapsCreateNewLineFunctionName] = makeFloidGoogleMapsCreateNewLineFunction();
  1308. // --------------------------------------
  1309. // floidGoogleMapsAddDoubleClickListener:
  1310. // --------------------------------------
  1311. var floidGoogleMapsAddDoubleClickListenerFunctionName = "floidMapAddDoubleClickListener_" + mapId;
  1312. this.parent[floidGoogleMapsAddDoubleClickListenerFunctionName] = makeFloidGoogleMapsAddDoubleClickListenerFunction();
  1313. // -----------------------------------------
  1314. // floidGoogleMapsRemoveDoubleClickListener:
  1315. // -----------------------------------------
  1316. var floidGoogleMapsRemoveDoubleClickListenerFunctionName = "floidMapRemoveDoubleClickListener_" + mapId;
  1317. this.parent[floidGoogleMapsRemoveDoubleClickListenerFunctionName] = makeFloidGoogleMapsRemoveDoubleClickListenerFunction();
  1318. // --------------------------------
  1319. // floidGoogleMapsGetPathMaxElevation:
  1320. // --------------------------------
  1321. var floidGoogleMapsGetPathMaxElevationFunctionName = "floidMapGetPathMaxElevation_" + mapId;
  1322. this.parent[floidGoogleMapsGetPathMaxElevationFunctionName] = makeFloidGoogleMapsGetPathMaxElevationFunction();
  1323. /////////////////////////////
  1324. // Map routines: //
  1325. /////////////////////////////
  1326. // ----- MARKERS -----
  1327. // ----------------
  1328. // createNewMarker:
  1329. // ----------------
  1330. function createNewMarker(latLng, markerId)
  1331. {
  1332. log("Making new marker [" + mapId + "] ("+latLng.lat + ", " + latLng.lng + ")");
  1333. var marker = new google.maps.Marker({
  1334. position: latLng,
  1335. map: map,
  1336. radius: 12,
  1337. hasShadow: true,
  1338. clickable: true,
  1339. draggable: true,
  1340. gravity: 0.5,
  1341. distanceScaling: false
  1342. });
  1343. ////////////////////////////////////////////////
  1344. // Marker listeners that call back to flash: //
  1345. ////////////////////////////////////////////////
  1346. // ------------------------------------------------------
  1347. // OK, here we want to add the listeners for this marker:
  1348. // ------------------------------------------------------
  1349. google.maps.event.addListener( marker,
  1350. 'dblclick',
  1351. function()
  1352. {
  1353. swfObject["floidMapMarkerDoubleClick_" + mapId+"_"+markerId](markerId);
  1354. });
  1355. google.maps.event.addListener( marker,
  1356. 'dragstart',
  1357. function(event)
  1358. {
  1359. swfObject["floidMapMarkerDragStart_" + mapId+"_"+markerId](markerId, event.latLng.lat(), event.latLng.lng());
  1360. });
  1361. google.maps.event.addListener( marker,
  1362. 'dragend',
  1363. function(event)
  1364. {
  1365. swfObject["floidMapMarkerDragEnd_" + mapId+"_"+markerId](markerId, event.latLng.lat(), event.latLng.lng());
  1366. });
  1367. google.maps.event.addListener( marker,
  1368. 'drag',
  1369. function(event)
  1370. {
  1371. swfObject["floidMapMarkerDrag_" + mapId+"_"+markerId](markerId, event.latLng.lat(), event.latLng.lng());
  1372. });
  1373. //***********************************//
  1374. //***********************************//
  1375. // Calls from Flash to the marker: //
  1376. //***********************************//
  1377. //***********************************//
  1378. ///////////////////////////////////////////////////
  1379. // Function creators for flash calls to marker: //
  1380. ///////////////////////////////////////////////////
  1381. // -----------------------------------------------------
  1382. // floidGoogleMapsMarkerSetClickable: [function creator]
  1383. // -----------------------------------------------------
  1384. function makeFloidGoogleMapsMarkerSetClickableFunction(marker, markerId)
  1385. {
  1386. return function(clickable)
  1387. {
  1388. log("floidGoogleMapsMarkerSettingClickable: " + markerId + " to " + clickable);
  1389. marker.setClickable(clickable);
  1390. }
  1391. }
  1392. // -----------------------------------------------------
  1393. // floidGoogleMapsMarkerSetDraggable: [function creator]
  1394. // -----------------------------------------------------
  1395. function makeFloidGoogleMapsMarkerSetDraggableFunction(marker, markerId)
  1396. {
  1397. return function(draggable)
  1398. {
  1399. log("floidGoogleMapsMarkerSettingDraggable: " + markerId + " to " + draggable);
  1400. marker.setDraggable(draggable);
  1401. }
  1402. }
  1403. // -----------------------------------------------------
  1404. // floidGoogleMapsMarkerSetIconString: [function creator]
  1405. // -----------------------------------------------------
  1406. function makeFloidGoogleMapsMarkerSetIconStringFunction(marker, markerId)
  1407. {
  1408. return function(iconString)
  1409. {
  1410. log("floidGoogleMapsMarkerSetIconString: " + markerId);
  1411. log("marker icon string: " + iconString);
  1412.  
  1413. var markerIcon = {url: 'data:image/png;base64,'+iconString,
  1414. size: new google.maps.Size(100, 38),
  1415. origin: new google.maps.Point(0, 0),
  1416. anchor: new google.maps.Point(0, 38)};
  1417.  
  1418.  
  1419. log("floidGoogleMapsMarkerSetIconString: " + markerId + " - markerIconMade");
  1420. marker.setIcon(markerIcon);
  1421. log("floidGoogleMapsMarkerSetIconString: " + markerId + " - markerIconSet");
  1422. }
  1423. }
  1424. // ------------------------------------------------------------
  1425. // floidGoogleMapsMarkerSetIconShadowString: [function creator]
  1426. // ------------------------------------------------------------
  1427. function makeFloidGoogleMapsMarkerSetIconShadowStringFunction(marker, markerId)
  1428. {
  1429. return function(iconShadowString)
  1430. {
  1431. log("floidGoogleMapsMarkerSetIconShadowString: " + markerId);
  1432. log("marker shadow string: " + iconShadowString);
  1433.  
  1434. var markerIconShadow = {url: 'data:image/png;base64,'+iconShadowString,
  1435. size: new google.maps.Size(132, 20),
  1436. origin: new google.maps.Point(0, 0),
  1437. anchor: new google.maps.Point(0, 16)};
  1438. log("floidGoogleMapsMarkerSetIconString: " + markerId + " - markerIconShadowMade");
  1439. marker.setShadow(markerIconShadow);
  1440. log("floidGoogleMapsMarkerSetIconString: " + markerId + " - markerIconShadowSet");
  1441. }
  1442. }
  1443. // ---------------------------------------------------------
  1444. // floidGoogleMapsMarkerRequestElevation: [function creator]
  1445. // ---------------------------------------------------------
  1446. function makeFloidGoogleMapsMarkerRequestElevationFunction(marker, markerId)
  1447. {
  1448. return function(markerId, lat, lng)
  1449. {
  1450. log("floidGoogleMapsMarkerRequestElevation: " + markerId + " - Requesting Elevation for: " + lat + " " + lng);
  1451. // Locations parameter:
  1452. var latLng = new google.maps.LatLng(lat, lng);
  1453. var locations = [];
  1454. locations.push(latLng);
  1455. // Create a LocationElevationRequest object using the array's one value
  1456. var positionalRequest = {
  1457. 'locations': locations
  1458. };
  1459. // Initiate the location request
  1460. elevator.getElevationForLocations(positionalRequest,
  1461. function(results, status)
  1462. {
  1463. log("got elevation result");
  1464. if (status == google.maps.ElevationStatus.OK)
  1465. {
  1466. log("got ok elevation result");
  1467. // Retrieve the first result
  1468. if (results[0])
  1469. {
  1470. log("results[0] was good: " + results[0].elevation);
  1471. // call back into flash :)
  1472. swfObject["floidMapMarkerElevationResult_" + mapId+"_"+markerId](markerId, results[0].elevation);
  1473. }
  1474. else
  1475. {
  1476. log("No results found");
  1477. }
  1478. }
  1479. else
  1480. {
  1481. log("Elevation service failed due to: " + status);
  1482. }
  1483. });
  1484. log("floidGoogleMapsMarkerRequestElevation: " + markerId + " - Elevation Requested");
  1485. }
  1486. }
  1487. // -----------------------------------------------
  1488. // floidGoogleMapsRemoveMarker: [function creator]
  1489. // -----------------------------------------------
  1490. function makeFloidGoogleMapsRemoveMarkerFunction(marker, markerId)
  1491. {
  1492. return function()
  1493. {
  1494. log("Removing marker.");
  1495. log("floidGoogleMapsRemoveMarker: " + mapId + " " + markerId);
  1496. try
  1497. {
  1498. // Remove the marker:
  1499. marker.setMap(null);
  1500. marker = null;
  1501. // Remove the globally bound functions:
  1502. delete this.parent[floidGoogleMapsMarkerSetClickableFunctionName];
  1503. delete this.parent[floidGoogleMapsMarkerSetDraggableFunctionName];
  1504. delete this.parent[floidGoogleMapsMarkerRequestElevationFunctionName];
  1505. delete this.parent[floidGoogleMapsMarkerSetIconStringFunctionName];
  1506. delete this.parent[floidGoogleMapsMarkerSetIconShadowStringFunctionName];
  1507. // Don't forget me!
  1508. delete this.parent[floidGoogleMapsRemoveMarkerFunctionName];
  1509. }
  1510. catch(err)
  1511. {
  1512. log("floidGoogleMapsRemoveMarker: error " + err);
  1513. log("floidGoogleMapsRemoveMarker: error " + mapId + " " + markerId + " " + err);
  1514. }
  1515. log("Done removing marker.");
  1516. }
  1517. }
  1518. ///////////////////////////////////////////////////////
  1519. // Add the flash calls for this marker to the DOM: //
  1520. ///////////////////////////////////////////////////////
  1521. // -----------------------------------------------------
  1522. // floidGoogleMapsMarkerSetClickable:
  1523. // -----------------------------------------------------
  1524. var floidGoogleMapsMarkerSetClickableFunctionName = "floidMapMarkerSetClickable_" + mapId + "_" + markerId;
  1525. this.parent[floidGoogleMapsMarkerSetClickableFunctionName] = makeFloidGoogleMapsMarkerSetClickableFunction(marker, markerId);
  1526. // -----------------------------------------------------
  1527. // floidGoogleMapsMarkerSetDraggable:
  1528. // -----------------------------------------------------
  1529. var floidGoogleMapsMarkerSetDraggableFunctionName = "floidMapMarkerSetDraggable_" + mapId + "_" + markerId;
  1530. this.parent[floidGoogleMapsMarkerSetDraggableFunctionName] = makeFloidGoogleMapsMarkerSetDraggableFunction(marker, markerId);
  1531. // -----------------------------------------------------
  1532. // floidGoogleMapsMarkerRequestElevation:
  1533. // -----------------------------------------------------
  1534. var floidGoogleMapsMarkerRequestElevationFunctionName = "floidMapMarkerRequestElevation_" + mapId + "_" + markerId;
  1535. this.parent[floidGoogleMapsMarkerRequestElevationFunctionName] = makeFloidGoogleMapsMarkerRequestElevationFunction(marker, markerId);
  1536. // -----------------------------------------------------
  1537. // floidGoogleMapsMarkerSetIconString:
  1538. // -----------------------------------------------------
  1539. var floidGoogleMapsMarkerSetIconStringFunctionName = "floidMapMarkerSetIconString_" + mapId + "_" + markerId;
  1540. this.parent[floidGoogleMapsMarkerSetIconStringFunctionName] = makeFloidGoogleMapsMarkerSetIconStringFunction(marker, markerId);
  1541. // -----------------------------------------------------
  1542. // floidGoogleMapsMarkerSetIconShadowString:
  1543. // -----------------------------------------------------
  1544. var floidGoogleMapsMarkerSetIconShadowStringFunctionName = "floidMapMarkerSetIconShadowString_" + mapId + "_" + markerId;
  1545. this.parent[floidGoogleMapsMarkerSetIconShadowStringFunctionName] = makeFloidGoogleMapsMarkerSetIconShadowStringFunction(marker, markerId);
  1546. // ----------------------------
  1547. // floidGoogleMapsRemoveMarker:
  1548. // ----------------------------
  1549. var floidGoogleMapsRemoveMarkerFunctionName = "floidMapRemoveMarker_" + mapId + "_" + markerId;
  1550. this.parent[floidGoogleMapsRemoveMarkerFunctionName] = makeFloidGoogleMapsRemoveMarkerFunction(marker, markerId);
  1551. }
  1552. // ----- LINES -----
  1553. // --------------
  1554. // createNewLine:
  1555. // --------------
  1556. function createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  1557. {
  1558. var lineCoordinates = [
  1559. new google.maps.LatLng(startLat, startLng),
  1560. new google.maps.LatLng(endLat, endLng)
  1561. ];
  1562. var strokeOpacity = a / 255.0;
  1563. var strokeColor = rgbToHex(r, g, b);
  1564. var line = new google.maps.Polyline( {
  1565. path: lineCoordinates,
  1566. strokeOpacity: strokeOpacity,
  1567. strokeColor: strokeColor,
  1568. clickable: false,
  1569. editable: false,
  1570. geodesic: true,
  1571. map: map
  1572. }
  1573. );
  1574. //////////////////////////////////////////////
  1575. // Line listeners that call back to flash: //
  1576. //////////////////////////////////////////////
  1577. // ----------------------------------------------------
  1578. // OK, here we want to add the listeners for this line:
  1579. // ----------------------------------------------------
  1580. // Default is no listeners for this line:
  1581.  
  1582. //***********************************//
  1583. //***********************************//
  1584. // Calls from Flash to the line: //
  1585. //***********************************//
  1586. //***********************************//
  1587. /////////////////////////////////////////////////
  1588. // Function creators for flash calls to line: //
  1589. /////////////////////////////////////////////////
  1590. // -----------------------------------------------
  1591. // floidGoogleMapsRemoveLine: [function creator]
  1592. // -----------------------------------------------
  1593. function makeFloidGoogleMapsRemoveLineFunction(line, lineId)
  1594. {
  1595. return function()
  1596. {
  1597. log("Removing line.");
  1598. try
  1599. {
  1600. // Remove the line:
  1601. line.setMap(null);
  1602. // Remove the globally bound functions:
  1603. // - empty
  1604. // Don't forget me!
  1605. delete this.parent[floidGoogleMapsRemoveLineFunctionName];
  1606. }
  1607. catch(err)
  1608. {
  1609. log("floidGoogleMapsRemoveMarker: error " + err);
  1610. }
  1611. log("Done removing line.");
  1612. }
  1613. }
  1614. // -----------------------------------------------
  1615. // floidGoogleMapsSetLineColor: [function creator]
  1616. // -----------------------------------------------
  1617. function makeFloidGoogleMapsSetLineColorFunction(line, lineId)
  1618. {
  1619. return function(a, r, g, b, w)
  1620. {
  1621. var newOpacity = a/255.0;
  1622. var newColor = rgbToHex(r, g, b);
  1623. log("Changing line color to: " + newColor);
  1624. try
  1625. {
  1626. line.setOptions({strokeColor: newColor, strokeOpacity: newOpacity, strokeWeight: w});
  1627. }
  1628. catch(err)
  1629. {
  1630. log("floidGoogleMapsSetLineColor: error " + err);
  1631. }
  1632. log("Done setting line color.");
  1633. }
  1634. }
  1635. // -------------------------------------------
  1636. // floidGoogleMapsMoveLine: [function creator]
  1637. // -------------------------------------------
  1638. function makeFloidGoogleMapsMoveLineFunction(line, lineId)
  1639. {
  1640. return function(startLat, startLng, endLat, endLng)
  1641. {
  1642. log("Moving line [" + lineId + "] to: " + startLat + " " + startLng + " -> " + endLat + " " + endLng);
  1643. try
  1644. {
  1645. var lineCoordinates = [
  1646. new google.maps.LatLng(startLat, startLng),
  1647. new google.maps.LatLng(endLat, endLng)
  1648. ];
  1649. line.setPath(lineCoordinates);
  1650. }
  1651. catch(err)
  1652. {
  1653. log("floidGoogleMapsMoveLine: error " + err);
  1654. }
  1655. log("Done moving line.");
  1656. }
  1657. }
  1658. /////////////////////////////////////////////////////
  1659. // Add the flash calls for this line to the DOM: //
  1660. /////////////////////////////////////////////////////
  1661. // -----------------------------------------------------
  1662. // floidGoogleMapsRemoveLineFunction:
  1663. // -----------------------------------------------------
  1664. var floidGoogleMapsRemoveLineFunctionName = "floidMapRemoveLine_" + mapId + "_" + lineId;
  1665. this.parent[floidGoogleMapsRemoveLineFunctionName] = makeFloidGoogleMapsRemoveLineFunction(line, lineId);
  1666. // -----------------------------------------------------
  1667. // floidGoogleMapsSetLineColorFunction:
  1668. // -----------------------------------------------------
  1669. var floidGoogleMapsSetLineColorFunctionName = "floidMapSetLineColor_" + mapId + "_" + lineId;
  1670. this.parent[floidGoogleMapsSetLineColorFunctionName] = makeFloidGoogleMapsSetLineColorFunction(line, lineId);
  1671. // -----------------------------------------------------
  1672. // floidGoogleMapsMoveLineFunction:
  1673. // -----------------------------------------------------
  1674. var floidGoogleMapsMoveLineFunctionName = "floidMapMoveLine__" + mapId + "_" + lineId;
  1675. this.parent[floidGoogleMapsMoveLineFunctionName] = makeFloidGoogleMapsMoveLineFunction(line, lineId);
  1676. }
  1677. // ------ Paths -------
  1678. // --------------------
  1679. // getPathMaxElevation:
  1680. // --------------------
  1681. function getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, actualSamples, actualPathDistanceInMeters)
  1682. {
  1683. var sampleLocations = calculateSamples(startLat, startLng, endLat, endLng, actualSamples);
  1684. // OK, make an array of sample points to test:
  1685. var samplePositions = [];
  1686. for(var i=0; i<sampleLocations.length/2; ++i)
  1687. {
  1688. var sampleLatLng = new google.maps.LatLng(sampleLocations[i*2], sampleLocations[i*2+1]);
  1689. samplePositions.push(sampleLatLng);
  1690. }
  1691. // Then make a request to google maps:
  1692. var positionalRequest = {
  1693. 'locations': samplePositions
  1694. };
  1695. // Send the location request:
  1696. elevator.getElevationForLocations(positionalRequest,
  1697. function(results, status)
  1698. {
  1699. // Note this is in meters:
  1700. log("got path max elevation results");
  1701. var maxElevation = -100000; // Min value
  1702. var errorFlag = true;
  1703. if (status == google.maps.ElevationStatus.OK)
  1704. {
  1705. log("got ok path max elevation results");
  1706. // Retrieve the first result
  1707. if (results[0])
  1708. {
  1709. log("getPathMaxElevation results[0] was good: " + results[0].elevation);
  1710. maxElevation = results[0].elevation;
  1711. for(var e=0; e<results.length; ++e)
  1712. {
  1713. log("elevation: " + results[e].elevation);
  1714. if(results[e].elevation>maxElevation)
  1715. {
  1716. maxElevation = results[e].elevation
  1717. }
  1718. }
  1719. errorFlag = false;
  1720. }
  1721. else
  1722. {
  1723. log("getPathMaxElevation: No results found");
  1724. }
  1725. }
  1726. else
  1727. {
  1728. log("getPathMaxElevation: Service failed due to: " + status);
  1729. }
  1730. // call back into flash :)
  1731. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  1732. });
  1733. log("getMaxPathElevation: " + lineId + " - Elevation Requested");
  1734. }
  1735. // OK, the map is fully initialized - call back into flash:
  1736. swfObject["floidMapInitialized_" + mapId]();
  1737. }
  1738. function finalize()
  1739. {
  1740. // Remove global map functions - TODO: remove remaining marker & line functions
  1741. try
  1742. {
  1743. delete this.parent[floidGoogleMapsCreateNewMarkerFunctionName];
  1744. delete this.parent[floidGoogleMapsCreateNewLineFunctionName];
  1745. delete this.parent[floidGoogleMapsAddDoubleClickListenerFunctionName];
  1746. delete this.parent[floidGoogleMapsRemoveDoubleClickListenerFunctionName];
  1747. delete this.parent[floidGoogleMapsGetPathMaxElevationFunctionName];
  1748. }
  1749. catch(err)
  1750. {
  1751. log("Removing map methods error: " + err);
  1752. }
  1753. if(swfObject != null)
  1754. {
  1755. // call back into flash :)
  1756. swfObject["floidMapFrameUnloaded_" + mapId]();
  1757. }
  1758. }
  1759. </script>
  1760. </head>
  1761. <body onload="initialize()" onunload="finalize()">
  1762. <div id="map_canvas" style="width:100%; height:100%"></div>
  1763. </body>
  1764. </html>
  1765.  
  1766. FloidMapQuestMapFrame.html - MapQuest html component:
  1767.  
  1768. <!DOCTYPE html>
  1769. <html>
  1770. <head>
  1771. <!-- faigelabs - test code for Floid maps - cfaigle - free -->
  1772. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  1773. <style type="text/css">
  1774. html { height: 100% }
  1775. body { height: 100%; margin: 0; padding: 0 }
  1776. #map_canvas { height: 100% }
  1777. </style>
  1778. <script type ="text/javascript"
  1779. src ="FloidMapUtilities.js">
  1780. </script>
  1781. <script type ="text/javascript"
  1782. src ="jquery-1.9.1.min.js">
  1783. </script>
  1784. <script type ="text/javascript"
  1785. src ="http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=YOUR_API_KEY">
  1786. </script>
  1787. <script type="text/javascript">
  1788. ///////////////////////////////////////////
  1789. ///////////////////////////////////////////
  1790. // Main Initialize - Magic starts here: //
  1791. ///////////////////////////////////////////
  1792. ///////////////////////////////////////////
  1793. function initialize()
  1794. {
  1795. // Could not get the listener to remove so we will just keep a flag:
  1796. var doubleClickable = false;
  1797. function mapDoubleClickListener(event)
  1798. {
  1799. if(doubleClickable)
  1800. {
  1801. mapDoubleClick(event.ll);
  1802. }
  1803. };
  1804. //----------------------------------//
  1805. // Create the default map options: //
  1806. //----------------------------------//
  1807. var mapOptions = {
  1808. elt : document.getElementById('map_canvas'),
  1809. zoom : 12,
  1810. latLng : { lat:latStart, lng: lngStart },
  1811. mtype : 'map',
  1812. bestFitMargin : 0,
  1813. zoomOnDoubleClick : false
  1814. };
  1815. //---------------------------------------//
  1816. // Create the map and elevator service: //
  1817. //---------------------------------------//
  1818. var map = new MQA.TileMap(mapOptions);
  1819. MQA.withModule('largezoom',
  1820. 'viewoptions',
  1821. 'mousewheel',
  1822. 'traffictoggle',
  1823. 'viewoptions',
  1824. 'geolocationcontrol',
  1825. 'insetmapcontrol',
  1826. function()
  1827. {
  1828. map.addControl(new MQA.ViewOptions());
  1829. map.addControl(new MQA.LargeZoom(), new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT, new MQA.Size(5,5)));
  1830. map.enableMouseWheelZoom();
  1831. });
  1832. //----------------------------------------------//
  1833. // By default we add the double click listener: //
  1834. //----------------------------------------------//
  1835. // In mapQuest we add it one time and then turn it on:
  1836. MQA.EventManager.addListener(map, 'doubleclick', mapDoubleClickListener);
  1837. addDoubleClickListener();
  1838. //-------------------------------------------------------//
  1839. // Make add and remove map double click event listeners: //
  1840. //-------------------------------------------------------//
  1841. function addDoubleClickListener()
  1842. {
  1843. log("addDoubleClickListener: " + mapId);
  1844. doubleClickable = true;
  1845. }
  1846. function removeDoubleClickListener()
  1847. {
  1848. log("removeDoubleClickListener: " + mapId);
  1849. doubleClickable = false;
  1850. }
  1851. //------------------------------------------//
  1852. // Create handlers for map double click: //
  1853. //------------------------------------------//
  1854. // mapDoubleClick:
  1855. function mapDoubleClick(latLng)
  1856. {
  1857. log("mapDoubleClick: " + latLng);
  1858. log("calling flash routine: " + "floidMapDoubleClick_" + mapId);
  1859. swfObject["floidMapDoubleClick_" + mapId](latLng.lat, latLng.lng);
  1860. }
  1861. //********************************//
  1862. //********************************//
  1863. // Calls from Flash to the map: //
  1864. //********************************//
  1865. //********************************//
  1866. ////////////////////////////////////////////////
  1867. // Function creators for flash calls to map: //
  1868. ////////////////////////////////////////////////
  1869. // ---------------------------------
  1870. // floidMapQuestMapsCreateNewMarker:
  1871. // ---------------------------------
  1872. function makeFloidMapQuestMapsCreateNewMarkerFunction()
  1873. {
  1874. return function(lat, lng, markerId)
  1875. {
  1876. log("floidMapQuestMapsCreateNewMarker: " + lat + " " + lng + " " + markerId);
  1877. createNewMarker(lat, lng, markerId);
  1878. }
  1879. }
  1880. // -------------------------------
  1881. // floidMapQuestMapsCreateNewLine:
  1882. // -------------------------------
  1883. function makeFloidMapQuestMapsCreateNewLineFunction()
  1884. {
  1885. return function(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  1886. {
  1887. log("floidMapQuestMapsCreateNewLine: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + a + " " + r + " " + g + " " + b);
  1888. createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w);
  1889. }
  1890. }
  1891. // ----------------------------------------
  1892. // floidMapQuestMapsAddDoubleClickListener:
  1893. // ----------------------------------------
  1894. function makeFloidMapQuestMapsAddDoubleClickListenerFunction()
  1895. {
  1896. return function(mapId)
  1897. {
  1898. log("floidMapQuestMapsAddDoubleClickListener: " + mapId);
  1899. addDoubleClickListener();
  1900. }
  1901. }
  1902. // -------------------------------------------
  1903. // floidMapQuestMapsRemoveDoubleClickListener:
  1904. // -------------------------------------------
  1905. function makeFloidMapQuestMapsRemoveDoubleClickListenerFunction()
  1906. {
  1907. return function(mapId)
  1908. {
  1909. log("floidMapQuestMapsRemoveDoubleClickListener: " + mapId);
  1910. removeDoubleClickListener();
  1911. }
  1912. }
  1913. // ----------------------------------
  1914. // floidMapQuestMapsGetPathMaxElevation:
  1915. // ----------------------------------
  1916. function makeFloidMapQuestMapsGetPathMaxElevationFunction()
  1917. {
  1918. return function(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters)
  1919. {
  1920. log("floidMapQuestMapsGetPathMaxElevation: " + startLat + " " + startLng + " " + endLat + " " + endLng + " " + maxMarkers + " " + requestedPathDistanceInMeters + " " + errorElevation + " " + warningElevation + " " + actualMarkers + " " + actualPathDistanceInMeters);
  1921. getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxMarkers, requestedPathDistanceInMeters, errorElevation, warningElevation, actualMarkers, actualPathDistanceInMeters);
  1922. }
  1923. }
  1924. //////////////////////////////////////////////////////////////////////////////
  1925. // Make a set of function creation routines for the flash calls to the DOM: //
  1926. //////////////////////////////////////////////////////////////////////////////
  1927. // ----------------------------------
  1928. // floidMapQuestMapsCreateNewMarker:
  1929. // ----------------------------------
  1930. var floidMapQuestMapsCreateNewMarkerFunctionName = "floidMapCreateNewMarker_" + mapId;
  1931. this.parent[floidMapQuestMapsCreateNewMarkerFunctionName] = makeFloidMapQuestMapsCreateNewMarkerFunction();
  1932. // --------------------------------
  1933. // floidMapQuestMapsCreateNewLine:
  1934. // --------------------------------
  1935. var floidMapQuestMapsCreateNewLineFunctionName = "floidMapCreateNewLine_" + mapId;
  1936. this.parent[floidMapQuestMapsCreateNewLineFunctionName] = makeFloidMapQuestMapsCreateNewLineFunction();
  1937. // -----------------------------------------
  1938. // floidMapQuestMapsAddDoubleClickListener:
  1939. // -----------------------------------------
  1940. var floidMapQuestMapsAddDoubleClickListenerFunctionName = "floidMapAddDoubleClickListener_" + mapId;
  1941. this.parent[floidMapQuestMapsAddDoubleClickListenerFunctionName] = makeFloidMapQuestMapsAddDoubleClickListenerFunction();
  1942. // --------------------------------------------
  1943. // floidMapQuestMapsRemoveDoubleClickListener:
  1944. // --------------------------------------------
  1945. var floidMapQuestMapsRemoveDoubleClickListenerFunctionName = "floidMapRemoveDoubleClickListener_" + mapId;
  1946. this.parent[floidMapQuestMapsRemoveDoubleClickListenerFunctionName] = makeFloidMapQuestMapsRemoveDoubleClickListenerFunction();
  1947. // --------------------------------
  1948. // floidMapQuestMapsGetPathMaxElevation:
  1949. // --------------------------------
  1950. var floidMapQuestMapsGetPathMaxElevationFunctionName = "floidMapGetPathMaxElevation_" + mapId;
  1951. this.parent[floidMapQuestMapsGetPathMaxElevationFunctionName] = makeFloidMapQuestMapsGetPathMaxElevationFunction();
  1952. /////////////////////////////
  1953. // Map routines: //
  1954. /////////////////////////////
  1955. // We have to store the marker listeners & clickable state:
  1956. var markerDoubleClickListener = null;
  1957. var markerDragStartListener = null;
  1958. var markerDragEndListener = null;
  1959. var markerDragListener = null;
  1960. var clickable = true;
  1961. // ----- MARKERS -----
  1962. // ----------------
  1963. // createNewMarker:
  1964. // ----------------
  1965. function createNewMarker(lat, lng, markerId)
  1966. {
  1967. var marker = new MQA.Poi({lat: lat, lng: lng});
  1968. log("Making new marker [" + mapId + "] ("+lat + ", " + lng + ")");
  1969. marker.draggable = true;
  1970. map.addShape(marker);
  1971. ////////////////////////////////////////////////
  1972. // Marker listeners that call back to flash: //
  1973. ////////////////////////////////////////////////
  1974. // ------------------------------------------------------
  1975. // OK, here we want to add the listeners for this marker:
  1976. // ------------------------------------------------------
  1977. markerDoubleClickListener = function()
  1978. {
  1979. if(clickable)
  1980. {
  1981. swfObject["floidMapMarkerDoubleClick_" + mapId+"_"+markerId](markerId);
  1982. }
  1983. };
  1984. MQA.EventManager.addListener(marker, 'dblclick', markerDoubleClickListener); // NOTE: dblclick v doubleclick - THIS IS DIFFERENT BETWEEN MAPS AND POI'S
  1985.  
  1986. markerDragStartListener = function(event)
  1987. {
  1988. swfObject["floidMapMarkerDragStart_" + mapId+"_"+markerId](markerId, event.srcObject.latLng.lat, event.srcObject.latLng.lng);
  1989. };
  1990. MQA.EventManager.addListener(marker, 'dragstart', markerDragStartListener);
  1991. markerDragEndListener = function(event)
  1992. {
  1993. swfObject["floidMapMarkerDragEnd_" + mapId+"_"+markerId](markerId, event.srcObject.latLng.lat, event.srcObject.latLng.lng);
  1994. };
  1995. MQA.EventManager.addListener(marker, 'dragend', markerDragEndListener);
  1996. markerDragListener = function(event)
  1997. {
  1998. swfObject["floidMapMarkerDrag_" + mapId+"_"+markerId](markerId, event.srcObject.latLng.lat, event.srcObject.latLng.lng);
  1999. };
  2000. MQA.EventManager.addListener(marker, 'drag', markerDragListener);
  2001. //***********************************//
  2002. //***********************************//
  2003. // Calls from Flash to the marker: //
  2004. //***********************************//
  2005. //***********************************//
  2006. ///////////////////////////////////////////////////
  2007. // Function creators for flash calls to marker: //
  2008. ///////////////////////////////////////////////////
  2009. // -------------------------------------------------------
  2010. // floidMapQuestMapsMarkerSetClickable: [function creator]
  2011. // -------------------------------------------------------
  2012. function makeFloidMapQuestMapsMarkerSetClickableFunction(marker, markerId)
  2013. {
  2014. return function(isClickable)
  2015. {
  2016. clickable = isClickable;
  2017. }
  2018. }
  2019. // -------------------------------------------------------
  2020. // floidMapQuestMapsMarkerSetDraggable: [function creator]
  2021. // -------------------------------------------------------
  2022. function makeFloidMapQuestMapsMarkerSetDraggableFunction(marker, markerId)
  2023. {
  2024. return function(draggable)
  2025. {
  2026. marker.setDraggable(draggable);
  2027. }
  2028. }
  2029. // --------------------------------------------------------
  2030. // floidMapQuestMapsMarkerSetIconString: [function creator]
  2031. // --------------------------------------------------------
  2032. function makeFloidMapQuestMapsMarkerSetIconStringFunction(marker, markerId)
  2033. {
  2034. return function(iconString)
  2035. {
  2036. log("floidMapQuestMapsMarkerSetIconString: " + markerId);
  2037. log("marker icon string: " + iconString);
  2038. marker.setIcon(new MQA.Icon('data:image/png;base64,'+iconString, 100, 38));
  2039. marker.setIconOffset(new MQA.Point(0,-38));
  2040. log("floidMapQuestMapsMarkerSetIconString: " + markerId + " - markerIconSet");
  2041. }
  2042. }
  2043. // --------------------------------------------------------------
  2044. // floidMapQuestMapsMarkerSetIconShadowString: [function creator]
  2045. // --------------------------------------------------------------
  2046. function makeFloidMapQuestMapsMarkerSetIconShadowStringFunction(marker, markerId)
  2047. {
  2048. return function(iconShadowString)
  2049. {
  2050. log("floidMapQuestMapsMarkerSetIconShadowString: " + markerId);
  2051. log("marker shadow string: " + iconShadowString);
  2052. log("floidMapQuestMapsMarkerSetIconString: " + markerId);
  2053. log("marker icon shadow string: " + iconShadowString);
  2054. marker.setShadow(new MQA.Icon('data:image/png;base64,'+iconShadowString, 132, 20));
  2055. log("floidMapQuestMapsMarkerSetIconString: " + markerId + " - markerIconSet");
  2056. marker.setShadowOffset(new MQA.Point(0,-20));
  2057. log("floidMapQuestMapsMarkerSetIconString: " + markerId + " - markerIconShadowSet");
  2058. }
  2059. }
  2060. // -----------------------------------------------------------
  2061. // floidMapQuestMapsMarkerRequestElevation: [function creator]
  2062. // -----------------------------------------------------------
  2063. function makeFloidMapQuestMapsMarkerRequestElevationFunction(marker, markerId)
  2064. {
  2065. return function(markerId, lat, lng)
  2066. {
  2067. // Build the url string:
  2068. // OK, make an array of sample points to test, but with only one point:
  2069. var sampleLocations = [lat, lng];
  2070. // Make elevation request object:
  2071. var elevationRequestObject = {
  2072. 'unit' : 'm',
  2073. 'latLngCollection': sampleLocations
  2074. };
  2075. // Convert to JSON:
  2076. var elevationRequestJSONString = JSON.stringify(elevationRequestObject);
  2077. log("Elevation JSON String: " + elevationRequestJSONString);
  2078. var mapQuestElevationUrl = "http://open.mapquestapi.com/elevation/v1/profile?outFormat=json&json="+elevationRequestJSONString+"&callback=?";
  2079. $.ajax({
  2080. url: mapQuestElevationUrl,
  2081. dataType: 'json',
  2082. type: 'GET',
  2083. contentType:'json',
  2084. crossDomain:true,
  2085. success: function(data) {
  2086. log( data );
  2087. if(data.elevationProfile.length >0)
  2088. {
  2089. var elevation = data.elevationProfile[0].height;
  2090. errorFlag = false;
  2091. log("Elevation of point: " + elevation);
  2092. // call back into flash :)
  2093. swfObject["floidMapMarkerElevationResult_" + mapId+"_"+markerId](markerId, elevation);
  2094. log("elevation callback done:");
  2095. }
  2096. },
  2097. error: function(data) {
  2098. log( 'error occurred - ' + data );
  2099. }
  2100. });
  2101. log("floidMapQuestMapsMarkerRequestElevation: " + markerId + " - Elevation Requested");
  2102. }
  2103. }
  2104. // -------------------------------------------------
  2105. // floidMapQuestMapsRemoveMarker: [function creator]
  2106. // -------------------------------------------------
  2107. function makeFloidMapQuestMapsRemoveMarkerFunction(marker, markerId)
  2108. {
  2109. return function()
  2110. {
  2111. log("Removing marker.");
  2112. try
  2113. {
  2114. // Remove the marker:
  2115. map.removeShape(marker);
  2116. marker = null;
  2117. // Remove the globally bound functions:
  2118. delete this.parent[floidMapQuestMapsMarkerSetClickableFunctionName];
  2119. delete this.parent[floidMapQuestMapsMarkerSetDraggableFunctionName];
  2120. delete this.parent[floidMapQuestMapsMarkerRequestElevationFunctionName];
  2121. delete this.parent[floidMapQuestMapsMarkerSetIconStringFunctionName];
  2122. delete this.parent[floidMapQuestMapsMarkerSetIconShadowStringFunctionName];
  2123. // Don't forget me!
  2124. delete this.parent[floidMapQuestMapsRemoveMarkerFunctionName];
  2125. }
  2126. catch(err)
  2127. {
  2128. log("floidMapQuestMapsRemoveMarker: error " + err);
  2129. }
  2130. log("Done removing marker.");
  2131. }
  2132. }
  2133. ///////////////////////////////////////////////////////
  2134. // Add the flash calls for this marker to the DOM: //
  2135. ///////////////////////////////////////////////////////
  2136. // -----------------------------------------------------
  2137. // floidMapQuestMapsMarkerSetClickable:
  2138. // -----------------------------------------------------
  2139. var floidMapQuestMapsMarkerSetClickableFunctionName = "floidMapMarkerSetClickable_" + mapId + "_" + markerId;
  2140. this.parent[floidMapQuestMapsMarkerSetClickableFunctionName] = makeFloidMapQuestMapsMarkerSetClickableFunction(marker, markerId);
  2141. // -----------------------------------------------------
  2142. // floidMapQuestMapsMarkerSetDraggable:
  2143. // -----------------------------------------------------
  2144. var floidMapQuestMapsMarkerSetDraggableFunctionName = "floidMapMarkerSetDraggable_" + mapId + "_" + markerId;
  2145. this.parent[floidMapQuestMapsMarkerSetDraggableFunctionName] = makeFloidMapQuestMapsMarkerSetDraggableFunction(marker, markerId);
  2146. // -----------------------------------------------------
  2147. // floidMapQuestMapsMarkerRequestElevation:
  2148. // -----------------------------------------------------
  2149. var floidMapQuestMapsMarkerRequestElevationFunctionName = "floidMapMarkerRequestElevation_" + mapId + "_" + markerId;
  2150. this.parent[floidMapQuestMapsMarkerRequestElevationFunctionName] = makeFloidMapQuestMapsMarkerRequestElevationFunction(marker, markerId);
  2151. // -----------------------------------------------------
  2152. // floidMapQuestMapsMarkerSetIconString:
  2153. // -----------------------------------------------------
  2154. var floidMapQuestMapsMarkerSetIconStringFunctionName = "floidMapMarkerSetIconString_" + mapId + "_" + markerId;
  2155. this.parent[floidMapQuestMapsMarkerSetIconStringFunctionName] = makeFloidMapQuestMapsMarkerSetIconStringFunction(marker, markerId);
  2156. // -----------------------------------------------------
  2157. // floidMapQuestMapsMarkerSetIconShadowString:
  2158. // -----------------------------------------------------
  2159. var floidMapQuestMapsMarkerSetIconShadowStringFunctionName = "floidMapMarkerSetIconShadowString_" + mapId + "_" + markerId;
  2160. this.parent[floidMapQuestMapsMarkerSetIconShadowStringFunctionName] = makeFloidMapQuestMapsMarkerSetIconShadowStringFunction(marker, markerId);
  2161. // ------------------------------
  2162. // floidMapQuestMapsRemoveMarker:
  2163. // ------------------------------
  2164. var floidMapQuestMapsRemoveMarkerFunctionName = "floidMapRemoveMarker_" + mapId + "_" + markerId;
  2165. this.parent[floidMapQuestMapsRemoveMarkerFunctionName] = makeFloidMapQuestMapsRemoveMarkerFunction(marker, markerId);
  2166. }
  2167. // ----- LINES -----
  2168. // -----------------
  2169. // createNewLine:
  2170. // -----------------
  2171. function createNewLine(lineId, startLat, startLng, endLat, endLng, a, r, g, b, w)
  2172. {
  2173. var newColorAlpha = a/255.0;
  2174. var newColor = rgbToHex(r, g, b);
  2175. var line = new MQA.LineOverlay();
  2176. line.setShapePoints([startLat, startLng, endLat, endLng]);
  2177. line.updateProperties( {color: newColor, colorAlpha: newColorAlpha, borderWidth: w});
  2178. map.addShape(line);
  2179. //////////////////////////////////////////////
  2180. // Line listeners that call back to flash: //
  2181. //////////////////////////////////////////////
  2182. // ----------------------------------------------------
  2183. // OK, here we want to add the listeners for this line:
  2184. // ----------------------------------------------------
  2185. // Default is no listeners for this line:
  2186. //***********************************//
  2187. //***********************************//
  2188. // Calls from Flash to the line: //
  2189. //***********************************//
  2190. //***********************************//
  2191. /////////////////////////////////////////////////
  2192. // Function creators for flash calls to line: //
  2193. /////////////////////////////////////////////////
  2194. // -----------------------------------------------
  2195. // floidMapQuestMapsRemoveLine: [function creator]
  2196. // -----------------------------------------------
  2197. function makeFloidMapQuestMapsRemoveLineFunction(line, lineId)
  2198. {
  2199. return function()
  2200. {
  2201. log("Removing line.");
  2202. try
  2203. {
  2204. // Remove the line:
  2205. map.removeShape(line);
  2206. // Remove the globally bound functions:
  2207. // - empty
  2208. // Don't forget me!
  2209. delete this.parent[floidMapQuestMapsRemoveLineFunctionName];
  2210. }
  2211. catch(err)
  2212. {
  2213. log("floidMapQuestMapsRemoveMarker: error " + err);
  2214. }
  2215. log("Done removing line.");
  2216. }
  2217. }
  2218. // -----------------------------------------------
  2219. // floidMapQuestMapsSetLineColor: [function creator]
  2220. // -----------------------------------------------
  2221. function makeFloidMapQuestMapsSetLineColorFunction(line, lineId)
  2222. {
  2223. return function(a, r, g, b, w)
  2224. {
  2225. var newColorAlpha = a/255.0;
  2226. var newColor = rgbToHex(r, g, b);
  2227. log("Changing line color: " + newColor);
  2228. try
  2229. {
  2230. line.updateProperties( {color: newColor, colorAlpha: newColorAlpha, borderWidth: w});
  2231. }
  2232. catch(err)
  2233. {
  2234. log("floidMapQuestMapsSetLineColor: error " + err);
  2235. }
  2236. log("Done setting line color.");
  2237. }
  2238. }
  2239. // ---------------------------------------------
  2240. // floidMapQuestMapsMoveLine: [function creator]
  2241. // ---------------------------------------------
  2242. function makeFloidMapQuestMapsMoveLineFunction(line, lineId)
  2243. {
  2244. return function(startLat, startLng, endLat, endLng)
  2245. {
  2246. log("Moving line [" + lineId + "] to: " + startLat + " " + startLng + " -> " + endLat + " " + endLng);
  2247. try
  2248. {
  2249. line.setShapePoints([startLat, startLng, endLat, endLng]);
  2250. }
  2251. catch(err)
  2252. {
  2253. log("floidMapQuestMapsMoveLine: error " + err);
  2254. }
  2255. log("Done moving line.");
  2256. }
  2257. }
  2258. /////////////////////////////////////////////////////
  2259. // Add the flash calls for this line to the DOM: //
  2260. /////////////////////////////////////////////////////
  2261. // -----------------------------------------------------
  2262. // floidMapQuestMapsRemoveLineFunction:
  2263. // -----------------------------------------------------
  2264. var floidMapQuestMapsRemoveLineFunctionName = "floidMapRemoveLine_" + mapId + "_" + lineId;
  2265. this.parent[floidMapQuestMapsRemoveLineFunctionName] = makeFloidMapQuestMapsRemoveLineFunction(line, lineId);
  2266. // -----------------------------------------------------
  2267. // floidMapQuestMapsSetLineColorFunction:
  2268. // -----------------------------------------------------
  2269. var floidMapQuestMapsSetLineColorFunctionName = "floidMapSetLineColor_" + mapId + "_" + lineId;
  2270. this.parent[floidMapQuestMapsSetLineColorFunctionName] = makeFloidMapQuestMapsSetLineColorFunction(line, lineId);
  2271. // -----------------------------------------------------
  2272. // floidMapQuestMapsMoveLineFunction:
  2273. // -----------------------------------------------------
  2274. var floidMapQuestMapsMoveLineFunctionName = "floidMapMoveLine__" + mapId + "_" + lineId;
  2275. this.parent[floidMapQuestMapsMoveLineFunctionName] = makeFloidMapQuestMapsMoveLineFunction(line, lineId);
  2276. }
  2277. // ------ Paths -------
  2278. // --------------------
  2279. // getPathMaxElevation:
  2280. // --------------------
  2281. function getPathMaxElevation(lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, actualSamples, actualPathDistanceInMeters)
  2282. {
  2283. var sampleLocations = calculateSamples(startLat, startLng, endLat, endLng, actualSamples);
  2284. // OK, make an array of sample points to test:
  2285. var samplePositions = [];
  2286. for(var i=0; i<sampleLocations.length/2; ++i)
  2287. {
  2288. samplePositions.push(sampleLocations[i*2], sampleLocations[i*2+1]);
  2289. }
  2290. // Make elevation request object:
  2291. var elevationRequestObject = {
  2292. 'unit' : 'm',
  2293. 'latLngCollection': samplePositions
  2294. };
  2295. // Convert to JSON:
  2296. var elevationRequestJSONString = JSON.stringify(elevationRequestObject);
  2297. log("Elevation JSON String: " + elevationRequestJSONString);
  2298. var mapQuestElevationUrl = "http://open.mapquestapi.com/elevation/v1/profile?outFormat=json&json="+elevationRequestJSONString+"&callback=?";
  2299. $.ajax({
  2300. url: mapQuestElevationUrl,
  2301. dataType: 'json',
  2302. type: 'GET',
  2303. contentType:'json',
  2304. crossDomain:true,
  2305. success: function(data) {
  2306. var errorFlag = true;
  2307. var maxElevation = -100000;
  2308. log( data );
  2309. try
  2310. {
  2311. if(data.elevationProfile.length >0)
  2312. {
  2313. maxElevation = data.elevationProfile[0].height;
  2314. errorFlag = false;
  2315. for(var i=0; i<data.elevationProfile.length; ++i)
  2316. {
  2317. var sampleElevation = data.elevationProfile[i].height;
  2318. if(sampleElevation > maxElevation) maxElevation = sampleElevation;
  2319. }
  2320. log("Max elevation of path: " + maxElevation);
  2321. // call back into flash :)
  2322. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  2323. log("elevation callback done:");
  2324. }
  2325. else
  2326. {
  2327. // call back into flash :)
  2328. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  2329. }
  2330. }
  2331. catch(err)
  2332. {
  2333. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  2334. }
  2335. },
  2336. error: function(data) {
  2337. log( 'getMaxPathElevation: error occurred - ' + data );
  2338. var errorFlag = true;
  2339. var maxElevation = -100000;
  2340. // call back into flash :)
  2341. swfObject["floidMapPathMaxElevationCallBack_" + mapId](lineId, startLat, startLng, endLat, endLng, maxSamples, requestedPathDistanceInMeters, errorElevation, warningElevation, maxElevation, actualSamples, actualPathDistanceInMeters, errorFlag);
  2342. }
  2343. });
  2344. log("getPathMaxElevation: " + lineId + " sent");
  2345. }
  2346. // OK, the map is fully initialized - call back into flash:
  2347. swfObject["floidMapInitialized_" + mapId]();
  2348. }
  2349. function finalize()
  2350. {
  2351. // Remove global map functions - TODO: remove remaining marker & line functions
  2352. try
  2353. {
  2354. delete this.parent[floidMapQuestMapsCreateNewMarkerFunctionName];
  2355. delete this.parent[floidMapQuestMapsCreateNewLineFunctionName];
  2356. delete this.parent[floidMapQuestMapsAddDoubleClickListenerFunctionName];
  2357. delete this.parent[floidMapQuestMapsRemoveDoubleClickListenerFunctionName];
  2358. delete this.parent[floidMapQuestMapsGetPathMaxElevationFunctionName];
  2359. }
  2360. catch(err)
  2361. {
  2362. log("Removing map methods error: " + err);
  2363. }
  2364. if(swfObject != null)
  2365. {
  2366. // call back into flash :)
  2367. swfObject["floidMapFrameUnloaded_" + mapId]();
  2368. }
  2369. }
  2370. </script>
  2371. </head>
  2372. <body onload="initialize()" onunload="finalize()">
  2373. <!-- Note that with height and width 100% below, the MapQuest map was not inset right -->
  2374. <div id="map_canvas" style="width:400px; height:400px;"></div>
  2375. </body>
  2376. </html>
  2377.  
  2378.  
  2379. FloidMapUtilities.js - Shared JavaScript utilities
  2380.  
  2381. // FloidMapUtilities.js
  2382. // faigelabs - test code for Floid maps - cfaigle - free
  2383. //------------------------//
  2384. // Parameters from URL: //
  2385. //------------------------//
  2386. var params = {};
  2387. var mapId = 0;
  2388. var latStart = 0;
  2389. var lngStart = 0;
  2390. //--------------------------------//
  2391. // Console log utility function: //
  2392. //--------------------------------//
  2393. function log(message)
  2394. {
  2395. if(typeof console == "object")
  2396. {
  2397. console.log(message);
  2398. }
  2399. }
  2400. //--------------------------------//
  2401. // Storage for the flash object: //
  2402. //--------------------------------//
  2403. var swfObject = null;
  2404. //-------------------------//
  2405. // Parse the parameters: //
  2406. //-------------------------//
  2407. var prmstr = window.location.search.substr(1);
  2408. var prmarr = prmstr.split ("&");
  2409. for ( var i = 0; i < prmarr.length; i++)
  2410. {
  2411. var tmparr = prmarr[i].split("=");
  2412. params[tmparr[0]] = tmparr[1];
  2413. }
  2414. //-------------------------//
  2415. // Get the map id: //
  2416. //-------------------------//
  2417. if(params['mapId'] != null)
  2418. {
  2419. try
  2420. {
  2421. mapId=Number(params['mapId']);
  2422. }
  2423. catch(err)
  2424. {
  2425. mapId = 0;
  2426. }
  2427. }
  2428. //-------------------------//
  2429. // Get the lat start: //
  2430. //-------------------------//
  2431. if(params['latStart'] != null)
  2432. {
  2433. try
  2434. {
  2435. latStart=Number(params['latStart']);
  2436. }
  2437. catch(err)
  2438. {
  2439. latStart = 0;
  2440. }
  2441. }
  2442. //-------------------------//
  2443. // Get the lng start: //
  2444. //-------------------------//
  2445. if(params['lngStart'] != null)
  2446. {
  2447. try
  2448. {
  2449. lngStart=Number(params['lngStart']);
  2450. }
  2451. catch(err)
  2452. {
  2453. lngStart = 0;
  2454. }
  2455. }
  2456. //-------------------------//
  2457. // Get the flash object: //
  2458. //-------------------------//
  2459. log("obj name: " + params['obj']);
  2460. swfObject = parent.document.getElementById(params['obj']);
  2461. //---------------------//
  2462. // Utility routines: //
  2463. //---------------------//
  2464. // Sample position calculation:
  2465. function calculateSamples(startLat, startLng, endLat, endLng, actualSamples)
  2466. {
  2467. // OK, make an array of sample points to test:
  2468. var sampleLocations = [];
  2469. for(var i=0; i<actualSamples; ++i)
  2470. {
  2471. var factor = i / (actualSamples-1); // Note - again we are including both start and end points...
  2472. log('factor: ' + factor);
  2473. var sampleLat = startLat + (endLat-startLat) * factor;
  2474. var sampleLng = startLng + (endLng-startLng) * factor;
  2475. log('Sample: ' + sampleLat + " " + sampleLng);
  2476. sampleLocations.push(sampleLat, sampleLng);
  2477. }
  2478. return sampleLocations;
  2479. }
  2480. // From: http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
  2481. function componentToHex(c)
  2482. {
  2483. var hex = c.toString(16);
  2484. return hex.length == 1 ? "0" + hex : hex;
  2485. }
  2486. function rgbToHex(r, g, b)
  2487. {
  2488. return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
  2489. }
  2490. function argbToHex(a, r, g, b)
  2491. {
  2492. return "#" + componentToHex(a) + componentToHex(r) + componentToHex(g) + componentToHex(b);
  2493. }
  2494. function rgbaToHex(r, g, b, a)
  2495. {
  2496. return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b) + componentToHex(a);
  2497. }
  2498.  
  2499.  
  2500. FloidPinAlt.as - Dynamic marker code:
  2501.  
  2502. package com.faiglelabs.floid.testcode
  2503. {
  2504. // faigelabs - test code for Floid maps - cfaigle - free
  2505. import flash.display.BitmapData;
  2506. import flash.display.Shape;
  2507. import flash.filters.BitmapFilterQuality;
  2508. import flash.filters.GlowFilter;
  2509. import flash.geom.ColorTransform;
  2510. import flash.geom.Matrix;
  2511. import flash.text.TextField;
  2512. import flash.text.TextFormat;
  2513. import flash.utils.ByteArray;
  2514. import mx.graphics.codec.PNGEncoder;
  2515. import com.foxarc.util.Base64;
  2516. public class FloidPinAlt
  2517. {
  2518. public var pinName : String = "No Name";
  2519. public function makeIcon():String
  2520. {
  2521. var iconShape : Shape = makeIconShape();
  2522. var finalBitmapData : BitmapData = new BitmapData(100, 38, true, 0x0);
  2523. var offsetMatrix : Matrix = new Matrix();
  2524. offsetMatrix.ty = 0;
  2525. offsetMatrix.tx = 0;
  2526. finalBitmapData.draw(iconShape, offsetMatrix);
  2527. var finalBitmapPNG : ByteArray = (new PNGEncoder()).encode(finalBitmapData);
  2528. var encodedMarkerBitmap:String = Base64.encode(finalBitmapPNG);
  2529. return encodedMarkerBitmap;
  2530. }
  2531. public function makeIconShadow():String
  2532. {
  2533. var iconShape : Shape = makeIconShape();
  2534. var finalBitmapData : BitmapData = new BitmapData(132, 20, true, 0x0);
  2535. var offsetMatrix : Matrix = new Matrix();
  2536. offsetMatrix.ty = 0;
  2537. offsetMatrix.tx = 20;
  2538. offsetMatrix.c = -1;
  2539. offsetMatrix.d = 0.5;
  2540. var colorTransform : ColorTransform = new ColorTransform();
  2541. colorTransform.alphaOffset = -160;
  2542. colorTransform.redMultiplier = 0.9;
  2543. colorTransform.greenMultiplier = 0.9;
  2544. colorTransform.blueMultiplier = 0.9;
  2545. colorTransform.redOffset = 0x10;
  2546. colorTransform.greenOffset = 0x10;
  2547. colorTransform.blueOffset = 0x10;
  2548. finalBitmapData.draw(iconShape, offsetMatrix, colorTransform);
  2549. var finalBitmapPNG : ByteArray = (new PNGEncoder()).encode(finalBitmapData);
  2550. var encodedMarkerBitmap:String = Base64.encode(finalBitmapPNG);
  2551. return encodedMarkerBitmap;
  2552. }
  2553. public function makeIconShape():Shape
  2554. {
  2555. var standardBackgroundColor:uint = 0xFF999999; // Gray
  2556. var standardLineColor:uint = 0xFF000000; // Black
  2557. var iconTextWidth:int = 120;
  2558. var iconTextHeight:int = 20;
  2559. var iconBarLocation:int = 18;
  2560. var iconBarHeight:int = 6;
  2561. var iconBarWidth:int = 100;
  2562. var iconPointerStartX:int = 14;
  2563. var iconPointerEndX:int = 18;
  2564. var iconPointerHeight:int = 32;
  2565. var iconLineBackgroundColor:int = 0xFF000000;
  2566. var iconLineStyleThickness:int = 2;
  2567. var iconBackgroundColor:uint = standardBackgroundColor;
  2568. var lineColor:uint = standardLineColor;
  2569. // Create a shape:
  2570. var iconShape:Shape = new Shape();
  2571. // NEXT: Draw the line to the bottom left:
  2572. iconShape.graphics.beginFill(iconBackgroundColor);
  2573. iconShape.graphics.lineStyle(iconLineStyleThickness, lineColor);
  2574. iconShape.graphics.moveTo(iconPointerStartX, iconBarLocation);
  2575. iconShape.graphics.lineTo(0, iconBarHeight + iconPointerHeight);
  2576. iconShape.graphics.lineTo(iconPointerEndX, iconBarLocation);
  2577. iconShape.graphics.lineTo(iconPointerStartX, iconBarLocation);
  2578. iconShape.graphics.endFill();
  2579. // NEXT: draw the bar:
  2580. iconShape.graphics.beginFill(iconBackgroundColor);
  2581. iconShape.graphics.lineStyle(iconLineStyleThickness, lineColor);
  2582. iconShape.graphics.drawRoundRect(0, iconBarLocation-(iconBarHeight/2), iconBarWidth, iconBarHeight, 3, 3);
  2583. iconShape.graphics.endFill();
  2584. // Create the text for the pinName:
  2585. var textfield:TextField = new TextField();
  2586. var outline:GlowFilter = new GlowFilter(0x00c0c0c0,1.0,2,2,4);
  2587. outline.quality = BitmapFilterQuality.MEDIUM;
  2588. textfield.filters=[outline];
  2589. textfield.text = pinName;
  2590. textfield.setTextFormat(new TextFormat("Verdana", 12, 0x00000000));
  2591. var bitmapdata:BitmapData = new BitmapData(iconTextWidth, iconTextHeight, true, 0x00000000);
  2592. bitmapdata.draw(textfield);
  2593. // Draw the bitmap onto the shape graphics:
  2594. iconShape.graphics.beginBitmapFill(bitmapdata);
  2595. iconShape.graphics.lineStyle();
  2596. iconShape.graphics.drawRect(0, 0, iconTextWidth, iconTextHeight);
  2597. iconShape.graphics.endFill();
  2598. return iconShape;
  2599. }
  2600. }
  2601. }
Add Comment
Please, Sign In to add comment