Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// analyze result of current depth
if (!curTzData) {
// no timezone in this quad, therefore must be timezone at sea
return getTimezoneAtSea(originalLon)
} else if (curTzData === 'f') {
// get exact boundaries
var geoJson = featureCache.get(quadPos)
if (!geoJson) {
geoJson = loadFeatures(quadPos)
featureCache.put(quadPos, geoJson)
}
var timezonesContainingPoint = []
for (var i = 0; i < geoJson.features.length; i++) {
if (inside(pt, geoJson.features[i])) {
timezonesContainingPoint.push(geoJson.features[i].properties.tzid)
}
}
// if at least one timezone contained the point, return those timezones,
// otherwise must be timezone at sea
return timezonesContainingPoint.length > 0
? timezonesContainingPoint
: getTimezoneAtSea(originalLon)
} else if (curTzData.length > 0) {
// exact match found
return curTzData.map(idx => tzData.timezones[idx])
} else if (typeof curTzData !== 'object') {
// not another nested quad index, throw error
err = new Error('Unexpected data type')
throw err
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'LineString') {
var distance = pointToLineDistance(centerPoint, geometry);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'Polygon') {
if (booleanPointInPolygon(centerPoint, geometry)) {
if (closestDistance != 0) {
closest = row;
closestDistance = 0;
}
} else {
var line = polygonToLine(geometry);
var distance = pointToLineDistance(centerPoint, line);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
}
}
}
}
closest.values.name.should.be.equal('point');
foundFeatures.should.be.deep.equal(['box1', 'box2', 'line', 'point']);
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'LineString') {
var distance = pointToLineDistance(centerPoint, geometry);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
} else if (distance == closestDistance && closest.type != 'Point') {
closest = row;
closestDistance = distance;
}
} else if (geometry.type == 'Polygon') {
if (booleanPointInPolygon(centerPoint, geometry)) {
if (closestDistance != 0) {
closest = row;
closestDistance = 0;
}
} else {
var line = polygonToLine(geometry);
var distance = pointToLineDistance(centerPoint, line);
if (distance < closestDistance) {
closest = row;
closestDistance = distance;
}
}
}
}
closest.properties.Name.should.be.equal('Rio Grande');
});
return;
}
let goal_layer = this.agentmap.units.getLayer(goal_place.id) || this.agentmap.streets.getLayer(goal_place.id);
//If the goal isn't unanchored, see if it's a street or a unit and schedule the agent appropriately.
if (goal_layer) {
let goal_coords = L.A.pointToCoordinateArray(goal_lat_lng);
//Buffering so that points on the perimeter, like the door, are captured.
//Also expands street lines into thin polygons (booleanPointInPolygon requires polys).
//Might be more efficient to generate the door so that it's slightly inside the area.
let goal_polygon = buffer(goal_layer.toGeoJSON(), .001);
if (booleanPointInPolygon(goal_coords, goal_polygon)) {
if (start_place.type === "unit" && goal_place.type === "unit" && start_place.id === goal_place.id) {
this.setTravelInUnit(goal_lat_lng, goal_place, speed);
return;
}
//Move to the street if it's starting at a unit and its goal is elsewhere.
else if (start_place.type === "unit") {
let start_unit_door = this.agentmap.getUnitDoor(start_place.id);
start_unit_door.new_place = start_place,
start_unit_door.speed = speed;
this.trip.path.push(start_unit_door);
let start_unit_street_id = this.agentmap.units.getLayer(start_place.id).street_id,
start_unit_street_point = this.agentmap.getStreetNearDoor(start_place.id);
start_unit_street_point.new_place = { type: "street", id: start_unit_street_id },
start_unit_street_point.speed = speed;
this.trip.path.push(start_unit_street_point);