Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2526)

Unified Diff: examples/js/maps/geocoder_service.js

Issue 985123002: Move geocoder code to location related path. This CL only moves files, no functional change. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/js/maps/geocoder.mojom ('k') | examples/location/geocoder_demo.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/js/maps/geocoder_service.js
diff --git a/examples/js/maps/geocoder_service.js b/examples/js/maps/geocoder_service.js
deleted file mode 100644
index 351a4606dfa894448880934268352da78256ad85..0000000000000000000000000000000000000000
--- a/examples/js/maps/geocoder_service.js
+++ /dev/null
@@ -1,128 +0,0 @@
-#!mojo mojo:js_content_handler
-
-define("main", [
- "console",
- "examples/js/maps/geocoder.mojom",
- "mojo/public/js/core",
- "mojo/public/js/unicode",
- "mojo/services/public/js/application",
- "mojo/services/network/public/interfaces/network_service.mojom",
- "mojo/services/network/public/interfaces/url_loader.mojom",
- "third_party/js/url",
-], function(console, geocoder, core, unicode, application, network, loader, url) {
-
- const Application = application.Application;
- const Bounds = geocoder.Bounds;
- const Geocoder = geocoder.Geocoder;
- const Geometry = geocoder.Geometry;
- const Location = geocoder.Location;
- const NetworkService = network.NetworkService;
- const Result = geocoder.Result;
- const Status = geocoder.Status;
- const URLRequest = loader.URLRequest;
- const URL = url.URL;
-
- var netService;
-
- Location.prototype.queryString = function() {
- // TBD: format floats to 6 decimal places
- return this.latitude + ", " + this.longitude;
- }
-
- Location.fromJSON = function(json) {
- return !json ? null : new Location({
- latitude: json.lat,
- longitude: json.lng,
- });
- }
-
- Bounds.fromJSON = function(json) {
- return !json ? null : new Bounds({
- northeast: Location.fromJSON(json.northeast),
- southwest: Location.fromJSON(json.southwest),
- });
- }
-
- Geometry.fromJSON = function(json) {
- return !json ? null : new Geometry({
- location: Location.fromJSON(json.location),
- location_type: json.location_type,
- viewport: Bounds.fromJSON(json.viewport),
- bounds: Bounds.fromJSON(json.bounds),
- });
- }
-
- Result.fromJSON = function(json) {
- return !json ? null : new Result({
- partial_match: !!json.partial_match,
- formatted_address: json.formatted_address,
- geometry: Geometry.fromJSON(json.geometry),
- types: json.types,
- // TBD: address_components
- });
- }
-
- function parseGeocodeResponse(arrayBuffer) {
- return JSON.parse(unicode.decodeUtf8String(new Uint8Array(arrayBuffer)));
- }
-
- function geocodeRequest(url) {
- return new Promise(function(resolveRequest) {
- var urlLoader;
- netService.createURLLoader(function(urlLoaderProxy) {
- urlLoader = urlLoaderProxy;
- });
-
- var urlRequest = new URLRequest({
- url: url.format(),
- method: "GET",
- auto_follow_redirects: true
- });
-
- urlLoader.start(urlRequest).then(function(urlLoaderResult) {
- core.drainData(urlLoaderResult.response.body).then(
- function(drainDataResult) {
- // TBD: handle drainData failure
- var value = parseGeocodeResponse(drainDataResult.buffer);
- resolveRequest({
- status: value.status,
- results: value.results.map(Result.fromJSON),
- });
- });
- });
- });
- }
-
- function geocodeURL(key, value, options) {
- var url = new URL("https://maps.googleapis.com/maps/api/geocode/json");
- url.query = {};
- url.query[key] = value;
- // TBD: add options url.query
- return url;
- }
-
- class GeocoderImpl {
- addressToLocation(address, options) {
- return geocodeRequest(geocodeURL("address", address, options));
- }
-
- locationToAddress(location, options) {
- return geocodeRequest(
- geocodeURL("latlng", location.queryString(), options));
- }
- }
-
- class GeocoderService extends Application {
- initialize() {
- netService = this.shell.connectToService(
- "mojo:network_service", NetworkService);
- }
-
- acceptConnection(initiatorURL, serviceProvider) {
- serviceProvider.provideService(Geocoder, GeocoderImpl);
- }
- }
-
- return GeocoderService;
-});
-
« no previous file with comments | « examples/js/maps/geocoder.mojom ('k') | examples/location/geocoder_demo.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698