All files / src/app/map/maps-database utils.ts

75% Statements 3/4
50% Branches 2/4
0% Functions 0/1
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                            1x     1x         1x                        
import { loadModules } from 'esri-loader';
 
/**
 * Interface representing maps in the format saved on the maps server.
 */
export interface ABAMap {
  uid: number;
  title: string;
  city: 0 | 1;
  creationDate: string;
  height?: number;
  width?: number;
  extent?: string;
  graphics?: string;
}
 
/**
 * Interface representing maps in the format used by the application
 * with the ArcGIS Js API.
 */
export interface EsriMap {
  uid?: number;
  title: string;
  city: 0 | 1;
  height: number;
  width: number;
  extent: __esri.Extent;
  graphics: __esri.Graphic[];
}
 
/**
 * Transform an ABAMap to an EsriMap.
 *
 * @param abaMap The ABAMap to transform to an EsriMap.
 *
 * @returns An EsriMap containing the transformed data from the input ABAMap.
 */
export async function ABAToEsriMap(abaMap: ABAMap): Promise<EsriMap> {
  const [
    Extent,
    Graphic
  ] = await loadModules([
    'esri/geometry/Extent',
    'esri/Graphic'
  ]);
 
  return {
    uid: abaMap.uid,
    title: abaMap.title,
    city: abaMap.city,
    height: abaMap.height,
    width: abaMap.width,
    extent: abaMap.extent ? Extent.fromJSON(JSON.parse(abaMap.extent)) : new Extent(),
    graphics: abaMap.graphics ? JSON.parse(abaMap.graphics).map(
      (graphic: any) => Graphic.fromJSON(graphic)
    ) : []
  } as EsriMap;
}