Menu

#146 OpenCycleMaps watermarked with 'API Key Required'

v1.7
closed
nobody
6
2019-02-17
2017-04-01
No

Ubuntu 16.04.2
Viking 1.6.2-2 (?)

In the case of OpenCycleMaps, the 'API Key Required' watermark is mainly a cosmetic issue as the maps are still accessible. However, various GIS and mapping cloud services accessible via https calls are using API keys for metering and billing, identifying users, and minimising quota theft.

It would be good if it were possible to specify an API key string to be appended to such https calls. In the case of OSRM services it is required for matching trackpoints to throughfares.

Discussion

  • Rob Norris

    Rob Norris - 2017-04-03

    Ticket moved from /p/viking/bugs/141/

     
  • Rob Norris

    Rob Norris - 2017-04-03
    • summary: BUG (?): OpenCycleMaps watermarked with 'API Key Required' --> OpenCycleMaps watermarked with 'API Key Required'
    • status: open --> pending
    • Group: v1.6 --> v1.7
     
  • Rob Norris

    Rob Norris - 2017-04-03

    This has been explicitly addressed in the latest source code for the OpenCycleMap case.

    Currently one can override the internal map defaults using the map configuration.

    See 'Extending Viking' in the User Manual (although it doesn't mentions that a new set of values can override the internally defined ones). If you define a group that already exists (i.e. by a repeated id key) then you need to define all the other keys as well, otherwise they will be reset to the defaults.

    Thus for Cycle Maps put this in your ~/.viking/maps.xml file:

    <objects>
      <object class="VikSlippyMapSource">
        <property name="id">17</property>
        <property name="label">OpenStreetMap (Cycle)</property>
        <property name="name">OSM-Cycle</property>
        <property name="hostname">tile.thunderforest.com</property>
        <property name="url">/cycle/%d/%d/%d.png?apikey=YOUR_API_KEY_HERE</property>
        <property name="zoom-min">0</property>
        <property name="zoom-max">18</property>
        <property name="copyright">Tiles courtesy of Andy Allan ©OpenStreetMap contributors</property>
        <property name="license">CC-BY-SA</property>
        <property name="license-url">http://www.openstreetmap.org/copyright</property>
         <property name="file-extension">.png</property>
      </object>
    </objects>
    

    Most if not all other web services Viking uses can be extended (and thus possible to override the internal defaults (or simply create new versions) to set a URL that includes ones own API keys/tokens).

    HTH.

     

    Last edit: Rob Norris 2018-08-12
  • Vaillant

    Vaillant - 2017-12-23

    The solution proposed by Rob works but few precisions to be added:

    • the hostname shall include a subdomain which is either a , b or c (see https://www.thunderforest.com/docs/map-tiles-api/)

    • You shall spend the time to create a thunderforest account (free for limited per month usage and put the key at the place below.

    • Under viking, you shall select the map here named "OpenStreetMap (Cycle)B"

    <objects>

    <object class=""> <property name="id">67</property> <property name="label">OpenStreetMap (Cycle)B</property> <property name="name">OSM-CycleB</property> <property name="hostname">a.tile.thunderforest.com</property> <property name="url">/cycle/%d/%d/%d.png?apikey=GET_IT_ON_THUNDERFOREST/property> <property name="zoom-min">0</property> <property name="zoom-max">18</property> <property name="copyright">Tiles courtesy of Andy Allan ©OpenStreetMap contributors</property> <property name="license">CC-BY-SA</property> <property name="license-url">http://www.openstreetmap.org/copyright</property> <property name="file-extension">.png</property> </property></object></objects>

    Then enjoy.

     
  • Hedley Finger

    Hedley Finger - 2018-07-28

    Ubuntu 18.04 Bionic Beaver LTS
    Viking 1.6.2
    OpenStreetMaps (Cycle)

    I have tried to change the defaults for Viking 1.6.2 by putting both versions of maps.xml into both ~/.viking/ and ~/.viking-maps . A map I have previously worked upon still comes up with "API Key Required" overlaying the map. I have closed Viking, loaded a new .gpx file, but the "API Key Required" message still appears.

    Why has this defaults file worked for other people but not me? How should I begin trouble-shooting? (I am a newbie to Ubuntu, Viking, and OSM.)

     

    Last edit: Hedley Finger 2018-07-28
  • Hedley Finger

    Hedley Finger - 2018-07-28

    Rob Norris:

    In the line

    <property name="url">/cycle/%d/%/%d.png?apikey=YOUR_API_KEY_HERE</property>
    

    is "cycle/%d/%/%d" correct? Should this be "cycle/%d/%d/%d", as in @Vaillant 's version?

     

    Last edit: Hedley Finger 2018-07-28
    • Rob Norris

      Rob Norris - 2018-08-12

      Yes, it should be "cycle/%d/%d/%d".
      Now fixed

       
  • Hedley Finger

    Hedley Finger - 2018-07-28

    u/robbieonsea
    u/vaillant

    There is no need to prepend "a", "b", or "c" to tile.thunderforest.com. The prefixes are just a workaround to allow more requests from a particular domain than some browsers allow.

    From https://www.thunderforest.com/docs/map-tiles-api/:

    Our tileserver subdomains allow your site to make simultaneous requests to multiple domain names, even though they all ultimately point to the same service. This effectively increases the number of simultaneous tile requests, that would otherwise be limited by the browser. By convention the different tileservers are labeled a, b, and c - so the following three URLs all point to the same service, and give the same tiles in response.


    https://a.tile.thunderforest.com/cycle/3/3/3.png?apikey=<insert-your-apikey-here>
    https://b.tile.thunderforest.com/cycle/3/3/3.png?apikey=<insert-your-apikey-here>
    https://c.tile.thunderforest.com/cycle/3/3/3.png?apikey=<insert-your-apikey-here></insert-your-apikey-here></insert-your-apikey-here></insert-your-apikey-here>


     

    Last edit: Hedley Finger 2018-07-28
  • Rob Norris

    Rob Norris - 2019-01-24
    • status: pending --> closed
     
  • Hedley Finger

    Hedley Finger - 2019-02-03

    u/robbieonsea
    u/vaillant

    Ubuntu 18.04 Bionic Beaver LTS
    Viking 1.7
    OpenCycleMaps

    I am going nuts here. I still cannot get rid of the "API key required" watermark, even after trying all the above suggestions. I put up with it as it didn't affect my current project. However, I now need to have clean maps for screenshots and PDF notes, etc. The appears not to have been fixed in the code (Viking 1.7). My current maps.xml file contains:

    <objects>
        <object class="VikSlippyMapSource">
            <property name="id">17</property>
            <!-- Vaillant says the ID is 67 (?) -->
            <property name="label">OpenStreetMap (Cycle)B</property>
            <property name="name">OSM-CycleB</property>
            <property name="scale">2</property>
            <property name="hostname">a.tile.thunderforest.com</property>
            <property name="url">/cycle/%d/%d/%d.png?    apikey=eefde18d6cf64c988414670470f040df<property>
            <!-- This is the key assigned to me by Thunderforest -->
            <property name="zoom-min">0</property>
            <property name="zoom-max">18</property>
            <property name="copyright">Tiles courtesy of Andy Allan, © OpenStreetMap contributors</property>
            <property name="license">CC-BY-SA</property>
            <property name="license-url">http://www.openstreetmap.org/copyright</property>
            <property name="file-extension">.png</property>
        </object>
    </objects>
    

    I have tried removing the maps.xml file altogether but watermarks still appear, suggesting this issue has not been fixed in the code. Another issue is that Vaillant and Rob differ on the ID value -- is it 17 or 67? I am not a coder, so how can I get a list of IDs for all the extension <object> items embedded in the code? Finally, how do I access OSRM services from within Viking.

     
  • Rob Norris

    Rob Norris - 2019-02-03

    OK I'll try to explain what I think is going on, but there are several different factors that will effect the behaviour.

    You will already have tile images stored on disk (which could have the API key watermark on them). If Viking and/or the server request thinks these images are 'new enough' it won't attempt to get a fresh tile.

    You may want to manually delete/move your on disk cache to try to cause a complete refresh so it will definitely be using your API key. This isn't possible via the GUI. The location of the tiles is dependent on the Map Layer configuration (both the map directory and cache layout properties).
    With a default directory of ~/.viking-maps, and a OSM layout type the location is:

    ~/.viking-maps/+'Map Name from config' - so for the above instance it will be:
    ~/.viking-maps/OSM-CycleB/
    

    So simply rename it e.g. ~/.viking-maps/OSM-CycleB-Backup/, and then restart Viking and it will create a fresh ~/.viking-maps/OSM-CycleB/

    For the (older) Viking layout style is somewhat more messy as it will be spread over many directories.

    ~/.viking-maps/t<MapID>s<Scale>z<Z> - so for the above instance it will be like:
    ~/.viking-maps/t13s1z0
    ~/.viking-maps/t13s2z0
    ~/.viking-maps/t13s3z0
    etc...
    

    Default Map Ids are here: https://sourceforge.net/p/viking/code/ci/master/tree/src/map_ids.h
    Here is a snippet:

    #define MAP_ID_OSM_MAPNIK 13
    #define MAP_ID_BLUE_MARBLE 15
    #define MAP_ID_OSM_CYCLE 17
    //#define MAP_ID_MAPQUEST_OSM 19 // Tile Service discontinued
    #define MAP_ID_OSM_TRANSPORT 20
    #define MAP_ID_OSM_ON_DISK 21
    #define MAP_ID_OSM_HUMANITARIAN 22
    #define MAP_ID_MBTILES 23
    #define MAP_ID_OSM_METATILES 24
    #define MAP_ID_MAPBOX_OUTDOORS 25
    #define MAP_ID_BING_AERIAL 212
    

    With the XML configuration file you're free to add any you like, but in my opinion it's best to use Id's greater than 128. If you use an Id that already exists, then any fields you specify (label, hostname, url, etc...) will overwrite whatever the previous values are.

    So currently with the above config with the id=17, you should see 'OpenStreetMap (Cycle)B' listed in GUI menu of available maps rather than the default 'OpenStreetMap (Cycle)'.
    If instead you used id=67, then you should see both 'OpenStreetMap (Cycle)' and 'OpenStreetMap (Cycle)B' in the available maps menu.

    I assume the spaces in property url

    "/cycle/%d/%d/%d.png?    apikey=abcdef...."
                          ^^^^
    

    Is an unintentional / copy / paste issue here? Otherwise make sure they don't exist in your .xml config as they might cause issues.

    ATM I'm not sure what happens when you don't specify a Id number. It's advisable to ensure the name and label fields are unique. I'm not sure what happens if these fields clash between map type entries.

    NB There is python tool to convert between the cache layouts, but typically not made available in distributions.
    "viking-cache.py" in here https://sourceforge.net/p/viking/code/ci/master/tree/tools/

    HTH, I'll address the OSRM usage in a separate message later.

     
  • Hedley Finger

    Hedley Finger - 2019-02-16

    Rob:

    Thanks for all your help; I am getting there. W.r.t. OSRM data streams, wouldn't it be fairly easy to convert GeoJSON polylines and waypoints to GPX for processing in Viking? If you avoided all the fancy closed geometric shapes. Just ignore the multi-* structures? Or convert all the data structures to polylines and write them back as GeoJSON polylines? I don't think there are too many navigation apps or devices that understand GeoJSON.

    I am not a programmer, geometer, or geographer. Have you noticed? I just want to convert my logs into optimised routes!

     
  • Rob Norris

    Rob Norris - 2019-02-17

    I think ATM the most expedient method to get something working will be to allow to specify an alternative program to GPSBabel to transform the received data.
    So for OSRM could make it a configuration setting to run a geojson to gpx program e.g. togpx -> https://github.com/tyrasd/togpx
    Remains to be seen if this actually works for the OSRM JSON, but should be quick to implement with the current code structure.
    One slight difficulty is how to set up command line parameters in the configuration (that is flexible to work for a variety of programs...)

     

Log in to post a comment.

MongoDB Logo MongoDB