forked from jsnbuchanan/crowd-funder-for-time-pwa
load the projects on the map on initial load
This commit is contained in:
@@ -118,9 +118,10 @@
|
|||||||
<div v-if="isMappedActive">
|
<div v-if="isMappedActive">
|
||||||
<div class="mt-4 h-96 w-5/6 mx-auto">
|
<div class="mt-4 h-96 w-5/6 mx-auto">
|
||||||
<l-map
|
<l-map
|
||||||
ref="map"
|
ref="projectMap"
|
||||||
:center="[localCenterLat, localCenterLong]"
|
:center="[localCenterLat, localCenterLong]"
|
||||||
:zoom="2"
|
:zoom="2"
|
||||||
|
@ready="onMapReady"
|
||||||
@moveend="onMoveEnd"
|
@moveend="onMoveEnd"
|
||||||
@zoomend="onZoomEnd"
|
@zoomend="onZoomEnd"
|
||||||
@zoomstart="onZoomStart"
|
@zoomstart="onZoomStart"
|
||||||
@@ -147,7 +148,9 @@
|
|||||||
<span v-if="searchBox"> None found in the selected area. </span>
|
<span v-if="searchBox"> None found in the selected area. </span>
|
||||||
<!-- Otherwise there's no search area selected so we'll just leave the search box for them to click. -->
|
<!-- Otherwise there's no search area selected so we'll just leave the search box for them to click. -->
|
||||||
</span>
|
</span>
|
||||||
<span v-else-if="isRemoteActive">No projects were found with that search.</span>
|
<span v-else-if="isRemoteActive"
|
||||||
|
>No projects were found with that search.</span
|
||||||
|
>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -190,14 +193,9 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import "leaflet/dist/leaflet.css";
|
import "leaflet/dist/leaflet.css";
|
||||||
import { Map } from "leaflet";
|
|
||||||
import * as L from "leaflet";
|
import * as L from "leaflet";
|
||||||
import { Component, Vue } from "vue-facing-decorator";
|
import { Component, Vue } from "vue-facing-decorator";
|
||||||
import {
|
import { LMap, LTileLayer } from "@vue-leaflet/vue-leaflet";
|
||||||
LMap,
|
|
||||||
LTileLayer,
|
|
||||||
LMarker,
|
|
||||||
} from "@vue-leaflet/vue-leaflet";
|
|
||||||
import { Router } from "vue-router";
|
import { Router } from "vue-router";
|
||||||
|
|
||||||
import QuickNav from "@/components/QuickNav.vue";
|
import QuickNav from "@/components/QuickNav.vue";
|
||||||
@@ -206,12 +204,20 @@ import ProjectIcon from "@/components/ProjectIcon.vue";
|
|||||||
import OnboardingDialog from "@/components/OnboardingDialog.vue";
|
import OnboardingDialog from "@/components/OnboardingDialog.vue";
|
||||||
import TopMessage from "@/components/TopMessage.vue";
|
import TopMessage from "@/components/TopMessage.vue";
|
||||||
import { NotificationIface } from "@/constants/app";
|
import { NotificationIface } from "@/constants/app";
|
||||||
import { db, retrieveSettingsForActiveAccount } from "@/db/index";
|
import {
|
||||||
|
db,
|
||||||
|
logConsoleAndDb,
|
||||||
|
retrieveSettingsForActiveAccount,
|
||||||
|
} from "@/db/index";
|
||||||
import { Contact } from "@/db/tables/contacts";
|
import { Contact } from "@/db/tables/contacts";
|
||||||
import { BoundingBox } from "@/db/tables/settings";
|
import { BoundingBox } from "@/db/tables/settings";
|
||||||
import { didInfo, getHeaders, PlanData } from "@/libs/endorserServer";
|
import {
|
||||||
|
didInfo,
|
||||||
|
errorStringForLog,
|
||||||
|
getHeaders,
|
||||||
|
PlanData,
|
||||||
|
} from "@/libs/endorserServer";
|
||||||
import { OnboardPage, retrieveAccountDids } from "@/libs/util";
|
import { OnboardPage, retrieveAccountDids } from "@/libs/util";
|
||||||
import { LocationEvent } from "leaflet";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
@@ -484,36 +490,47 @@ export default class DiscoverView extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onMoveEnd(event: LocationEvent) {
|
async onMapReady(map: L.Map) {
|
||||||
|
this.requestTiles(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tried but failed to use other vue-leaflet methods update:zoom and update:bounds
|
||||||
|
// To access the from this.$refs, use this.$refs.projectMap.mapObject
|
||||||
|
|
||||||
|
async onMoveEnd(event: L.LocationEvent) {
|
||||||
if (this.zoomedSoDoNotMove) {
|
if (this.zoomedSoDoNotMove) {
|
||||||
|
// since a zoom triggers a moveend, too, don't duplicate a tile request
|
||||||
this.zoomedSoDoNotMove = false;
|
this.zoomedSoDoNotMove = false;
|
||||||
} else {
|
} else {
|
||||||
// not part of a zoom so request tiles
|
// not part of a zoom so request tiles
|
||||||
await this.requestTiles(event);
|
await this.requestTiles(event.target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onZoomEnd(event: LocationEvent) {
|
async onZoomEnd(event: L.LocationEvent) {
|
||||||
await this.requestTiles(event);
|
await this.requestTiles(event.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
onZoomStart(event: LocationEvent) {
|
onZoomStart(/* event: L.LocationEvent */) {
|
||||||
this.zoomedSoDoNotMove = true;
|
this.zoomedSoDoNotMove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async requestTiles(event: LocationEvent) {
|
async requestTiles(targetMap: L.Map) {
|
||||||
const bounds = event.target.getBounds();
|
try {
|
||||||
|
const bounds = targetMap.getBounds();
|
||||||
const queryParams = [
|
const queryParams = [
|
||||||
"minLocLat=" + bounds?.getSouthWest().lat,
|
"minLocLat=" + bounds?.getSouthWest().lat,
|
||||||
"maxLocLat=" + bounds?.getNorthEast().lat,
|
"maxLocLat=" + bounds?.getNorthEast().lat,
|
||||||
"westLocLon=" + bounds?.getSouthWest().lng,
|
"westLocLon=" + bounds?.getSouthWest().lng,
|
||||||
"eastLocLon=" + bounds?.getNorthEast().lng,
|
"eastLocLon=" + bounds?.getNorthEast().lng,
|
||||||
].join("&");
|
].join("&");
|
||||||
const response = await fetch(this.apiServer + "/api/v2/report/planCountsByBBox?" + queryParams);
|
const response = await fetch(
|
||||||
|
this.apiServer + "/api/v2/report/planCountsByBBox?" + queryParams,
|
||||||
|
);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const results = await response.json();
|
const results = await response.json();
|
||||||
if (results.data?.tiles?.length > 0) {
|
if (results.data?.tiles?.length > 0) {
|
||||||
Object.values(this.markers).forEach(marker => marker.remove());
|
Object.values(this.markers).forEach((marker) => marker.remove());
|
||||||
this.markers = {};
|
this.markers = {};
|
||||||
for (const tile of results.data.tiles) {
|
for (const tile of results.data.tiles) {
|
||||||
const pinLat = (tile.minFoundLat + tile.maxFoundLat) / 2;
|
const pinLat = (tile.minFoundLat + tile.maxFoundLat) / 2;
|
||||||
@@ -522,13 +539,40 @@ export default class DiscoverView extends Vue {
|
|||||||
className: "numbered-marker",
|
className: "numbered-marker",
|
||||||
html: `<strong>${tile.recordCount}</strong>`,
|
html: `<strong>${tile.recordCount}</strong>`,
|
||||||
iconSize: [24, 24],
|
iconSize: [24, 24],
|
||||||
|
// Why isn't this showing?
|
||||||
iconAnchor: [12, 12], // coordinates of the tip of the icon relative to the top-left corner of the icon
|
iconAnchor: [12, 12], // coordinates of the tip of the icon relative to the top-left corner of the icon
|
||||||
});
|
});
|
||||||
const marker = L.marker([pinLat, pinLon], { icon: numberIcon });
|
const marker = L.marker([pinLat, pinLon], { icon: numberIcon });
|
||||||
marker.addTo(event.target);
|
marker.addTo(targetMap);
|
||||||
this.markers["" + tile.indexLat + "x" + tile.indexLon] = marker;
|
this.markers[
|
||||||
|
"" + tile.indexLat + "X" + tile.indexLon + "*" + tile.recordCount
|
||||||
|
] = marker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw {
|
||||||
|
message: "Got an error loading projects on the map.",
|
||||||
|
response: {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
url: response.url,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logConsoleAndDb(
|
||||||
|
"Error loading projects on the map: " + errorStringForLog(e),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Map Error",
|
||||||
|
text: "There was a problem loading projects on the map.",
|
||||||
|
},
|
||||||
|
3000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user