Rename MapMarkerResponseDtoDecorator to MapMarkerResponse
This commit is contained in:
parent
3e47ca3815
commit
778ee8175e
3 changed files with 14 additions and 18 deletions
|
@ -95,23 +95,19 @@ export type MapMarkerResponseDto = [
|
|||
string
|
||||
];
|
||||
|
||||
export class MapMarkerResponseDtoDecorator {
|
||||
export class MapMarkerResponse {
|
||||
constructor(private lat: number, private lon: number, private assetId: string | null) {}
|
||||
|
||||
static from(response: object): MapMarkerResponseDtoDecorator {
|
||||
static from(response: object): MapMarkerResponse {
|
||||
const responseArray = response as MapMarkerResponseDto;
|
||||
|
||||
const assetId = responseArray.length === 3 ? responseArray[2] : null;
|
||||
|
||||
return new MapMarkerResponseDtoDecorator(
|
||||
responseArray[0] as number,
|
||||
responseArray[1] as number,
|
||||
assetId
|
||||
);
|
||||
return new MapMarkerResponse(responseArray[0] as number, responseArray[1] as number, assetId);
|
||||
}
|
||||
|
||||
static fromMany(responses: object[]): MapMarkerResponseDtoDecorator[] {
|
||||
return responses.map(MapMarkerResponseDtoDecorator.from);
|
||||
static fromMany(responses: object[]): MapMarkerResponse[] {
|
||||
return responses.map(MapMarkerResponse.from);
|
||||
}
|
||||
|
||||
public getAssetId(): string | null {
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
import { MarkerClusterGroup, Marker, Icon, LeafletEvent } from 'leaflet';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { getMapContext } from './map.svelte';
|
||||
import { MapMarkerResponseDtoDecorator, api } from '@api';
|
||||
import { MapMarkerResponse, api } from '@api';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
class AssetMarker extends Marker {
|
||||
marker: MapMarkerResponseDtoDecorator;
|
||||
marker: MapMarkerResponse;
|
||||
|
||||
constructor(marker: MapMarkerResponseDtoDecorator) {
|
||||
constructor(marker: MapMarkerResponse) {
|
||||
const markerAssetId = marker.getAssetId();
|
||||
|
||||
super(marker.getLatLon(), {
|
||||
|
@ -40,7 +40,7 @@
|
|||
|
||||
const map = getMapContext();
|
||||
|
||||
function setUpCluster(markers: MapMarkerResponseDtoDecorator[]) {
|
||||
function setUpCluster(markers: MapMarkerResponse[]) {
|
||||
cluster = new MarkerClusterGroup({
|
||||
showCoverageOnHover: false,
|
||||
zoomToBoundsOnClick: false,
|
||||
|
@ -80,7 +80,7 @@
|
|||
|
||||
onMount(() => setUpCluster(markers));
|
||||
|
||||
export let markers: MapMarkerResponseDtoDecorator[];
|
||||
export let markers: MapMarkerResponse[];
|
||||
$: {
|
||||
if (cluster) {
|
||||
cluster.remove();
|
||||
|
|
|
@ -8,24 +8,24 @@
|
|||
isViewingAssetStoreState,
|
||||
viewingAssetStoreState
|
||||
} from '$lib/stores/asset-interaction.store';
|
||||
import { api, MapMarkerResponseDtoDecorator } from '@api';
|
||||
import { api, MapMarkerResponse } from '@api';
|
||||
import { onMount } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
export let data: PageData;
|
||||
let mapMarkers: MapMarkerResponseDtoDecorator[] = [];
|
||||
let mapMarkers: MapMarkerResponse[] = [];
|
||||
|
||||
let initialMapCenter: [number, number] = [48, 11];
|
||||
|
||||
onMount(async () => {
|
||||
mapMarkers = MapMarkerResponseDtoDecorator.fromMany(data.mapMarkers);
|
||||
mapMarkers = MapMarkerResponse.fromMany(data.mapMarkers);
|
||||
|
||||
if (mapMarkers.length) {
|
||||
initialMapCenter = mapMarkers[0].getLatLon();
|
||||
}
|
||||
|
||||
const markersResponse = (await api.assetApi.getMapMarkers()).data;
|
||||
mapMarkers = MapMarkerResponseDtoDecorator.fromMany(markersResponse);
|
||||
mapMarkers = MapMarkerResponse.fromMany(markersResponse);
|
||||
});
|
||||
|
||||
let viewingAssets: string[] = [];
|
||||
|
|
Loading…
Reference in a new issue