Adding a travel type control

In this tutorial, we will show you how to let users select different travel type, like bike, car or walk, using the TravelTypeFab angular directive and the map is automatically updated with the calculated polygons. You can use this TravelTypeFab for anything you want, e.g. select different travel speeds for fast or slow bikers.

Adding a travel type control

Refine travel modes easily

GET YOUR FREE API KEY to use this example
hide code
<!DOCTYPE html>
  <script src=""></script>
  <!--  Include leaflet javascript and css -->
  <link rel="stylesheet" href="" crossorigin="">
  <script src="" crossorigin=""></script>
  <!--  Include angular stuff  -->
  <script src=""></script>
  <script src=""></script>
  <link rel="stylesheet" href="">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <!--  Include r360.js and angular plugin -->
  <script src=""></script>
  <script src=""></script>
    html, body { width: 100%; height: 100%; margin: 0; font-family: sans-serif; }
    #map { width: 100%; height: 100%; }
    .controls { position: absolute; right: 20px; top: 20px; z-index: 1000;}

  <!--  where the map will live  -->
  <div id="map"></div>
  <div ng-app="TravelTypeExample" ng-controller="TravelTypeExampleController as vm" class="controls" ng-cloak="" layout="column" layout-align="start end">
    <travel-type-fab label="Travel Type" md-direction="left" md-animation="md-scale" model="vm.travelType">
    var latlon = [52.51, 13.37];
    var map ='map').setView(latlon, 13);
    map.attributionControl.addAttribution("ÖPNV Daten © <a href='' target='_blank'>VBB</a>");

    /* to change the location of the map change the lat and long, here 40.717192,-74.012042.
    To change the default zoom level change 17 to another number. 0 is entire world twice over and 18 is the closest you can get

    // initialise the base map
    r360.basemap({ style: 'basic', apikey: '__APIPLACEHOLDER__' }).addTo(map);

    // create a marker and add it to the map
    var marker = L.marker(latlon).addTo(map);

    // create the layer to add the polygons
    var polygonLayer = r360.leafletPolygonLayer();
    // add it to the map

    // helper function to encapsulate the show polygon action
    function showPolygons(travelType) {

      // you need to define some options for the polygon service
      // for more travel options check out the other tutorials
      var travelOptions = r360.travelOptions();
      // please contact us and request your own key
      // set the service url for your area
      // we only have one source which is the marker we just added
      // we want to have polygons for 10 to 30 minutes
      travelOptions.setTravelTimes([600,1200, 1800]);
      // get the selected travel type from the control
      // will only be considered if travel type is transit

      // call the service
      r360.PolygonService.getTravelTimePolygons(travelOptions, function(polygons) {

        // in case there are already polygons on the map/layer clear them
        // and fit the map to the polygon bounds ('true' parameter)
        polygonLayer.clearAndAddLayers(polygons, true);

    angular.module('TravelTypeExample', ['ngMaterial', 'ng360'])
      .controller("TravelTypeExampleController", function($scope) {
        var vm = this;

        this.travelType = 'walk';

        $scope.$watch('vm.travelType', function() {