[gnome-maps] placeEntry: Add support for plain coordinates
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] placeEntry: Add support for plain coordinates
- Date: Sat, 6 Sep 2014 15:58:07 +0000 (UTC)
commit d6f283bb1428559ac2926701ff82e55f3fcafa29
Author: Damián Nohales <damiannohales gmail com>
Date: Mon Sep 1 16:12:11 2014 -0300
placeEntry: Add support for plain coordinates
This adds support for parsing plain coordinates with the format
"<latitude>, <longitude>" in PlaceEntry class. When PlaceEntry
detects a valid plain coordinate (valid format, between valid ranges)
being introduced, it will skip the place search, also, no reverse
search is performed.
Plain coordinates places are internally represented by a GeocodePlace
object whose "name" property is null.
https://bugzilla.gnome.org/show_bug.cgi?id=735842
src/placeEntry.js | 36 ++++++++++++++++++++++++++++++++++--
1 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/placeEntry.js b/src/placeEntry.js
index 806db5f..7cc07cb 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -36,6 +36,9 @@ Geocode.Location.prototype.equals = function(location) {
location.longitude === this.longitude);
};
+// Matches coordinates string with the format "<lat>, <long>"
+const COORDINATES_REGEX = /^\s*(\-?\d+(?:\.\d+)?)\s*,\s*(\-?\d+(?:\.\d+)?)\s*$/;
+
const PlaceEntry = new Lang.Class({
Name: 'PlaceEntry',
Extends: Gtk.SearchEntry,
@@ -55,8 +58,11 @@ const PlaceEntry = new Lang.Class({
return;
if (p) {
- this.text = p.name;
- Application.placeStore.addRecent(p);
+ if (p.name) {
+ this.text = p.name;
+ Application.placeStore.addRecent(p);
+ } else
+ this.text = p.location.latitude + ', ' + p.location.longitude;
} else
this.text = '';
@@ -130,12 +136,38 @@ const PlaceEntry = new Lang.Class({
return popover;
},
+ _validateCoordinates: function(lat, lon) {
+ return lat <= 90 && lat >= -90 && lon <= 180 && lon >= -180;
+ },
+
+ _parseCoordinates: function(text) {
+ let match = text.match(COORDINATES_REGEX);
+
+ if (match) {
+ let latitude = parseFloat(match[1]);
+ let longitude = parseFloat(match[2]);
+
+ if (this._validateCoordinates(latitude, longitude)) {
+ return new Geocode.Location({ latitude: latitude,
+ longitude: longitude });
+ } else
+ return null;
+ } else
+ return null;
+ },
+
_onActivate: function() {
if (this.text.length === 0) {
this.place = null;
return;
}
+ let parsedLocation = this._parseCoordinates(this.text);
+ if (parsedLocation) {
+ this.place = new Geocode.Place({ location: parsedLocation });
+ return;
+ }
+
let bbox = this._mapView.view.get_bounding_box();
this._popover.showSpinner();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]