server/utils.js
/**Create custom Matrix Request based on coordinate Array. Return an Array of
 * Here (x1,y1) : bottom-left point, (x2, y2): top-right point,
 * x1 to x2 : origin coordinates (row-wise); y1 to y2: destination (column-wise)
 * @param {Array(Array(number)} coordinateArray
 * @returns {Promise<{sections: Array({x1:number, x2:number, y1: number, y2: number}), customMatrix: Array(Array(number))}>}
 */
Create custom Matrix Request based on coordinate Array.
Create custom Matrix Request based on coordinate Array .
function createDMRequests(coordinateArray) {
  return new Promise((resolve, reject) => {
    try {
      let size = coordinateArray.length;
      let customMatrix = new Array(size);
      for (let i = 0; i < size; i++) {
        customMatrix[i] = new Array(size);
      }
      let sections = distanceMatrixHelper.calcRequestNeeded(size);
      for (let j = 0; j < sections.length; j++) {
        let origins = `origins=`;
        for (let i = sections[j].x1; i <= sections[j].x2; i++) {
          origins += `${coordinateArray[i].lat},${coordinateArray[i].lon}|`;
        }
        origins = origins.slice(0, origins.length - 1);
        let destinations = `destinations=`;
        for (let i = sections[j].y1; i <= sections[j].y2; i++) {
          destinations += `${coordinateArray[i].lat},${coordinateArray[i].lon}|`;
        }
        destinations = destinations.slice(0, destinations.length - 1);
        let url = constructDistanceMatrixRequest(origins, destinations); 
        sections[j].url = url;
      }
      resolve({ sections, customMatrix });
    } catch (err) {
      reject("createDMRequests():" + err);
    }
  });
}
function createDMRequests ( coordinateArray ) { return new Promise ( ( resolve , reject ) => { try { let size = coordinateArray . length ; let customMatrix = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) { customMatrix [ i ] = new Array ( size ) ; } let sections = distanceMatrixHelper . calcRequestNeeded ( size ) ; for ( let j = 0 ; j < sections . length ; j ++ ) { let origins = ` ` ; for ( let i = sections [ j ] . x1 ; i <= sections [ j ] . x2 ; i ++ ) { origins += ` ${ coordinateArray [ i ] . lat } ${ coordinateArray [ i ] . lon } ` ; } origins = origins . slice ( 0 , origins . length - 1 ) ; let destinations = ` ` ; for ( let i = sections [ j ] . y1 ; i <= sections [ j ] . y2 ; i ++ ) { destinations += ` ${ coordinateArray [ i ] . lat } ${ coordinateArray [ i ] . lon } ` ; } destinations = destinations . slice ( 0 , destinations . length - 1 ) ; let url = constructDistanceMatrixRequest ( origins , destinations ) ; sections [ j ] . url = url ; } resolve ( { sections , customMatrix } ) ; } catch ( err ) { reject ( "createDMRequests():" + err ) ; } } ) ; }
Create custom Matrix Request based on coordinate Array.
Create custom Matrix Request based on coordinate Array .
//2a