]> git.street.me.uk Git - andy/viking.git/blob - src/osm.c
added save previous user input string and input label options to datasource search...
[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-2014, 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                                 "name", "OSM-Mapnik",
51                                 "hostname", "tile.openstreetmap.org",
52                                 "url", "/%d/%d/%d.png",
53                                 "check-file-server-time", FALSE,
54                                 "use-etag", TRUE,
55                                 "zoom-min", 0,
56                                 "zoom-max", 19,
57                                 "copyright", "© OpenStreetMap contributors",
58                                 "license", "CC-BY-SA",
59                                 "license-url", "http://www.openstreetmap.org/copyright",
60                                 NULL));
61   VikMapSource *cycle_type =
62     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
63                                 "id", 17,
64                                 "label", "OpenStreetMap (Cycle)",
65                                 "name", "OSM-Cycle",
66                                 "hostname", "tile.opencyclemap.org",
67                                 "url", "/cycle/%d/%d/%d.png",
68                                 "check-file-server-time", TRUE,
69                                 "use-etag", FALSE,
70                                 "zoom-min", 0,
71                                 "zoom-max", 18,
72                                 "copyright", "Tiles courtesy of Andy Allan © OpenStreetMap contributors",
73                                 "license", "CC-BY-SA",
74                                 "license-url", "http://www.openstreetmap.org/copyright",
75                                 NULL));
76   VikMapSource *transport_type =
77     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
78                                 "id", 20,
79                                 "label", "OpenStreetMap (Transport)",
80                                 "name", "OSM-Transport",
81                                 "hostname", "tile2.opencyclemap.org",
82                                 "url", "/transport/%d/%d/%d.png",
83                                 "check-file-server-time", TRUE,
84                                 "use-etag", FALSE,
85                                 "zoom-min", 0,
86                                 "zoom-max", 18,
87                                 "copyright", "Tiles courtesy of Andy Allan © OpenStreetMap contributors",
88                                 "license", "CC-BY-SA",
89                                 "license-url", "http://www.openstreetmap.org/copyright",
90                                 NULL));
91   VikMapSource *mapquest_type =
92     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
93                                 "id", 19,
94                                 "name", "OSM-MapQuest",
95                                 "label", "OpenStreetMap (MapQuest)",
96                                 "hostname", "otile1.mqcdn.com",
97                                 "url", "/tiles/1.0.0/osm/%d/%d/%d.png",
98                                 "check-file-server-time", TRUE,
99                                 "use-etag", FALSE,
100                                 "zoom-min", 0,
101                                 "zoom-max", 19,
102                                 "copyright", "Tiles Courtesy of MapQuest © OpenStreetMap contributors",
103                                 "license", "MapQuest Specific",
104                                 "license-url", "http://developer.mapquest.com/web/info/terms-of-use",
105                                 NULL));
106   VikMapSource *hot_type =
107     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
108                                 "id", 22,
109                                 "name", "OSM-Humanitarian",
110                                 "label", "OpenStreetMap (Humanitarian)",
111                                 "hostname", "c.tile.openstreetmap.fr",
112                                 "url", "/hot/%d/%d/%d.png",
113                                 "check-file-server-time", TRUE,
114                                 "use-etag", FALSE,
115                                 "zoom-min", 0,
116                                 "zoom-max", 20, // Super detail!!
117                                 "copyright", "© OpenStreetMap contributors. Tiles courtesy of Humanitarian OpenStreetMap Team",
118                                 "license", "CC-BY-SA",
119                                 "license-url", "http://www.openstreetmap.org/copyright",
120                                 NULL));
121
122   // NB no cache needed for this type!!
123   VikMapSource *direct_type =
124     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
125                                 "id", 21,
126                                 "label", _("On Disk OSM Tile Format"),
127                                 // For using your own generated data assumed you know the license already!
128                                 "copyright", "© OpenStreetMap contributors", // probably
129                                 "use-direct-file-access", TRUE,
130                                 NULL));
131
132   // NB no cache needed for this type!!
133   VikMapSource *mbtiles_type =
134     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
135                                 "id", 23,
136                                 "label", _("MBTiles File"),
137                                 // For using your own generated data assumed you know the license already!
138                                 "copyright", "© OpenStreetMap contributors", // probably
139                                 "use-direct-file-access", TRUE,
140                                 "is-mbtiles", TRUE,
141                                 NULL));
142
143   // NB no cache needed for this type!!
144   VikMapSource *metatiles_type =
145     VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE,
146                                 "id", 24,
147                                 "label", _("OSM Metatiles"),
148                                 // For using your own generated data assumed you know the license already!
149                                 "copyright", "© OpenStreetMap contributors", // probably
150                                 "use-direct-file-access", TRUE,
151                                 "is-osm-meta-tiles", TRUE,
152                                 NULL));
153
154   maps_layer_register_map_source (mapquest_type);
155   maps_layer_register_map_source (mapnik_type);
156   maps_layer_register_map_source (cycle_type);
157   maps_layer_register_map_source (transport_type);
158   maps_layer_register_map_source (hot_type);
159   maps_layer_register_map_source (direct_type);
160   maps_layer_register_map_source (mbtiles_type);
161   maps_layer_register_map_source (metatiles_type);
162
163   // Webtools
164   VikWebtoolCenter *webtool = NULL;
165   webtool = vik_webtool_center_new_with_members ( _("OSM (view)"), "http://openstreetmap.org/?lat=%s&lon=%s&zoom=%d" );
166   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
167   g_object_unref ( webtool );
168
169   webtool = vik_webtool_center_new_with_members ( _("OSM (edit)"), "http://www.openstreetmap.org/edit?lat=%s&lon=%s&zoom=%d" );
170   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
171   g_object_unref ( webtool );
172
173   webtool = vik_webtool_center_new_with_members ( _("OSM (render)"), "http://www.informationfreeway.org/?lat=%s&lon=%s&zoom=%d&layers=B0000F000F" );
174   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
175   g_object_unref ( webtool );
176
177   VikWebtoolBounds *webtoolbounds = NULL;
178   // Example: http://127.0.0.1:8111/load_and_zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&select=node413602999
179   // JOSM or merkaartor must already be running with remote interface enabled
180   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" );
181   vik_ext_tools_register ( VIK_EXT_TOOL ( webtoolbounds ) );
182   g_object_unref ( webtoolbounds );
183
184   VikWebtoolFormat *vwtf = NULL;
185   vwtf = vik_webtool_format_new_with_members ( _("Geofabrik Map Compare"),
186                                                "http://tools.geofabrik.de/mc/#%s/%s/%s",
187                                                "ZAO" );
188   vik_ext_tools_register ( VIK_EXT_TOOL ( vwtf ) );
189   g_object_unref ( vwtf );
190
191   // Datasource
192   VikWebtoolDatasource *vwtds = NULL;
193   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, NULL, NULL );
194   vik_ext_tool_datasources_register ( VIK_EXT_TOOL ( vwtds ) );
195   g_object_unref ( vwtds );
196
197   // Goto
198   VikGotoXmlTool *nominatim = VIK_GOTO_XML_TOOL ( g_object_new ( VIK_GOTO_XML_TOOL_TYPE, "label", "OSM Nominatim",
199     "url-format", "http://nominatim.openstreetmap.org/search?q=%s&format=xml",
200     "lat-path", "/searchresults/place",
201     "lat-attr", "lat",
202     "lon-path", "/searchresults/place",
203     "lon-attr", "lon",
204     NULL ) );
205     vik_goto_register ( VIK_GOTO_TOOL ( nominatim ) );
206     g_object_unref ( nominatim );
207
208   VikGotoXmlTool *namefinder = VIK_GOTO_XML_TOOL ( g_object_new ( VIK_GOTO_XML_TOOL_TYPE, "label", "OSM Name finder",
209     "url-format", "http://gazetteer.openstreetmap.org/namefinder/search.xml?find=%s&max=1",
210     "lat-path", "/searchresults/named",
211     "lat-attr", "lat",
212     "lon-path", "/searchresults/named",
213     "lon-attr", "lon",
214     NULL ) );
215     vik_goto_register ( VIK_GOTO_TOOL ( namefinder ) );
216     g_object_unref ( namefinder );
217
218   // Not really OSM but can't be bothered to create somewhere else to put it...
219   webtool = vik_webtool_center_new_with_members ( _("Wikimedia Toolserver GeoHack"), "http://toolserver.org/~geohack/geohack.php?params=%s;%s" );
220   vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
221   g_object_unref ( webtool );
222   
223   /* See API references: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api */
224   VikRoutingEngine *osrm = g_object_new ( VIK_ROUTING_WEB_ENGINE_TYPE,
225     "id", "osrm",
226     "label", "OSRM",
227     "format", "gpx",
228     "url-base", "http://router.project-osrm.org/viaroute?output=gpx",
229     "url-start-ll", "&loc=%s,%s",
230     "url-stop-ll", "&loc=%s,%s",
231     "url-via-ll", "&loc=%s,%s",
232     NULL);
233   vik_routing_register ( VIK_ROUTING_ENGINE ( osrm ) );
234   g_object_unref ( osrm );
235 }
236