Repository: flex-asjs Updated Branches: refs/heads/develop 7dd59490f -> 0b65a29a4
Added functions to set the map zoom level and to use geo-code API to locate an address and display a marker. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/0b65a29a Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/0b65a29a Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/0b65a29a Branch: refs/heads/develop Commit: 0b65a29a4315f3e297bf6291effad0d9d26c8443 Parents: 7dd5949 Author: Peter Ent <[email protected]> Authored: Tue May 20 10:44:28 2014 -0400 Committer: Peter Ent <[email protected]> Committed: Tue May 20 10:44:28 2014 -0400 ---------------------------------------------------------------------- .../src/org/apache/flex/maps/google/Map.as | 34 +++++++++++++++ .../apache/flex/maps/google/beads/MapView.as | 32 +++++++++++++- .../src/org/apache/flex/maps/google/Map.js | 44 ++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0b65a29a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as index 44ca927..ffae3a5 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/Map.as @@ -89,5 +89,39 @@ package org.apache.flex.maps.google viewBead.mapit(centerLat, centerLong, zoom); } } + + /** + * Sets the magnification level on the map with 1 being the lowest level + * (essentially the entire world) and 14 being very zoomed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function setZoom( zoom:Number ) : void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.setZoom(zoom); + } + } + + /** + * Translates the given address into a geo-location, moves the map to + * that location, and places a marker on that location. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function markAddress( address:String ) : void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.geoCodeAndMarkAddress(address); + } + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0b65a29a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as index e7d6eb6..e2a738a 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/maps/google/beads/MapView.as @@ -107,6 +107,20 @@ package org.apache.flex.maps.google.beads } } + public function geoCodeAndMarkAddress(address:String):void + { + if (_loader && page) { + _loader.window.codeaddress(address); + } + } + + public function setZoom(zoom:Number):void + { + if (_loader && page) { + _loader.window.map.setZoom(zoom); + } + } + /** * @private */ @@ -136,14 +150,30 @@ package org.apache.flex.maps.google.beads private static var pageTemplateEnd:String = '&sensor=false">'+ ' </script>'+ ' <script type="text/javascript">'+ + ' var map;'+ + ' var geocoder;'+ ' function mapit(lat, lng, zoomLevel) {'+ ' var mapOptions = {'+ ' center: new google.maps.LatLng(lat, lng),'+ ' zoom: zoomLevel'+ ' };'+ - ' var map = new google.maps.Map(document.getElementById("map-canvas"),'+ + ' map = new google.maps.Map(document.getElementById("map-canvas"),'+ ' mapOptions);'+ ' };'+ + ' function codeaddress(address) {'+ + ' if (!geocoder) geocoder = new google.maps.Geocoder();'+ + ' geocoder.geocode( { "address": address}, function(results, status) {'+ + ' if (status == google.maps.GeocoderStatus.OK) {'+ + ' map.setCenter(results[0].geometry.location);'+ + ' var marker = new google.maps.Marker({'+ + ' map: map,'+ + ' position: results[0].geometry.location,'+ + ' });'+ + ' } else {'+ + ' alert("Geocode was not successful for the following reason: " + status);'+ + ' }'+ + ' });'+ + ' };'+ ' function initialize() {'+ ' mapit(-34.397, 150.644, 8);'+ ' };'+ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0b65a29a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js index 9ac51b6..6e9f60f 100644 --- a/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js +++ b/frameworks/js/FlexJS/src/org/apache/flex/maps/google/Map.js @@ -93,5 +93,49 @@ org.apache.flex.maps.google.Map.prototype.loadMap = mapOptions['center'] = new window['google']['maps']['LatLng'](centerLat, centerLong); mapOptions['zoom'] = zoom; this.map = new window['google']['maps']['Map'](this.element, mapOptions); + this.geocoder = null; + } +}; + + +/** + * @expose + * @param {Number} zoomLevel The level of magnification. + */ +org.apache.flex.maps.google.Map.prototype.setZoom = + function(zoomLevel) { + if (this.initialized) { + this.map.setZoom(zoomLevel); + } +}; + + +/** + * @expose + * @param {string} address The address to locate and mark on the map. + */ +org.apache.flex.maps.google.Map.prototype.markAddress = + function(address) { + if (this.initialized) { + if (!this.geocoder) this.geocoder = new window['google']['maps']['Geocoder'](); + this.geocoder.geocode({ 'address': address}, goog.bind(this.geoCodeHandler, this)); + } +}; + + +/** + * @param {Array} results The found location(s). + * @param {string} status Status of the call. + */ +org.apache.flex.maps.google.Map.prototype.geoCodeHandler = + function(results, status) { + if (status == window['google']['maps']['GeocoderStatus']['OK']) { + this.map['setCenter'](results[0]['geometry']['location']); + var marker = new window['google']['maps']['Marker']({ + map: this.map, + position: results[0]['geometry']['location'] + }); + } else { + alert('Geocode was not successful for the following reason: ' + status); } };
