Skip to content

Commit

Permalink
Show only start/end points for failed test results
Browse files Browse the repository at this point in the history
change handling of random address being outside of map view
  • Loading branch information
cmhodgson committed Jun 27, 2024
1 parent 9a11ccb commit cc1b157
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions ols-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,6 @@ <h4>Examples:</h4>
routeQuery = 'apikey=' + DATABC_APIKEY
}

var xmdx = 5000;
if(queryParams.get('xmdx')) {
var num = parseInt(queryParams.get('xmdx'));
if(!isNaN(num)) {
xmdx = num;
}
}

var matchPrecisionNot = "";
if('noStreets' in queryParams) {
matchPrecisionNot = "street";
Expand Down Expand Up @@ -2308,7 +2300,12 @@ <h4>Examples:</h4>
});

function addTestResults(data) {
var testResultsLayer = L.geoJSON(data.features, {
// don't draw the geometry for any failed routes
var features = [];
for(let f of data.features) {
if(f.properties.distance > 0) features.push(f);
}
var testResultsLayer = L.geoJSON(features, {
style: getTestStyle,
pane: map.getPane('routePane')
});
Expand Down Expand Up @@ -2430,9 +2427,7 @@ <h4>Examples:</h4>
}
}).addTo(map);
}
if(center) {
centerMap(routeLayer.getBounds(), center);
}
centerMap(routeLayer.getBounds(), center);

// update icon numbering
$('#routerList input.input-field').each( function(index, element) {
Expand Down Expand Up @@ -3311,7 +3306,7 @@ <h4>Examples:</h4>
}

// Random Address event handler
function randomAddress($field, locationDescriptor, callback, $statusDiv = null, retries = 0) {
function randomAddress($field, locationDescriptor, callback, $statusDiv = null) {
if($statusDiv) {
$statusDiv.html('Jumping to random civic address...');
}
Expand All @@ -3337,7 +3332,6 @@ <h4>Examples:</h4>
url: gcApi + "sites/nearest.json",
data: {
locationDescriptor: locationDescriptor,
maxDistance: xmdx,
excludeUnits: true,
onlyCivic: true,
brief: true,
Expand All @@ -3347,19 +3341,17 @@ <h4>Examples:</h4>
if($statusDiv) {
$statusDiv.empty();
}
$field.val(data.properties.fullAddress);
return callback(data, $field);
if(data.properties?.fullAddress) {
$field.val(data.properties.fullAddress);
return callback(data, $field);
}
},
error: function(request) {
if(retries < 100) {
randomAddress($field, locationDescriptor, callback, $statusDiv, retries+1);
} else {
if($statusDiv) {
$statusDiv.empty();
}
alert(baseErrorMsg + "Error retrieving nearest site to random point, please try your request again.");
console.log(request);
if($statusDiv) {
$statusDiv.empty();
}
alert(baseErrorMsg + "Error retrieving nearest site to random point, please try your request again.");
console.log(request);
}
});
}
Expand All @@ -3375,15 +3367,23 @@ <h4>Examples:</h4>
var options = {
maxZoom: 16
};
options.paddingBottomRight = [20,20];
options.paddingTopLeft = [20,20];
if(tabs) {
options.paddingTopLeft = [400,0];
options.paddingTopLeft = [420,20];
}
if(center) {
map.fitBounds(bounds.pad(0.25), options);
} else if(!map.getBounds().contains(bounds.pad(0.25))) {
// if the bounds aren't within the current map bounds
// zoom out to include the bounds
map.fitBounds(bounds.extend(map.getBounds()).pad(0.25), options);
} else {
// check if the point is hidden behind the options tabs (400px wide)
let mapLL = L.CRS.EPSG3857.latLngToPoint(map.getBounds().getSouthWest(), map.getZoom());
let boundsLL = L.CRS.EPSG3857.latLngToPoint(bounds.getSouthWest(), map.getZoom());
let diff = boundsLL.x - mapLL.x;
if(!map.getBounds().contains(bounds) || (tabs && (diff < 400)) ) {
// if the bounds aren't within the current map bounds
// zoom out to include the bounds
map.fitBounds(bounds.extend(map.getBounds()).pad(0.25), options);
}
}
}
function date2String(date) {
Expand Down

0 comments on commit cc1b157

Please sign in to comment.