Calculating the bearing of each box drawn by RouteBoxer

Currently I have a fully functional map that can use RouteBoxer on a path from A to B and query a fusion table based on the route (and other variables) to only display certain rows that are relevant to that route. The issue I have now is that my map and query does not take direction traveled into consideration (i.e. it's showing data from the fusion table that are on both sides of the road). I know I need to calculate the bearing for each step in the route to be able to determine the direction traveled, but I'm not sure how to do that. Once I can get the bearing, using that value to query the fusion table should be easy. /// ******************************************************************** /// ========================= ROUTING FUNCTIONS ======================== /// ******************************************************************** // ================================================================= // Function to Perform routing // ================================================================= function route() { document.getElementById("print-directions").style.display = "inline" document.getElementById("print-map").style.display = "none" // Display loading message. document.getElementById('loading_image').style.visibility="visible"; printDirectionsFlag = true; // Clear any previous route boxes from the map clearBoxes(); distance = 5; // Default distance var request = { origin: document.getElementById("search-input-from").value, destination: document.getElementById("search-input-to").value, travelMode: google.maps.DirectionsTravelMode.DRIVING } // Make the directions request directionService.route(request, function(result, status) { if (status == google.maps.DirectionsStatus.OK) { directionsRenderer.setDirections(result); // Box around the overview path of the first route var path = result.routes[0].overview_path; //alert(path); var boxes = routeBoxer.box(path, distance); drawBoxes(boxes); } else { alert("Directions query failed: " + status); } }); } /* function calcBearing(){ } */ // ================================================================= // Function to conduct a spatial query based on input bounds // ================================================================= function spatialQuery(bounds) { var str = new String(bounds); var coord = str.split(","); clearOverlays(legendItemsArray_LightOnly); clearOverlays(legendItemsArray_HeavyOnly); clearOverlays(legendItemsArray_LightHeavy); // Empty marker arrays legendItemsArray_LightOnly = []; legendItemsArray_HeavyOnly = []; legendItemsArray_LightHeavy = []; // Reset and re-run query //var fustionTableId = '1SnbgBARsBwxjh5CTUTLSIWd7_yVMxCkX0iXUvf0'; var querySelect = querySelectRestAreas; var queryWhere = "'PUBLISH' = 'Y' AND 'RA_CAT' IN ('RA', 'PA') AND 'RA_TYPE' IN ('B', 'H', 'L')"; var queryWhereSpatial = " AND ST_INTERSECTS('LATITUDE', RECTANGLE(LATLNG("+coord[0].slice(2)+", "+coord[1].slice(0,coord[1].length-1)+"), LATLNG("+coord[2].slice(2)+", "+coord[3].slice(0,coord[3].length-2)+")))"; var queryOptions = setQueryOptions(); var queryWhereClause = queryWhere + queryOptions + queryWhereSpatial; var queryOrderBy = "'IIT_NE_ID'"; loadTable(ftID, querySelect, queryWhereClause, queryOrderBy); } // ================================================================= // Function to conduct a spatial query based on input bounds // ================================================================= function updateQuery() { // Display loading message. document.getElementById('facilities-loader').style.visibility="visible"; if(printDirectionsFlag){ route(); } else{ clearOverlays(legendItemsArray_LightOnly); clearOverlays(legendItemsArray_HeavyOnly); clearOverlays(legendItemsArray_LightHeavy); // Empty marker arrays legendItemsArray_LightOnly = []; legendItemsArray_HeavyOnly = []; legendItemsArray_LightHeavy = []; // Reset and re-run query //var fustionTableId = '1SnbgBARsBwxjh5CTUTLSIWd7_yVMxCkX0iXUvf0'; var querySelect = querySelectRestAreas; var queryWhere = "'PUBLISH' = 'Y' AND 'RA_CAT' IN ('RA', 'PA') AND 'RA_TYPE' IN ('B', 'H', 'L')"; //var queryWhereSpatial = " ST_INTERSECTS('LATITUDE', RECTANGLE(LATLNG("+coord[0].slice(2)+", "+coord[1].slice(0,coord[1].length-1)+"), LATLNG("+coord[2].slice(2)+", "+coord[3].slice(0,coord[3].length-2)+")))"; var queryOptions = setQueryOptions(); // alert(queryOptions); var queryWhereClause = queryWhere + queryOptions; var queryOrderBy = "'IIT_NE_ID'"; loadTable(ftID, querySelect, queryWhereClause, queryOrderBy); } } // ================================================================= // Function to draw the array of boxes as polylines on the map // ================================================================= function drawBoxes(boxes) { boxpolys = new Array(boxes.length); for (var i = 0; i < boxes.length; i++) { boxpolys[i] = new google.maps.Rectangle({ bounds: boxes[i], fillOpacity: 0, strokeOpacity: 100, strokeColor: '#000000', strokeWeight: 1, map: map }); //alert(boxes[i]); //spatialQuery(boxes[i]); } // Display loading message. document.getElementById('loading_image').style.visibility="hidden"; } I'm not sure where this calculation for bearing would go or how you actually do it. Any ideas?
There is a calculation of the heading of a polyline in the geometry library documentation

以上就是Calculating the bearing of each box drawn by RouteBoxer的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏