1
/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
2
/* vim: set et ts=4 sw=4: */
4
* Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
6
* GNOME Maps is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; either version 2 of the License, or (at your
9
* option) any later version.
11
* GNOME Maps is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* You should have received a copy of the GNU General Public License along
17
* with GNOME Maps; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
* Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
23
const Clutter = imports.gi.Clutter;
24
const Champlain = imports.gi.Champlain;
25
const Geocode = imports.gi.GeocodeGlib;
27
const Lang = imports.lang;
28
const Mainloop = imports.mainloop;
29
const Signals = imports.signals;
31
const Utils = imports.utils;
32
const Path = imports.path;
33
const _ = imports.gettext.gettext;
35
// A map location object with an added accuracy.
36
const MapLocation = new Lang.Class({
39
_init: function(geocodeLocation, mapView) {
40
this._mapView = mapView;
41
this._view = mapView.view;
42
this.latitude = geocodeLocation.latitude;
43
this.longitude = geocodeLocation.longitude;
44
this.description = geocodeLocation.description;
45
this.accuracy = geocodeLocation.accuracy;
48
// Go to this location from the current location on the map, optionally
50
// TODO: break this out somewhere, this is useful in other cases as well.
51
goTo: function(animate) {
52
Utils.debug("Going to " + this.description);
55
this._view.center_on(this.latitude, this.longitude);
62
/* Lets first ensure that both current and destination location are visible
63
* before we start the animated journey towards destination itself. We do this
64
* to create the zoom-out-then-zoom-in effect that many map implementations
65
* do. This not only makes the go-to animation look a lot better visually but
66
* also give user a good idea of where the destination is compared to current
70
Utils.once(this._view, "animation-completed", (function() {
71
Utils.once(this._view, "animation-completed::go-to", (function() {
76
this._view.go_to(this.latitude, this.longitude);
79
this._mapView.ensureVisible([this._getCurrentLocation(), this]);
82
show: function(layer) {
83
let marker = new Champlain.Label({ text: this.description });
84
marker.set_location(this.latitude, this.longitude);
85
layer.add_marker(marker);
86
Utils.debug("Added marker at " + this.latitude + ", " + this.longitude);
89
showNGoTo: function(animate, layer) {
94
// Zoom to the maximal zoom-level that fits the accuracy circle
95
zoomToFit: function() {
97
if (this.accuracy === Geocode.LOCATION_ACCURACY_UNKNOWN)
98
zoom = 11; // Accuracy is usually city-level when unknown
99
else if (this.accuracy <= Geocode.LOCATION_ACCURACY_STREET)
101
else if (this.accuracy <= Geocode.LOCATION_ACCURACY_CITY)
103
else if (this.accuracy <= Geocode.LOCATION_ACCURACY_REGION)
105
else if (this.accuracy <= Geocode.LOCATION_ACCURACY_COUNTRY)
109
this._view.set_zoom_level(zoom);
112
getAccuracyDescription: function() {
113
switch(this.accuracy) {
114
case Geocode.LOCATION_ACCURACY_UNKNOWN:
115
/* Translators: Accuracy of user location information */
118
/* Translators: Accuracy of user location information */
121
let area = Math.PI * Math.pow(this.accuracy / 1000, 2);
122
area = Math.floor(area);
123
return area.toString() + _(" km²");
127
_getCurrentLocation: function() {
128
return new Geocode.Location({
129
latitude: this._view.get_center_latitude(),
130
longitude: this._view.get_center_longitude()
134
Utils.addSignalMethods(MapLocation.prototype);