Codebase list gnome-maps / fdd4d86
mapSource, mapView: Fix handling different attribution logos We previously never had different attribution logos for the map sources. Fix this so that it actually works to update the logo when switching source now that we use different providers for street and aerial. Marcus Lundblad 2 years ago
2 changed file(s) with 44 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
2929 const Service = imports.service;
3030 const Utils = imports.utils;
3131
32 let _attributionImage = null;
32 let _attributionImages = [];
3333
3434 const _FILE_CACHE_SIZE_LIMIT = (10 * 1024 * 1024); /* 10Mb */
3535 const _MEMORY_CACHE_SIZE_LIMIT = 100; /* number of tiles */
4545 _init(view) {
4646 super._init();
4747
48 if (_attributionImage)
49 this.contents = _attributionImage;
50 else
51 return;
52
48 this._view = view;
5349 this._rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL;
54 view.connect('notify::width', () => this._updatePosition(view));
55 view.connect('notify::height', () => this._updatePosition(view));
50 view.connect('notify::width', () => this._updatePosition());
51 view.connect('notify::height', () => this._updatePosition());
5652
5753 this._updatePosition(view);
5854 }
5955
60 _updatePosition(view) {
61 let width = _attributionImage.pixbuf.width;
62 let height = _attributionImage.pixbuf.height;
63 let x = view.width - width - _LOGO_PADDING_X;
64 /* TODO: ideally the attribution logo should be aligned to the left
65 * side in RTL locales, but I couldn't get that working with Clutter
66 * actor positioning, so adjust the padding to fit above the scale
67 * for now
68 */
69 let y = view.height - height -
70 (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y);
56 setSource(source) {
57 this._id = source.get_id();
7158
72 this.set_position(x, y);
59 let bin = this.get_widget();
60
61 if (bin.get_child())
62 bin.remove(bin.get_child());
63
64 if (_attributionImages[source.get_id()]) {
65 bin.add(_attributionImages[source.get_id()]);
66 bin.visible = true;
67 } else {
68 bin.visible = false;
69 }
70
71 this._updatePosition();
72 }
73
74 _updatePosition() {
75 let image = _attributionImages[this._id];
76
77 if (image) {
78 let width = image.pixbuf.width;
79 let height = image.pixbuf.height;
80 let x = this._view.width - width - _LOGO_PADDING_X;
81 /* TODO: ideally the attribution logo should be aligned to the left
82 * side in RTL locales, but I couldn't get that working with Clutter
83 * actor positioning, so adjust the padding to fit above the scale
84 * for now
85 */
86 let y = this._view.height - height -
87 (this._rtl ? _LOGO_PADDING_Y_RTL : _LOGO_PADDING_Y);
88
89 this.set_position(x, y);
90 }
7391 }
7492 });
7593
7795 if (!source.attribution_logo || source.attribution_logo === "")
7896 return;
7997
80 if (!_attributionImage)
81 _attributionImage = new Gtk.Image();
98 if (!_attributionImages[source.id])
99 _attributionImages[source.id] = new Gtk.Image({ visible: true });
82100
83101 let data = GLib.base64_decode(source.attribution_logo);
84102 let stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(data));
85 _attributionImage.pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
103 _attributionImages[source.id].pixbuf =
104 GdkPixbuf.Pixbuf.new_from_stream(stream, null);
86105 }
87106
88107 function _createTileSource(source) {
436436 this.view.add_child(this._attribution);
437437 }
438438
439 this._attribution.setSource(this.view.map_source);
440
439441 Application.settings.set('map-type', mapType);
440442 } else {
441443 let renderer = new Champlain.ImageRenderer();