1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

Maps: Add MapsSettings with multiple tile providers options

This commit is contained in:
Bastiaan van der Plaat 2023-09-16 21:10:23 +02:00 committed by Andrew Kaster
parent 264782557e
commit aed25991e6
14 changed files with 379 additions and 15 deletions

View file

@ -8,13 +8,15 @@
#pragma once
#include <AK/Queue.h>
#include <LibConfig/Listener.h>
#include <LibGUI/Frame.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
#include <LibProtocol/Request.h>
#include <LibProtocol/RequestClient.h>
class MapWidget : public GUI::Frame {
class MapWidget : public GUI::Frame
, public Config::Listener {
C_OBJECT(MapWidget);
public:
@ -26,15 +28,15 @@ public:
};
struct Options {
String tile_layer_url { "https://tile.openstreetmap.org/{}/{}/{}.png"_string };
Optional<String> tile_provider {};
LatLng center;
int zoom;
bool context_menu_enabled { true };
bool scale_enabled { true };
int scale_max_width { 100 };
bool attribution_enabled { true };
String attribution_text { "© OpenStreetMap contributors"_string };
URL attribution_url { "https://www.openstreetmap.org/copyright"sv };
Optional<String> attribution_text {};
Optional<URL> attribution_url {};
};
LatLng center() const { return m_center; }
@ -76,7 +78,7 @@ public:
String text;
Position position;
Optional<URL> url {};
bool persistent { false };
Optional<String> name {};
Gfx::IntRect rect { 0, 0, 0, 0 };
};
void add_panel(Panel const& panel)
@ -84,9 +86,9 @@ public:
m_panels.append(panel);
update();
}
void clear_panels()
void remove_panels_with_name(StringView name)
{
m_panels.remove_all_matching([](auto const& panel) { return !panel.persistent; });
m_panels.remove_all_matching([name](auto const& panel) { return panel.name == name; });
update();
}
@ -117,6 +119,7 @@ protected:
RefPtr<Protocol::RequestClient> request_client() const { return m_request_client; }
private:
virtual void config_string_did_change(StringView domain, StringView group, StringView key, StringView value) override;
virtual void doubleclick_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
@ -154,7 +157,8 @@ private:
Vector<RefPtr<Protocol::Request>, TILES_DOWNLOAD_PARALLEL_MAX> m_active_requests;
Queue<TileKey, 32> m_tile_queue;
RefPtr<Gfx::Bitmap> m_marker_image;
String m_tile_layer_url;
Optional<String> m_tile_provider;
String m_default_tile_provider;
LatLng m_center;
int m_zoom {};
bool m_context_menu_enabled {};