目前我有一个功能齐全的地图,可以在从A到B的路径上使用RouteBoxer,并根据路径(和其他变量)查询融合表,只显示与该路线相关的某些行。我现在遇到的问题是我的地图和查询没有考虑到方向(即它显示了融合表中位于道路两侧的数据)。我知道我需要计算路线中每一步的方位,以便能够确定行进的方向,但我不知道该怎么做。一旦我可以获得方位,使用该值来查询融合表应该很容易。
/// ********************************************************************
/// ========================= 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";
}
我不确定轴承计算的位置或实际操作方式。有什么想法吗?