diff --git a/data/atlas.gresource.xml b/data/atlas.gresource.xml index dd237e3..0feba55 100644 --- a/data/atlas.gresource.xml +++ b/data/atlas.gresource.xml @@ -2,6 +2,5 @@ icons/pointer.svg - icons/location.svg diff --git a/data/icons/location.svg b/data/icons/location.svg deleted file mode 100644 index 949a9a1..0000000 --- a/data/icons/location.svg +++ /dev/null @@ -1,121 +0,0 @@ - - - - - location - - - - - - - - - - - - - - - - - - location - - - Ryo Nakano - - - - - - - - - - - - - diff --git a/src/MapWidget.vala b/src/MapWidget.vala index fa56a23..32d9986 100644 --- a/src/MapWidget.vala +++ b/src/MapWidget.vala @@ -17,9 +17,13 @@ public class Atlas.MapWidget : Gtk.Box { private Shumate.SimpleMap map_widget; private Shumate.Map base_map; + // Displays the "pin" icon at a specified place by search + private Shumate.MarkerLayer pin_layer; + // Displays the position of current location + private Shumate.MarkerLayer location_layer; + private GClue.Location? location = null; - private MarkerLayerManager manager; private bool is_watching_location = false; // The Royal Observatory @@ -40,7 +44,11 @@ public class Atlas.MapWidget : Gtk.Box { } public void init_marker_layers () { - manager = new MarkerLayerManager (map_widget); + pin_layer = new Shumate.MarkerLayer (map_widget.viewport); + map_widget.add_overlay_layer (pin_layer); + + location_layer = new Shumate.MarkerLayer (map_widget.viewport); + map_widget.add_overlay_layer (location_layer); } // Set the initial location of the map widget. @@ -101,8 +109,8 @@ public class Atlas.MapWidget : Gtk.Box { this.location.longitude = lng; } - manager.clear_markers (MarkerType.LOCATION); - manager.new_marker_at_pos (MarkerType.LOCATION, lat, lng); + clear_location (); + mark_location_at (lat, lng); } // Inspired from https://gitlab.gnome.org/GNOME/gnome-clocks/blob/master/src/geocoding.vala @@ -130,8 +138,8 @@ public class Atlas.MapWidget : Gtk.Box { public void go_to_place (Geocode.Place place) { Geocode.Location loc = place.location; - manager.clear_markers (MarkerType.POINTER); - manager.new_marker_at_pos (MarkerType.POINTER, loc.latitude, loc.longitude); + clear_pin (); + mark_pin_at (loc.latitude, loc.longitude); base_map.go_to (loc.latitude, loc.longitude); } @@ -141,4 +149,37 @@ public class Atlas.MapWidget : Gtk.Box { Atlas.Application.settings.set_double ("longitude", base_map.viewport.longitude); Atlas.Application.settings.set_double ("zoom-level", base_map.viewport.zoom_level); } + + private void clear_location () { + location_layer.remove_all (); + } + + private void clear_pin () { + pin_layer.remove_all (); + } + + private void mark_location_at (double latitude, double longitude) { + var marker = new Shumate.Point () { + latitude = latitude, + longitude = longitude, + selectable = true + }; + + location_layer.add_marker (marker); + } + + private void mark_pin_at (double latitude, double longitude) { + var image = new Gtk.Image.from_icon_name ("pointer") { + icon_size = Gtk.IconSize.LARGE + }; + + var marker = new Shumate.Marker () { + latitude = latitude, + longitude = longitude, + child = image, + selectable = true + }; + + pin_layer.add_marker (marker); + } } diff --git a/src/MarkerLayerManager.vala b/src/MarkerLayerManager.vala deleted file mode 100644 index b890e80..0000000 --- a/src/MarkerLayerManager.vala +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2014-2015 Atlas Developers - * 2018-2025 Ryo Nakano - */ - -namespace Atlas { - public enum MarkerType { - POINTER, - LOCATION - } - - public class MarkerLayerManager : Object { - private struct LayerData { - Shumate.MarkerLayer layer; - string icon_name; - } - - private const string POINTER_ICON_NAME = "pointer"; - private const string LOCATION_ICON_NAME = "location"; - - public Shumate.SimpleMap map_widget { private get; construct; } - private LayerData[] layer_data; - - public MarkerLayerManager (Shumate.SimpleMap map_widget) { - Object (map_widget: map_widget); - } - - construct { - var pointer_layer = new Shumate.MarkerLayer (map_widget.viewport); - map_widget.add_overlay_layer (pointer_layer); - LayerData pointer_data = { - pointer_layer, - POINTER_ICON_NAME - }; - layer_data += pointer_data; - - var location_layer = new Shumate.MarkerLayer (map_widget.viewport); - map_widget.add_overlay_layer (location_layer); - LayerData location_data = { - location_layer, - LOCATION_ICON_NAME - }; - layer_data += location_data; - } - - public void new_marker_at_pos (MarkerType type, double latitude, double longitude) { - LayerData data = layer_data[type]; - - var image = new Gtk.Image.from_icon_name (data.icon_name) { - icon_size = Gtk.IconSize.LARGE - }; - var marker = new Shumate.Marker () { - latitude = latitude, - longitude = longitude, - child = image, - selectable = true - }; - data.layer.add_marker (marker); - } - - public void clear_markers (MarkerType type) { - LayerData data = layer_data[type]; - data.layer.remove_all (); - } - } -} diff --git a/src/meson.build b/src/meson.build index b0c12d6..847e7de 100644 --- a/src/meson.build +++ b/src/meson.build @@ -23,7 +23,6 @@ sources = files( 'Define.vala', 'MainWindow.vala', 'MapWidget.vala', - 'MarkerLayerManager.vala', 'Util.vala', )