import { FindOnMapResult , SearchResult } from "facilmap-types" ; import { numberKeys } from "facilmap-utils" ; import { isEqual } from "lodash" ; import { Client } from "./decorators" ; import { FileResult , FileResultObject } from "./files" ; const VIEW_KEYS = [ "name" , "baseLayer" , "layers" , "top" , "bottom" , "left" , "right" , "filter" ] ; const TYPE_KEYS = [ "name" , "type" , "defaultColour" , "colourFixed" , "defaultSize" , "sizeFixed" , "defaultSymbol" , "symbolFixed" , "defaultShape" , "shapeFixed" , "defaultWidth" , "widthFixed" , "defaultMode" , "modeFixed" , "fields" ] ; export function isSearchResult ( result ) { return ! isMapResult ( result ) && ! isFileResult ( result ) ; } export function isMapResult ( result ) { return "kind" in result ; } export function isFileResult ( result ) { return "isFileResult" in result && result . isFileResult ; } export function isMarkerResult ( result ) { if ( isMapResult ( result ) ) return result . kind == "marker" ; else return ( result . lat != null && result . lon != null ) || ( ! ! result . geojson && result . geojson . type == "Point" ) ; } export function isLineResult ( result ) { if ( isMapResult ( result ) ) return result . kind == "line" ; else return ! ! result . geojson && [ "LineString" , "MultiLineString" , "Polygon" , "MultiPolygon" ] . includes ( result . geojson . type ) ; } export function viewExists ( client , view ) { for ( const viewId of numberKeys ( client . views ) ) { if ( ! VIEW_KEYS . some ( ( idx ) => ! isEqual ( view [ idx ] , client . views [ viewId ] [ idx ] ) ) ) return true ; } return false ; } export function typeExists ( client , type ) { for ( const typeId of numberKeys ( client . types ) ) { if ( ! TYPE_KEYS . some ( ( idx ) => ! isEqual ( type [ idx ] , client . types [ typeId ] [ idx ] ) ) ) return true ; } return false ; }