For interactive map development we suggest using open-source JavaScript library Leaflet. It's a lightweight, feature-rich library which can be extended with lots of plugins.
Here is a short guide on how to add a map to your project using Leaflet and TravelTime tiles. More extensive tutorials on using Leaflet can be found here.
To get the interactive map to work, first of all you’ll need to include CSS code needed for your page to access leaflet.js, then define elements, map size, default zoom parameters and focus point of the map.
- Include Leaflet
CSSfile in the head section of your document:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>- Include Leaflet JavaScript file after Leaflet’s
CSS:
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
- Put a
divelement with a certainidwhere you want your map to be:
<div id="mapid"></div>- Define map container height, for example by setting it in
CSS:
#mapid { height: 180px; }- To initialize the map, set the inital geographical position of the map and a zoom level:
var mymap = L.map('mapid').setView([51.505, -0.09], 13);- Add a TravelTime tile layer to the map. The tiles server URL includes the tile style — available options are
osm-brightandpositron. ReplaceYOUR_APP_IDwith your access key. Note that tiles are not available with the free API key. To request access, contact us at hello@traveltime.com. Attribution is required to comply with OpenStreetMap and TravelTime copyright requirements.
L.tileLayer('https://tiles.traveltimeapp.com/osm-bright/{z}/{x}/{y}.png?key=YOUR_APP_ID', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> | Created with <a href="http://traveltime.com" target="_blank">TravelTime API</a>',
maxZoom: 22,
tileSize: 256,
}).addTo(mymap);L.tileLayer('https://tiles.traveltimeapp.com/positron/{z}/{x}/{y}.png?key=YOUR_APP_ID', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> | Created with <a href="http://traveltime.com" target="_blank">TravelTime API</a>',
maxZoom: 22,
tileSize: 256,
}).addTo(mymap);After doing all of these steps you should have a working map with mouse, touch interactions working as well as zoom and attribution control.
More extensive tutorials on using Leaflet can be found here.