Skip to content

Commit

Permalink
Cleanup buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Jul 31, 2024
1 parent 98bde80 commit feb285b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
22 changes: 12 additions & 10 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function isValidEntityInfo(entityInfo) {
}

function compositeGeoJson(features) {
if (!features.length) return;
var coordinates = [];
features.forEach(function(feature) {
if (feature.geometry.type === 'Polygon') {
Expand All @@ -230,18 +231,18 @@ function compositeGeoJson(features) {
coordinates = coordinates.concat(feature.geometry.coordinates);
}
});
var unbuffered = {
return {
type: "Feature",
geometry: {
type: "MultiPolygon",
coordinates: coordinates,
},
properties: features.length ? features[0].properties : {}
properties: features[0].properties
};
return coordinates.length ? turfBuffer.buffer(unbuffered, 0.25, {units: 'kilometers'}) : unbuffered;
}

var focusAreaGeoJson;
var focusAreaGeoJsonBuffered;
var focusAreaBoundingBox;

function buildFocusAreaGeoJson() {
Expand All @@ -267,14 +268,16 @@ function buildFocusAreaGeoJson() {
}
function loadFocusArea() {
focusAreaGeoJson = buildFocusAreaGeoJson();
focusAreaGeoJsonBuffered = focusAreaGeoJson?.geometry?.coordinates?.length ? turfBuffer.buffer(focusAreaGeoJson, 0.25, {units: 'kilometers'}) : focusAreaGeoJson;
focusAreaBoundingBox = bboxOfGeoJson(focusAreaGeoJson);
var maxBbox = focusAreaBoundingBox;
var fitBbox = focusAreaBoundingBox;
if (focusAreaBoundingBox) {
var width = focusAreaBoundingBox[2] - focusAreaBoundingBox[0];
var height = focusAreaBoundingBox[3] - focusAreaBoundingBox[1];
maxBbox = extendBbox(focusAreaBoundingBox, Math.max(width, height));
fitBbox = extendBbox(focusAreaBoundingBox, Math.max(width, height) / 10);
var maxExtent = Math.max(width, height);
maxBbox = extendBbox(focusAreaBoundingBox, maxExtent);
fitBbox = extendBbox(focusAreaBoundingBox, maxExtent / 16);
}
map.setMaxBounds(maxBbox);
if (fitBbox) map.fitBounds(fitBbox);
Expand All @@ -301,16 +304,15 @@ function focusEntity(entityInfo) {
updateTrailLayers();

document.getElementById("map-title").innerText = '';
document.getElementById("focus-meta").style.display = focusedEntityInfo ? 'flex' : 'none';

if (focusedEntityInfo) {
document.getElementById("focus-meta").style.display = 'flex';
fetchOsmEntity(type, entityId).then(function(entity) {
if (focusAreaGeoJson) document.getElementById("map-title").innerText = focusAreaGeoJson.properties.name;
/*fetchOsmEntity(type, entityId).then(function(entity) {
if (entity?.tags?.name) {
document.getElementById("map-title").innerText = entity.tags.name;
}
});
} else {
document.getElementById("focus-meta").style.display = 'none';
});*/
}
}

Expand Down
16 changes: 8 additions & 8 deletions js/mapController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,8 @@ function isSpecifiedExpressionForLens(lens, travelMode) {

function waterTrailPoisFilter(travelMode) {
var filter = ["all"];
if (focusAreaGeoJson?.geometry?.coordinates?.length) {
filter.push(["within", focusAreaGeoJson]);
if (focusAreaGeoJsonBuffered?.geometry?.coordinates?.length) {
filter.push(["within", focusAreaGeoJsonBuffered]);
}
if (travelMode !== "canoe") {
filter.push([
Expand All @@ -1028,8 +1028,8 @@ function trailPoisFilter(travelMode) {
]
],
]
if (focusAreaGeoJson?.geometry?.coordinates?.length) {
filter.push(["within", focusAreaGeoJson]);
if (focusAreaGeoJsonBuffered?.geometry?.coordinates?.length) {
filter.push(["within", focusAreaGeoJsonBuffered]);
}
if (travelMode !== 'all') {
var poiKeys = [travelMode];
Expand Down Expand Up @@ -1394,15 +1394,15 @@ function updateTrailLayers() {
['in', ["get", "boundary"], ["literal", ["protected_area", "national_park"]]]
],
["!=", ["get", "OSM_ID"], focusedEntityInfo ? focusedEntityInfo.id : null],
...(focusAreaGeoJson?.geometry?.coordinates?.length ?
focusAreaFilter = [["within", focusAreaGeoJson]] : []),
...(focusAreaGeoJsonBuffered?.geometry?.coordinates?.length ?
focusAreaFilter = [["within", focusAreaGeoJsonBuffered]] : []),
])
.setFilter('peaks', [
"all",
["has", "name"],
["has", "ele_ft"],
...(focusAreaGeoJson?.geometry?.coordinates?.length ?
focusAreaFilter = [["within", focusAreaGeoJson]] : []),
...(focusAreaGeoJsonBuffered?.geometry?.coordinates?.length ?
focusAreaFilter = [["within", focusAreaGeoJsonBuffered]] : []),
]);

function setParksFilter(layer, filter) {
Expand Down

0 comments on commit feb285b

Please sign in to comment.