]> git.street.me.uk Git - andy/viking.git/blob - src/osm.c
Merge commit 'ToolbarConfig'
[andy/viking.git] / src / osm.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5  * Copyright (C) 2007,2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
6  * Copyright (c) 2012, Rob Norris <rw_norris@hotmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <glib/gi18n.h>
28
29 #include "osm.h"
30 #include "vikmapslayer.h"
31 #include "vikslippymapsource.h"
32 #include "vikwmscmapsource.h"
33 #include "vikwebtoolcenter.h"
34 #include "vikwebtoolbounds.h"
35 #include "vikwebtoolformat.h"
36 #include "vikwebtool_datasource.h"
37 #include "vikexttools.h"
38 #include "vikexttool_datasources.h"
39 #include "vikgotoxmltool.h"
40 #include "vikgoto.h"
41 #include "vikrouting.h"
42 #include "vikroutingwebengine.h"
43
44 /* initialisation */
45 void osm_init () {
46   VikMapSource *mapnik_type =
47     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
48                                 "id", 13,
49                                 "label", "OpenStreetMap (Mapnik)",
50                                 "hostname", "tile.openstreetmap.org",
51                                 "url", "/%d/%d/%d.png",
52                                 "check-file-server-time", FALSE,
53                                 "use-etag", TRUE,
54                                 "copyright", "© OpenStreetMap contributors",
55                                 "license", "CC-BY-SA",
56                                 "license-url", "http://www.openstreetmap.org/copyright",
57                                 NULL));
58   VikMapSource *cycle_type =
59     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
60                                 "id", 17,
61                                 "label", "OpenStreetMap (Cycle)",
62                                 "hostname", "tile.opencyclemap.org",
63                                 "url", "/cycle/%d/%d/%d.png",
64                                 "check-file-server-time", TRUE,
65                                 "use-etag", FALSE,
66                                 "copyright", "Tiles courtesy of Andy Allan © OpenStreetMap contributors",
67                                 "license", "CC-BY-SA",
68                                 "license-url", "http://www.openstreetmap.org/copyright",
69                                 NULL));
70   VikMapSource *transport_type =
71     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
72                                 "id", 20,
73                                 "label", "OpenStreetMap (Transport)",
74                                 "hostname", "tile2.opencyclemap.org",
75                                 "url", "/transport/%d/%d/%d.png",
76                                 "check-file-server-time", TRUE,
77                                 "use-etag", FALSE,
78                                 "copyright", "Tiles courtesy of Andy Allan © OpenStreetMap contributors",
79                                 "license", "CC-BY-SA",
80                                 "license-url", "http://www.openstreetmap.org/copyright",
81                                 NULL));
82   VikMapSource *mapquest_type =
83     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
84                                 "id", 19,
85                                 "label", "OpenStreetMap (MapQuest)",
86                                 "hostname", "otile1.mqcdn.com",
87                                 "url", "/tiles/1.0.0/osm/%d/%d/%d.png",
88                                 "check-file-server-time", TRUE,
89                                 "use-etag", FALSE,
90                                 "copyright", "Tiles Courtesy of MapQuest © OpenStreetMap contributors",
91                                 "license", "MapQuest Specific",
92                                 "license-url", "http://developer.mapquest.com/web/info/terms-of-use",
93                                 NULL));
94   VikMapSource *hot_type =
95     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
96                                 "id", 22,
97                                 "label", "OpenStreetMap (Humanitarian)",
98                                 "hostname", "c.tile.openstreetmap.fr",
99                                 "url", "/hot/%d/%d/%d.png",
100                                 "check-file-server-time", TRUE,
101                                 "use-etag", FALSE,
102                                 "copyright", "© OpenStreetMap contributors. Tiles courtesy of Humanitarian OpenStreetMap Team",
103                                 "license", "CC-BY-SA",
104                                 "license-url", "http://www.openstreetmap.org/copyright",
105                                 NULL));
106
107   // NB no cache needed for this type!!
108   VikMapSource *direct_type =
109     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
110                                 "id", 21,
111                                 "label", _("On Disk OSM Tile Format"),
112                                 // For using your own generated data assumed you know the license already!
113                                 "copyright", "© OpenStreetMap contributors", // probably
114                                 "use-direct-file-access", TRUE,
115                                 NULL));
116
117   // NB no cache needed for this type!!
118   VikMapSource *mbtiles_type =
119     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
120                                 "id", 23,
121                                 "label", _("MBTiles File"),
122                                 // For using your own generated data assumed you know the license already!
123                                 "copyright", "© OpenStreetMap contributors", // probably
124                                 "use-direct-file-access", TRUE,
125                                 "is-mbtiles", TRUE,
126                                 NULL));
127
128   maps_layer_register_map_source (mapquest_type);
129   maps_layer_register_map_source (mapnik_type);
130   maps_layer_register_map_source (cycle_type);
131   maps_layer_register_map_source (transport_type);
132   maps_layer_register_map_source (hot_type);
133   maps_layer_register_map_source (direct_type);
134   maps_layer_register_map_source (mbtiles_type);
135
136   // Webtools
137   VikWebtoolCenter *webtool = NULL;
138   webtool = vik_webtool_center_new_with_members ( _("OSM (view)"), "http://openstreetmap.org/?lat=%s&lon=%s&zoom=%d" );
139   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
140   g_object_unref ( webtool );
141
142   webtool = vik_webtool_center_new_with_members ( _("OSM (edit)"), "http://www.openstreetmap.org/edit?lat=%s&lon=%s&zoom=%d" );
143   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
144   g_object_unref ( webtool );
145
146   webtool = vik_webtool_center_new_with_members ( _("OSM (render)"), "http://www.informationfreeway.org/?lat=%s&lon=%s&zoom=%d&layers=B0000F000F" );
147   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
148   g_object_unref ( webtool );
149
150   VikWebtoolBounds *webtoolbounds = NULL;
151   // Example: http://127.0.0.1:8111/load_and_zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&select=node413602999
152   // JOSM or merkaartor must already be running with remote interface enabled
153   webtoolbounds = vik_webtool_bounds_new_with_members ( _("Local port 8111 (eg JOSM)"), "http://localhost:8111/load_and_zoom?left=%s&right=%s&bottom=%s&top=%s" );
154   vik_ext_tools_register ( VIK_EXT_TOOL ( webtoolbounds ) );
155   g_object_unref ( webtoolbounds );
156
157   VikWebtoolFormat *vwtf = NULL;
158   vwtf = vik_webtool_format_new_with_members ( _("Geofabrik Map Compare"),
159                                                "http://tools.geofabrik.de/mc/#%s/%s/%s",
160                                                "ZAO" );
161   vik_ext_tools_register ( VIK_EXT_TOOL ( vwtf ) );
162   g_object_unref ( vwtf );
163
164   // Datasource
165   VikWebtoolDatasource *vwtds = NULL;
166   vwtds = vik_webtool_datasource_new_with_members ( _("OpenStreetMap Notes"), "http://api.openstreetmap.org/api/0.6/notes.gpx?bbox=%s,%s,%s,%s&amp;closed=0", "LBRT", NULL );
167   vik_ext_tool_datasources_register ( VIK_EXT_TOOL ( vwtds ) );
168   g_object_unref ( vwtds );
169
170   // Goto
171   VikGotoXmlTool *nominatim = VIK_GOTO_XML_TOOL ( g_object_new ( VIK_GOTO_XML_TOOL_TYPE, "label", "OSM Nominatim",
172     "url-format", "http://nominatim.openstreetmap.org/search?q=%s&format=xml",
173     "lat-path", "/searchresults/place",
174     "lat-attr", "lat",
175     "lon-path", "/searchresults/place",
176     "lon-attr", "lon",
177     NULL ) );
178     vik_goto_register ( VIK_GOTO_TOOL ( nominatim ) );
179     g_object_unref ( nominatim );
180
181   VikGotoXmlTool *namefinder = VIK_GOTO_XML_TOOL ( g_object_new ( VIK_GOTO_XML_TOOL_TYPE, "label", "OSM Name finder",
182     "url-format", "http://gazetteer.openstreetmap.org/namefinder/search.xml?find=%s&max=1",
183     "lat-path", "/searchresults/named",
184     "lat-attr", "lat",
185     "lon-path", "/searchresults/named",
186     "lon-attr", "lon",
187     NULL ) );
188     vik_goto_register ( VIK_GOTO_TOOL ( namefinder ) );
189     g_object_unref ( namefinder );
190
191   // Not really OSM but can't be bothered to create somewhere else to put it...
192   webtool = vik_webtool_center_new_with_members ( _("Wikimedia Toolserver GeoHack"), "http://toolserver.org/~geohack/geohack.php?params=%s;%s" );
193   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
194   g_object_unref ( webtool );
195   
196   /* See API references: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api */
197   VikRoutingEngine *osrm = g_object_new ( VIK_ROUTING_WEB_ENGINE_TYPE,
198     "id", "osrm",
199     "label", "OSRM",
200     "format", "gpx",
201     "url-base", "http://router.project-osrm.org/viaroute?output=gpx",
202     "url-start-ll", "&loc=%s,%s",
203     "url-stop-ll", "&loc=%s,%s",
204     "url-via-ll", "&loc=%s,%s",
205     NULL);
206   vik_routing_register ( VIK_ROUTING_ENGINE ( osrm ) );
207   g_object_unref ( osrm );
208 }
209