Commit 6a6a17ec authored by Jonas Danielsson's avatar Jonas Danielsson
Browse files

mapSource: Get tile server information from service.json

Attempt to download a service.json file from gnome.org. The
file will define all information needed to create a libchamplain
source. This will help us to change the tile-server without needing
to update the application.

If the call to gnome.org fails. Fallback to a default service.json.

https://bugzilla.gnome.org/show_bug.cgi?id=769352
parent d8713841
......@@ -11,6 +11,9 @@ org.gnome.Maps.data.gresource: org.gnome.Maps.data.gresource.xml $(app_resource_
--target=$@ \
--sourcedir=$(srcdir) $<
tileservicedir = $(pkgdatadir)
tileservice_DATA = maps-service.json
resourcedir = $(pkgdatadir)
resource_DATA = org.gnome.Maps.data.gresource
......@@ -46,6 +49,7 @@ EXTRA_DIST = \
org.gnome.Maps.appdata.xml.in \
osm-types.json \
$(app_resource_files) \
maps-service.json \
$(NULL)
CLEANFILES = \
......
This diff is collapsed.
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="65" height="20"><defs/><metadata><rdf:RDF><cc:Work rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/><dc:title/></cc:Work></rdf:RDF></metadata><g transform="translate(-261.8483,-98.50395)"><g transform="matrix(0.17441836,0,0,0.17441836,220.52282,29.229342)" style="opacity:0.25;fill:#ffffff;stroke:#000000;stroke-width:17.20002365;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"><path d="M 5.28 1.5 C 4.54 1.56 3.9 2.25 3.91 3 l 0 11.88 c 0.02 0.77 0.72 1.47 1.5 1.47 l 1.75 0 c 0.78 0 1.48 -0.69 1.5 -1.47 l 0 -4.28 0.72 1.19 c 0.53 0.87 2.03 0.87 2.56 0 l 0.72 -1.19 0 4.28 c 0.02 0.76 0.7 1.45 1.47 1.47 l 1.75 0 c 0.78 0 1.48 -0.69 1.5 -1.47 l 0 -0.16 c 1.02 1.12 2.46 1.81 4.09 1.81 l 4.09 0 0 1.47 c -0 0.78 0.69 1.48 1.47 1.5 l 1.75 0 c 0.79 -0 1.5 -0.71 1.5 -1.5 l 0.02 -1.47 c 1.72 0 3.08 -0.64 4.14 -1.69 l 0 0.19 c 0 0.39 0.16 0.79 0.44 1.06 0.28 0.28 0.67 0.44 1.06 0.44 l 3.31 0 c 2.03 0 3.85 -1.06 4.91 -2.69 1.05 1.61 2.84 2.69 4.88 2.69 1.03 0 1.98 -0.27 2.81 -0.75 0.28 0.35 0.73 0.57 1.19 0.56 l 2.12 0 c 0.48 0.01 0.97 -0.23 1.25 -0.62 l 0.91 -1.28 0.91 1.28 c 0.28 0.39 0.74 0.63 1.22 0.62 l 2.16 0 C 62.67 16.33 63.42 14.89 62.81 14 L 60.22 10.38 62.62 7 C 63.26 6.11 62.5 4.62 61.41 4.62 l -2.16 0 C 58.78 4.62 58.31 4.86 58.03 5.25 L 57.31 6.28 56.56 5.25 C 56.29 4.86 55.82 4.62 55.34 4.62 l -2.16 0 c -0.49 -0 -0.97 0.25 -1.25 0.66 -0.86 -0.51 -1.84 -0.81 -2.91 -0.81 -2.03 0 -3.83 1.08 -4.88 2.69 C 43.1 5.53 41.27 4.47 39.19 4.47 L 39.19 3 C 39.19 2.61 39.03 2.21 38.75 1.94 38.47 1.66 38.08 1.5 37.69 1.5 l -1.75 0 c -0.71 0 -1.5 0.83 -1.5 1.5 l 0 3.16 C 33.38 5.1 31.96 4.47 30.38 4.47 l -3.34 0 c -0.77 0.02 -1.47 0.72 -1.47 1.5 l 0 0.31 c -1.02 -1.12 -2.46 -1.81 -4.09 -1.81 -1.63 0 -3.07 0.7 -4.09 1.81 L 17.38 3 c -0 -0.79 -0.71 -1.5 -1.5 -1.5 L 14.5 1.5 C 13.55 1.5 12.28 1.87 11.66 2.94 l -1 1.69 -1 -1.69 C 9.03 1.87 7.77 1.5 6.81 1.5 l -1.41 0 C 5.36 1.5 5.32 1.5 5.28 1.5 z m 16.19 7.72 c 0.53 0 0.94 0.35 0.94 1.28 l 0 1.28 -0.94 0 c -0.52 0 -0.94 -0.38 -0.94 -1.28 -0 -0.9 0.42 -1.28 0.94 -1.28 z m 8.81 0 c 0.83 0 1.18 0.68 1.19 1.28 0.01 0.94 -0.62 1.28 -1.19 1.28 z m 8.72 0 c 0.72 0 1.37 0.6 1.37 1.28 0 0.77 -0.51 1.28 -1.37 1.28 z m 10.03 0 c 0.58 0 1.09 0.5 1.09 1.28 0 0.78 -0.51 1.28 -1.09 1.28 -0.58 0 -1.12 -0.5 -1.12 -1.28 0 -0.78 0.54 -1.28 1.12 -1.28 z" transform="matrix(5.7333414,0,0,5.7333414,236.93308,397.17498)" style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:17.20002365;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans"/></g><g transform="matrix(0.17441836,0,0,0.17441836,220.52282,29.229342)" style="fill:#ffffff"><path d="m 5.41 3 0 12 1.75 0 0 -9.91 3.5 5.94 3.47 -5.94 0 9.91 1.75 0 0 -12 L 14.5 3 C 13.8 3 13.25 3.16 12.94 3.69 L 10.66 7.59 8.38 3.69 C 8.07 3.16 7.51 3 6.81 3 z M 36 3 l 0 12.03 3.25 0 c 2.44 0 4.38 -1.91 4.38 -4.53 0 -2.62 -1.93 -4.47 -4.38 -4.47 C 38.7 6.03 38.32 6 37.75 6 l 0 -3 z M 21.47 5.97 c -2.44 0 -4.19 1.91 -4.19 4.53 0 2.62 1.75 4.53 4.19 4.53 l 4.19 0 0 -4.53 c 0 -2.62 -1.75 -4.53 -4.19 -4.53 z m 27.56 0 c -2.41 0 -4.38 2.03 -4.38 4.53 0 2.5 1.97 4.53 4.38 4.53 2.41 0 4.34 -2.03 4.34 -4.53 0 -2.5 -1.94 -4.53 -4.34 -4.53 z m -22 0.03 0 12 1.75 0 0 -2.97 c 0.57 0 1.04 -0 1.59 0 2.44 0 4.34 -1.91 4.34 -4.53 0 -2.62 -1.9 -4.5 -4.34 -4.5 z m 26.16 0 3.03 4.38 -3.19 4.62 2.12 0 L 57.31 11.91 59.44 15 61.59 15 58.38 10.38 61.41 6 59.25 6 57.31 8.81 55.34 6 z M 21.47 7.72 c 1.4 0 2.44 1.19 2.44 2.78 l 0 2.78 -2.44 0 c -1.4 0 -2.44 -1.21 -2.44 -2.78 -0 -1.57 1.04 -2.78 2.44 -2.78 z m 27.56 0 c 1.44 0 2.59 1.24 2.59 2.78 0 1.54 -1.15 2.78 -2.59 2.78 -1.44 0 -2.62 -1.24 -2.62 -2.78 0 -1.54 1.18 -2.78 2.62 -2.78 z m -20.25 0.03 1.59 0 c 1.59 0 2.59 1.28 2.59 2.75 0 1.47 -1.13 2.78 -2.59 2.78 l -1.59 0 z m 8.97 0 1.5 0 c 1.47 0 2.62 1.28 2.62 2.75 0 1.47 -1.04 2.78 -2.62 2.78 l -1.5 0 z" transform="matrix(5.7333414,0,0,5.7333414,236.93308,397.17498)" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"/></g></g></svg>
\ No newline at end of file
......@@ -3,7 +3,6 @@
<gresource prefix="/org/gnome/Maps">
<file preprocess="xml-stripblanks">ui/account-row.ui</file>
<file preprocess="xml-stripblanks">ui/app-menu.ui</file>
<file preprocess="xml-stripblanks">ui/attribution-logo.ui</file>
<file preprocess="xml-stripblanks">ui/busy-marker.ui</file>
<file preprocess="xml-stripblanks">ui/check-in-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/context-menu.ui</file>
......@@ -38,7 +37,6 @@
<file alias="application.css">gnome-maps.css</file>
<file alias="ui/maptype-aerial.png">media/maptype-aerial.png</file>
<file alias="ui/maptype-street.png">media/maptype-street.png</file>
<file alias="ui/attribution.svg">media/mapbox-attribution-logo.svg</file>
<file alias="osm-types.json" compressed="true">osm-types.json</file>
</gresource>
<gresource prefix="/org/gnome/Maps/gtk">
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.10 -->
<template class="Gjs_AttributionLogo" parent="GtkImage">
<property name="halign">end</property>
<property name="valign">end</property>
<property name="margin_bottom">6</property>
<property name="margin_end">6</property>
<property name="visible">true</property>
<property name="resource">/org/gnome/Maps/ui/attribution.svg</property>
</template>
</interface>
......@@ -18,56 +18,102 @@
*/
const Champlain = imports.gi.Champlain;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Soup = imports.gi.Soup;
const Utils = imports.utils;
/*
* These URIs are used by the libchamplain network tile source.
* The #X#, #Y#, #Z# coords will get replaced with actual tile numbers.
*/
const _AERIAL_URI = "https://gis.gnome.org/tiles/satellite/v1/#Z#/#X#/#Y#";
const _STREET_URI = "https://gis.gnome.org/tiles/street/v1/#Z#/#X#/#Y#";
/* unique names are needed for file caching */
const _AERIAL_NAME = "mapbox-satellite-v1";
const _STREET_NAME = "mapbox-street-v1";
let _tileService = null;
let _attributionImage = null;
const _TILE_SIZE = 256;
const _MIN_ZOOM = 0;
const _MAX_ZOOM = 19;
const _TILE_SERVICE_URL = 'https://gis.gnome.org/services/v1/service.json';
const _DEFAULT_SERVICE_FILE = 'maps-service.json';
const _FILE_CACHE_SIZE_LIMIT = (10 * 1024 * 1024); /* 10Mb */
const _MEMORY_CACHE_SIZE_LIMIT = 100; /* number of tiles */
const AttributionLogo = new Lang.Class({
Name: 'AttributionLogo',
Extends: Gtk.Image,
Template: 'resource:///org/gnome/Maps/ui/attribution-logo.ui',
Extends: Gtk.Bin,
_init: function() {
this.parent();
this.parent({ margin_end: 6,
margin_bottom: 25,
halign: Gtk.Align.END,
valign: Gtk.Align.END });
this.add(_attributionImage);
}
});
function _createTileSource(uri, name) {
return new Champlain.NetworkTileSource(
{ id: name,
name: name,
license: null,
license_uri: null,
min_zoom_level: _MIN_ZOOM,
max_zoom_level: _MAX_ZOOM,
tile_size: _TILE_SIZE,
projection: Champlain.MapProjection.MERCATOR,
renderer: new Champlain.ImageRenderer(),
uri_format: uri
});
function _updateAttributionImage(source) {
if (!_attributionImage)
_attributionImage = new Gtk.Image();
if (!source.attribution_logo || source.attribution_logo === "") {
_attributionImage.visible = false;
return;
}
let data = GLib.base64_decode(source.attribution_logo);
let stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(data));
_attributionImage.pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
}
function _createCachedSource(uri, name) {
let tileSource = _createTileSource(uri, name);
function _createDefaultService() {
let filename = GLib.build_filenamev([pkg.pkgdatadir,
_DEFAULT_SERVICE_FILE]);
let data = Utils.readFile(filename);
_tileService = JSON.parse(data).tiles;
return _tileService;
}
function _getTileService() {
if (_tileService)
return _tileService;
let user_agent = 'gnome-maps/' + pkg.version;
let session = new Soup.Session({ user_agent : user_agent });
let msg = Soup.Message.new('GET', _TILE_SERVICE_URL);
try {
let stream = Gio.DataInputStream.new(session.send(msg, null));
let lines = "";
while(true) {
let [line, _] = stream.read_line_utf8(null);
if (line === null)
break;
lines += line;
}
_tileService = JSON.parse(lines).tiles;
return _tileService;
} catch(e) {
Utils.debug(e);
return _createDefaultService();
}
}
function _createTileSource(source) {
let tileSource = new Champlain.NetworkTileSource({
id: source.id,
name: source.name,
license: source.license,
license_uri: source.license_uri,
min_zoom_level: source.min_zoom_level,
max_zoom_level: source.max_zoom_level,
tile_size: source.tile_size,
renderer: new Champlain.ImageRenderer(),
uri_format: source.uri_format
});
tileSource.max_conns = source.max_connections;
return tileSource;
}
function _createCachedSource(source) {
let tileSource = _createTileSource(source);
_updateAttributionImage(source);
let fileCache = new Champlain.FileCache({
size_limit: _FILE_CACHE_SIZE_LIMIT,
......@@ -98,9 +144,9 @@ function _createCachedSource(uri, name) {
}
function createAerialSource() {
return _createCachedSource(_AERIAL_URI, _AERIAL_NAME);
};
return _createCachedSource(_getTileService().aerial);
}
function createStreetSource() {
return _createCachedSource(_STREET_URI, _STREET_NAME);
};
return _createCachedSource(_getTileService().street);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment