GPX and KML files
GPX (GPS Exchange format) and KML (Keyhole Markup Language) files are used to record a route, typically recorded live on a walk by a GPS system. KML files can also show polygon areas as well as linear routes, so they are useful for showing areas and boundaries. The OS mapping engine allows you to import these as layers on your map, which is useful for showing a route and marking significant features. The file must be on the same WordPress domain as your site. The easiest way is simply to upload as a media file and then copy and paste the URL from your media library.
Elevation Profiles
This was one of the most-requested features in OpenSpace maps, and thanks to Leaflet maps plugins we can now provide them. They only work with GPX files (not KML) and the elevation data must be included in the GPX file. To see the profile you need to set a height, either by setting the default profile height on the plugin settings page or by using the shortcode attribute.
This example uses a GPX track to show a walking route on the map. The map will auto-scale to show the whole route.
The GPX file also includes elevation data, allowing us to show the elevation profile of the route below the map. If you hover over the profile it will show a marker on the map, and an info box with the height and distance data.
[osmap gpx="http://skirridsystems.co.uk/wp-content/uploads/2018/01/horseshoe.gpx" color="darkgreen" track="4" profile="175"]
Shortcode Attributes
gpx="routefile1|routefile2|routefile3"
Specifies three GPX files to show on the map.
kml="kmlfile1|kmlfile2|kmlfile3"
Specifies three KML files to show on the map.
color=red
or color=#ff0000
sets the colour of the tracks shown from a GPX or KML file.
track=3
Sets the width of the track in pixels.
opacity=0.8
Sets the track opacity from 0.0 to 1.0. Default value is 0.7.
gpxstyle=1
Tells the GPX file processor to take the track colour from the GPX file rather than from the OS maps settings. This is useful for GPX files which contain multiple tracks. Note that it is now possible to include multiple GPX files, so this method is less often required.
profile=200
Sets the elevation profile height, overriding the default on the settings page
start_marker=green
Places a green marker at the start of the GPX track. Any of the marker colours listed below can be used.
end_marker=red
Places a red marker at the end of the GPX track. For circular routes there is no merit in displaying both start and end markers.
Additional route attributes
In addition to the route file you can also specify the track colour and some text to go in a popup which opens when the track is clicked. You can also specify a group for the marker if you are using layers, but you won’t need that in most cases. Route file is the only mandatory item. You can add the other options using the appropriate leading character, and they must be in this order:
- Location
- $group
- !colour
- ;description
Routes with Markers
You can use both routes and markers on the same map. Just add both of them to the shortcode as in this example:
[osmap gpx="http://skirridsystems.co.uk/wp-content/uploads/2018/01/horseshoe.gpx" color="darkgreen" markers="SH6099054380!red;Snowdon|SH624551;Crib Goch"]
List Files
If you have a lot of markers or routes, or if the descriptions are long, you may be better putting the definitions into a text file. This works for GPX and KML files in the same way as it does for markers, using either text or JSON format.
Upload the text file to your WordPress media library and refer to the file instead.
gpxfile="http://example.com/gpx_routes.txt"
kmlfile="http://example.com/kml_overlays.txt"
This example combines six different GPX tracks onto one map, assigning a different colour to each.
[osmap height=750 gpx="http://skirridsystems.co.uk/wp-content/uploads/ranger-track1.gpx!#800080|http://skirridsystems.co.uk/wp-content/uploads/watkinpath.gpx!#000080|http://skirridsystems.co.uk/wp-content/uploads/south_ridge.gpx!#FF0000|http://skirridsystems.co.uk/wp-content/uploads/llanberis-path11.gpx!#008000|http://skirridsystems.co.uk/wp-content/uploads/miners-path.gpx!#008080|http://skirridsystems.co.uk/wp-content/uploads/cribgoch_GPS.gpx!#808000"]
Thanks to mudandroutes for these GPX files.
« Adding Markers Up Using Layers »