Repository: flex-asjs Updated Branches: refs/heads/develop 9212e7743 -> 0c58c7c9d
Added new functions to the Map class for searching, zooming, and map position. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/0c58c7c9 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/0c58c7c9 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/0c58c7c9 Branch: refs/heads/develop Commit: 0c58c7c9daf58265757f814b610ffece82ff7748 Parents: 9212e77 Author: Peter Ent <p...@apache.org> Authored: Wed May 28 09:32:22 2014 -0400 Committer: Peter Ent <p...@apache.org> Committed: Wed May 28 09:32:22 2014 -0400 ---------------------------------------------------------------------- .../src/org/apache/flex/maps/google/Map.as | 65 ++++++++ .../apache/flex/maps/google/beads/MapView.as | 152 ++++++++++++++++++- .../src/org/apache/flex/maps/google/Map.js | 42 ++++- 3 files changed, 253 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0c58c7c9/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 ffae3a5..b379032 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 @@ -108,6 +108,71 @@ package org.apache.flex.maps.google } /** + * Centers the map on the address given. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function centerOnAddress( address:String ) : void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.centerOnAddress(address); + } + } + + /** + * Marks the current center of the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function markCurrentLocation() : void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.markCurrentLocation(); + } + } + + /** + * Performs a search near the center of map. The result is a set of + * markers displayed on the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function nearbySearch(placeName:String):void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.nearbySearch(placeName); + } + } + + /** + * Clears the search result markers from the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function clearSearchResults():void + { + var viewBead:MapView = getBeadByType(IBeadView) as MapView; + if (viewBead) { + viewBead.clearSearchResults(); + } + } + + /** * Translates the given address into a geo-location, moves the map to * that location, and places a marker on that location. * http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0c58c7c9/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 e2a738a..a78a45a 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,13 +107,89 @@ package org.apache.flex.maps.google.beads } } - public function geoCodeAndMarkAddress(address:String):void + /** + * @private + * This function may be dropped. + */ + private function geoCodeAndMarkAddress(address:String):void { if (_loader && page) { _loader.window.codeaddress(address); } } + /** + * Centers the map on the address given. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function centerOnAddress(address:String):void + { + if (_loader && page) { + //_loader.window.addEventListener("mapCentered",onMapCentered); + _loader.window.map.center_changed = onMapCentered; + _loader.window.centeronaddress(address); + } + } + + /** + * Marks the current center of the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function markCurrentLocation():void + { + if (_loader && page) { + _loader.window.markcurrentlocation(); + } + } + + /** + * Performs a search near the center of map. The result is a set of + * markers displayed on the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function nearbySearch(placeName:String):void + { + if (_loader && page) { + _loader.window.addEventListener("searchResults",onSearchResults); + _loader.window.nearbysearch(placeName); + } + } + + /** + * Clears the search result markers from the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function clearSearchResults():void + { + if (_loader && page) { + _loader.window.clearmarkers(); + } + } + + /** + * Sets the zoom factor of the map. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ public function setZoom(zoom:Number):void { if (_loader && page) { @@ -132,6 +208,22 @@ package org.apache.flex.maps.google.beads /** * @private + */ + private function onMapCentered():void + { + trace("The map has been centered"); + } + + /** + * @private + */ + private function onSearchResults(event:*):void + { + trace("We have results"); + } + + /** + * @private * This page definition is used with HTMLLoader to bring in the Google Maps * API (a Google APP token is required). */ @@ -147,11 +239,15 @@ package org.apache.flex.maps.google.beads ' <script type="text/javascript"'+ ' src="https://maps.googleapis.com/maps/api/js?v=3.exp'; - private static var pageTemplateEnd:String = '&sensor=false">'+ + private static var pageTemplateEnd:String = '&libraries=places&sensor=false">'+ ' </script>'+ ' <script type="text/javascript">'+ ' var map;'+ ' var geocoder;'+ + ' var currentCenter;' + + ' var service;' + + ' var places;' + + ' var markers;'+ ' function mapit(lat, lng, zoomLevel) {'+ ' var mapOptions = {'+ ' center: new google.maps.LatLng(lat, lng),'+ @@ -164,16 +260,64 @@ package org.apache.flex.maps.google.beads ' 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);'+ + ' currentCenter = results[0].geometry.location;'+ + ' map.setCenter(currentCenter);'+ ' var marker = new google.maps.Marker({'+ ' map: map,'+ - ' position: results[0].geometry.location,'+ + ' position: currentCenter,'+ ' });'+ ' } else {'+ ' alert("Geocode was not successful for the following reason: " + status);'+ ' }'+ ' });'+ ' };'+ + ' function centeronaddress(address) {'+ + ' if (!geocoder) geocoder = new google.maps.Geocoder();'+ + ' geocoder.geocode( { "address": address}, function(results, status) {'+ + ' if (status == google.maps.GeocoderStatus.OK) {'+ + ' currentCenter = results[0].geometry.location;'+ + ' map.setCenter(currentCenter);' + + ' } else {'+ + ' alert("Geocode was not successful for the following reason: " + status);'+ + ' }'+ + ' });'+ + ' };'+ + ' function markcurrentlocation() {'+ + ' createMarker(currentCenter);'+ + ' };' + + ' function createMarker(location) {' + + ' var marker = new google.maps.Marker({'+ + ' map: map,'+ + ' position: location,'+ + ' });' + + ' return marker;'+ + ' };' + + ' function clearmarkers() {' + + ' if (markers) {' + + ' for(var i=0; i < markers.length; i++) {' + + ' markers[i].setMap(null);' + + ' }' + + ' markers = null;' + + ' }' + + ' };'+ + ' function nearbysearch(placename) {' + + ' if (markers == null) markers = [];' + + ' service = new google.maps.places.PlacesService(map);'+ + ' service.nearbySearch({"location": currentCenter,' + + ' "radius": 5000,' + + ' "name": placename}, function(results, status) {' + + ' places = results;' + + ' if (status == google.maps.places.PlacesServiceStatus.OK) {' + + ' for(var i=0; i < results.length; i++) {' + + ' var place = results[i];' + + ' markers.push(createMarker(place.geometry.location));' + + ' }' + + ' var event = document.createEvent("Event");'+ + ' event.initEvent("searchResults", true, true);' + + ' window.dispatchEvent(event);' + + ' }' + + ' });'+ + ' };'+ ' function initialize() {'+ ' mapit(-34.397, 150.644, 8);'+ ' };'+ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0c58c7c9/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 6e9f60f..e979422 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 @@ -112,6 +112,27 @@ org.apache.flex.maps.google.Map.prototype.setZoom = /** * @expose + * @param {string} address The new center of the map. + */ +org.apache.flex.maps.google.Map.prototype.centerOnAddress = function(address) { + if (!this.geocoder) this.geocoder = new google.maps.Geocoder(); + this.geocoder.geocode( { "address": address}, goog.bind(this.positionHandler, this)); +}; + + +/** + * @expose + */ +org.apache.flex.maps.google.Map.prototypemarkcurrentlocation = function() { + var marker = new google.maps.Marker({ + map: this.map, + position: this.currentCenter + }); +}; + + +/** + * @expose * @param {string} address The address to locate and mark on the map. */ org.apache.flex.maps.google.Map.prototype.markAddress = @@ -127,13 +148,30 @@ org.apache.flex.maps.google.Map.prototype.markAddress = * @param {Array} results The found location(s). * @param {string} status Status of the call. */ +org.apache.flex.maps.google.Map.prototype.positionHandler = + function(results, status) { + if (status == window['google']['maps']['GeocoderStatus']['OK']) { + this.currentCenter = results[0]['geometry']['location']; + this.map['setCenter'](this.currentCenter); + window.dispatchEvent("mapCentered"); + } else { + alert('Geocode was not successful for the following reason: ' + status); + } +}; + + +/** + * @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']); + this.currentCenter = results[0]['geometry']['location']; + this.map['setCenter'](this.currentCenter); var marker = new window['google']['maps']['Marker']({ map: this.map, - position: results[0]['geometry']['location'] + position: this.currentCenter }); } else { alert('Geocode was not successful for the following reason: ' + status);