SHARE
TWEET

Untitled

a guest Jan 15th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. setupRoutingAPI(map) {
  2.         ghRouting.clearPoints();
  3.  
  4.         if (typeof routingLayer.clearLayers !== "undefined") {
  5.           console.log('wyjebie blad')
  6.         }
  7.  
  8.         ghRouting.addPoint(new GHInput(this.from.point.lat, this.from.point.lng));
  9.  
  10.         if (Object.keys(this.via1).length > 0) ghRouting.addPoint(new GHInput(this.via1.point.lat, this.via1.point.lng));
  11.         if (Object.keys(this.via2).length > 0) ghRouting.addPoint(new GHInput(this.via2.point.lat, this.via2.point.lng));
  12.         if (Object.keys(this.via3).length > 0) ghRouting.addPoint(new GHInput(this.via3.point.lat, this.via3.point.lng));
  13.         if (Object.keys(this.via4).length > 0) ghRouting.addPoint(new GHInput(this.via4.point.lat, this.via4.point.lng));
  14.  
  15.         ghRouting.addPoint(new GHInput(this.destination.point.lat, this.destination.point.lng));
  16.  
  17.         ghRouting.doRequest()
  18.           .then(function (json) {
  19.             var path = json.paths[0];
  20.             routingLayer.clearLayers();
  21.  
  22.             routingLayer.addData({
  23.               "type": "Feature",
  24.               "geometry": path.points
  25.             });
  26.             var outHtml = "Distance in meter: " + path.distance;
  27.             $("#routing-response").html(outHtml);
  28.  
  29.             // center the map after drawing route
  30.             if (path.bbox) {
  31.               var minLon = path.bbox[0];
  32.               var minLat = path.bbox[1];
  33.               var maxLon = path.bbox[2];
  34.               var maxLat = path.bbox[3];
  35.               var tmpB = new L.LatLngBounds(new L.LatLng(minLat, minLon), new L.LatLng(maxLat, maxLon));
  36.               map.fitBounds(tmpB);
  37.             }
  38.           })
  39.           .catch(function (err) {
  40.             var str = "An error occured: " + err.message;
  41.             $("#routing-response").text(str);
  42.           });
  43.         // end of API call using JS library
  44.  
  45.         var routingLayer = L.geoJson().addTo(this.routingMap);
  46.         routingLayer.clearLayers();
  47.  
  48.         routingLayer.options = {
  49.           style: { color: "#00cc33", "weight": 5, "opacity": 0.6 }
  50.         };
  51.       },
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top