Guest User

Creating a Static Map Req with Route Response Data

a guest
May 14th, 2019
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         function callback(data, stops) {
  2.             $("#results").val(JSON.stringify(data, undefined, 4));
  3.  
  4.             var bbox = data.route.boundingBox;
  5.             var sesh = data.route.sessionId;
  6.  
  7.             var url = constructStaticMapURL(sesh, bbox, stops, $(window).width(), $(window).height());
  8.             showImage(url, $(window).width(), $(window).height())
  9.         }
  10.  
  11.         function constructStaticMapURL(sessionID, boundingBox, stops, width, height) {
  12.             var stopsString = ''
  13.             if(stops.length > 0) {
  14.                 stopsString = '&locations='
  15.                 for(var i = 0; i < stops.length; i++) {
  16.                     stopsString += stops[i]
  17.                     stopsString += '|marker-' + (i+1)
  18.                     if(i + 1 < stops.length) {
  19.                         stopsString += '||'
  20.                     }
  21.                 }
  22.                 console.log(stopsString)
  23.             }
  24.             var ullat, ullong, lrlat, lrlong;
  25.             ullat = boundingBox.ul.lat;
  26.             ullong = boundingBox.ul.lng;
  27.             lrlat = boundingBox.lr.lat;
  28.             lrlong = boundingBox.lr.lng;
  29.             var URL = 'https://www.mapquestapi.com/staticmap/v5/map?' + 'key=' + key
  30.             + '&session=' + sessionID + stopsString
  31.             + '&boundingBox=' + ullat + ','
  32.             + ullong + ',' + lrlat + ',' + lrlong
  33.             + '&size=' + width + ',' + height;
  34.             console.log(URL);
  35.             return URL; //this will be the src parameter in the showImage function
  36.         }
RAW Paste Data