Set bounds to default if the district doesn't have a service area
This commit is contained in:
parent
963254973b
commit
f1e4aca9b8
3 changed files with 21 additions and 14 deletions
|
|
@ -27,10 +27,8 @@ import {
|
|||
shallowRef,
|
||||
} from "vue";
|
||||
|
||||
import type { Bounds } from "@/type/api";
|
||||
|
||||
interface Props {
|
||||
bounds?: Bounds;
|
||||
bounds?: maplibregl.LngLatBounds;
|
||||
center?: maplibregl.LngLatLike;
|
||||
zoom?: number;
|
||||
}
|
||||
|
|
@ -88,6 +86,7 @@ function initializeMap() {
|
|||
|
||||
console.log("initializing map...");
|
||||
const _map = new maplibregl.Map({
|
||||
bounds: props.bounds,
|
||||
container: mapDiv.value,
|
||||
center: props.center,
|
||||
style: "https://tiles.stadiamaps.com/styles/alidade_smooth.json",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,20 @@
|
|||
import maplibregl from "maplibre-gl";
|
||||
import type { Marker } from "@/types";
|
||||
import type { Location } from "@/type/api";
|
||||
import type { Bounds, Location } from "@/type/api";
|
||||
|
||||
export function boundsDefault(): maplibregl.LngLatBounds {
|
||||
return new maplibregl.LngLatBounds(
|
||||
new maplibregl.LngLat(-125, 50),
|
||||
new maplibregl.LngLat(-70, 25),
|
||||
);
|
||||
}
|
||||
|
||||
export function boundsFromAPI(b: Bounds): maplibregl.LngLatBounds {
|
||||
return new maplibregl.LngLatBounds(
|
||||
new maplibregl.LngLat(b.min.longitude, b.max.latitude),
|
||||
new maplibregl.LngLat(b.max.longitude, b.min.latitude),
|
||||
);
|
||||
}
|
||||
|
||||
export function boundsMarkers(markers: Marker[]): maplibregl.LngLatBounds {
|
||||
let min_lat = 90;
|
||||
|
|
@ -18,13 +32,6 @@ export function boundsMarkers(markers: Marker[]): maplibregl.LngLatBounds {
|
|||
new maplibregl.LngLat(max_lng, max_lat),
|
||||
);
|
||||
}
|
||||
export function boundsDefault(): maplibregl.LngLatBounds {
|
||||
return new maplibregl.LngLatBounds(
|
||||
new maplibregl.LngLat(-125, 50),
|
||||
new maplibregl.LngLat(-70, 25),
|
||||
);
|
||||
}
|
||||
|
||||
// Helper functions (outside component)
|
||||
const getBoundingBox = (points: Location[]) => {
|
||||
if (!points || points.length === 0) {
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ import { onMounted, reactive } from "vue";
|
|||
import Map from "@/map/Map.vue";
|
||||
import Layer from "@/map/Layer.vue";
|
||||
import Source from "@/map/Source.vue";
|
||||
import { boundsDefault, boundsFromAPI } from "@/map/util";
|
||||
import { formatBigNumber, formatTimeRelative } from "@/format";
|
||||
import { router } from "@/route/config";
|
||||
import { useSessionStore } from "@/store/session";
|
||||
|
|
@ -269,11 +270,11 @@ onMounted(async () => {
|
|||
function doClickMap(cell: string) {
|
||||
router.push("/_/cell/" + cell);
|
||||
}
|
||||
function mapBounds(): Bounds | undefined {
|
||||
function mapBounds(): maplibregl.LngLatBounds {
|
||||
if (session.organization?.service_area) {
|
||||
return session.organization?.service_area;
|
||||
return boundsFromAPI(session.organization?.service_area);
|
||||
}
|
||||
return undefined;
|
||||
return boundsDefault();
|
||||
}
|
||||
function refreshData() {
|
||||
console.log("fake refresh");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue