Skip to content

Commit

Permalink
Fix panning
Browse files Browse the repository at this point in the history
Upgrade leaflet
Closes #81
  • Loading branch information
AlexMacocian committed Aug 11, 2024
1 parent 07c91f5 commit d6221f3
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 105 deletions.
38 changes: 28 additions & 10 deletions GuildWarsPartySearch.FrontEnd/Content/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ async function buildPartyList() {
}
}

async function navigateToLocation(mapObj) {
async function navigateToLocation(mapObj, showParties) {
for (const continentData of leafletData) {
if (!continentData.regions) {
continue;
Expand All @@ -967,9 +967,26 @@ async function navigateToLocation(mapObj) {
return;
}

var pixelBounds = map.getPixelBounds();
var desiredBounds = pixelBounds.getSize().divideBy(2);
var quarterSize = pixelBounds.getSize().divideBy(4);
var center = L.point(pixelBounds.min.x + desiredBounds.x, pixelBounds.min.y + desiredBounds.y)

var reducedPixelBounds = L.bounds(L.point(center.x - quarterSize.x, center.y - quarterSize.y), L.point(center.x + quarterSize.x, center.y + quarterSize.y));
if (reducedPixelBounds.contains(location.coordinates)) {
mapClicked(location);
return;
}

setURLParameter("navigating", "1");
map.panTo(location.coordinates);
mapClicked(location);
map.setView(location.coordinates, 2, { animate: true, duration: 1 });
await waitMillis(1000);
map.setZoom(map.getMaxZoom(), { animate: true, duration: 1 });
await waitMillis(1000);
if (showParties) {
mapClicked(location);
}
resetURLParameter("navigating");
return; // Assuming you only want to navigate to the first match
}
}
Expand All @@ -979,9 +996,7 @@ async function navigateToLocation(mapObj) {

function mapRowClicked(mapObj) {
window.location.hash = mapObj.name;
navigateToLocation(mapObj);
showPartyWindow();
buildPartyWindow();
navigateToLocation(mapObj, true);
}

function hidePartyWindowRows(rowType) {
Expand Down Expand Up @@ -1180,10 +1195,7 @@ function loadMap(mapIndex) {
}
}).on('click focus movestart', function () {
hideMenu();
if (getURLParameter("navigating") == "1") {
resetURLParameter("navigating");
}
else {
if (!getURLParameter("navigating") == "1") {
hidePartyWindow();
}
});
Expand Down Expand Up @@ -1427,6 +1439,12 @@ async function waitForLoaded(){
}
}

async function waitMillis(millis) {
return new Promise(resolve => {
setTimeout(resolve, millis);
});
}

function togglePartyWindow(){
document.querySelector("#partyWindow").classList.toggle("hidden");
}
Expand Down
6 changes: 3 additions & 3 deletions GuildWarsPartySearch.FrontEnd/Content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

<link href="stylesheet.css?v=20240809003" rel="stylesheet" />

<link rel="stylesheet" href="libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="libs/leaflet/1.9.4/leaflet.css" />
<link rel="stylesheet" href="libs/leaflet.draw/0.2.3/leaflet.draw.css" />

<script src="libs/leaflet/0.7.7/leaflet.js"></script>
<script src="libs/leaflet/1.9.4/leaflet.js"></script>
<script src="libs/moment/2.29.1/moment.min.js"></script>
<style>
</style>
Expand Down Expand Up @@ -86,6 +86,6 @@
</tbody>
</table>
</div>
<script src="app.js?v=20240811003"></script>
<script src="app.js?v=20240811004"></script>
</body>
</html>

This file was deleted.

Loading

0 comments on commit d6221f3

Please sign in to comment.