Skip to content

Commit

Permalink
Merge pull request #21 from geoblocks/wip_search
Browse files Browse the repository at this point in the history
Search plugin
  • Loading branch information
tyrossel authored Nov 4, 2024
2 parents 72a445b + a7f39d6 commit 4bacc21
Show file tree
Hide file tree
Showing 27 changed files with 461 additions and 29 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default tseslint.config(
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
},
},
{
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"vite": "5.4.10"
},
"dependencies": {
"@shoelace-style/shoelace": "2.18.0"
"@shoelace-style/shoelace": "2.18.0",
"@types/geojson": "^7946.0.14"
}
}
3 changes: 3 additions & 0 deletions src/apps/custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Custom app

This app is a starting point for a fully custom app.
60 changes: 60 additions & 0 deletions src/apps/custom/customConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type {CustomConfig} from './ingv-config-custom.js';

export const config: CustomConfig = {
languages: ['fr', 'en'],
header: {
title: {
fr: 'Ma custom app',
en: 'My custom app',
},
searchContext: {
providers: [
{
type: 'geoadmin',
options: {
sr: '2056',
limit: 10,
},
},
{
type: 'nominatim',
options: {
limit: 10,
},
},
],
},
},
footer: {
contact: '[email protected]',
impressum: {
fr: 'Bla bla FR impressim',
en: 'Bla bla EN impressim',
},
},
app: {
cesiumContext: {
catalogs: {
'@geoadmin': () => import('../../catalogs/geoadminCatalog.js'),
},
layers: {
imageries: ['@geoadmin/pixel-karte-farbe'],
terrain: '@geoadmin/terrain',
},
quickLists: {
baseLayers: [
'@geoadmin/pixel-karte-farbe',
'@geodmin/pixel-karte-frau',
'@geoadmin/swissimage',
],
},
camera: {
position: [6.628484, 46.5, 1000],
orientation: {
heading: 0,
pitch: -30.0,
},
},
},
},
};
30 changes: 30 additions & 0 deletions src/apps/custom/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My custom application</title>
<!-- <link rel="stylesheet" href="./src/index.css" /> -->
<script type="module" src="./index.ts"></script>

<style>
/* FIXME: move to default style */
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
}
</style>
</head>
<body>
<noscript>Enable JS!</noscript>
<ngv-app-custom></ngv-app-custom>
</body>
</html>
35 changes: 35 additions & 0 deletions src/apps/custom/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type {HTMLTemplateResult} from 'lit';
import {html} from 'lit';
import {customElement} from 'lit/decorators.js';

import '../../structure/ngv-structure-app.js';

// // @ts-expect-error ?url parameter is a viteJS specificity
// import logoUrl from "../../logo.svg?url";
import {localized} from '@lit/localize';
import {ABaseApp} from '../../structure/BaseApp.js';

import './ngv-main-custom.js';

import type {CustomConfig} from './ingv-config-custom.js';

@customElement('ngv-app-custom')
@localized()
export class NgvAppCustom extends ABaseApp<CustomConfig> {
constructor() {
super(() => import('./customConfig.js'));
}

render(): HTMLTemplateResult {
const r = super.render();
if (r && !this.config) {
// todo check
return r;
}
return html`
<ngv-structure-app .config=${this.config}>
<ngv-main-custom .config=${this.config?.app}></ngv-main-custom>
</ngv-structure-app>
`;
}
}
8 changes: 8 additions & 0 deletions src/apps/custom/ingv-config-custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {IngvCesiumContext} from '../../interfaces/cesium/ingv-cesium-context.js';
import type {INgvStructureApp} from '../../structure/ngv-structure-app.js';

export interface CustomConfig extends INgvStructureApp {
app: {
cesiumContext: IngvCesiumContext;
};
}
22 changes: 22 additions & 0 deletions src/apps/custom/ngv-main-custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {customElement, property} from 'lit/decorators.js';
import type {HTMLTemplateResult} from 'lit';
import {html, LitElement} from 'lit';
import type {CustomConfig} from './ingv-config-custom.js';

import '../../plugins/cesium/ngv-plugin-cesium-widget.js';

@customElement('ngv-main-custom')
export class NgvMainCustom extends LitElement {
@property({type: Object})
config: CustomConfig['app'];

protected render(): HTMLTemplateResult {
return html` <div class="app-container">Nice app implementation</div> `;
}
}

declare global {
interface HTMLElementTagNameMap {
'ngv-main-custom': NgvMainCustom;
}
}
2 changes: 1 addition & 1 deletion src/apps/illumination/ingv-config-illumination.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js';
import type {IngvCesiumContext} from '../../interfaces/cesium/ingv-cesium-context.js';
import type {INgvStructureApp} from '../../structure/ngv-structure-app.js';

export interface IIlluminationConfig extends INgvStructureApp {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/permits/ingv-config-permits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js';
import type {IngvCesiumContext} from '../../interfaces/cesium/ingv-cesium-context.js';
import type {INgvStructureApp} from '../../structure/ngv-structure-app.js';

export interface IPermitsConfig extends INgvStructureApp {
Expand Down
2 changes: 1 addition & 1 deletion src/catalogs/cesiumCatalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {INGVCatalog} from '../interfaces/ingv-catalog.js';
import type {INGVCatalog} from '../interfaces/cesium/ingv-catalog.js';

export const catalog: INGVCatalog = {
id: '@cesium',
Expand Down
2 changes: 1 addition & 1 deletion src/catalogs/demoCatalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {INGVCatalog} from '../interfaces/ingv-catalog.js';
import type {INGVCatalog} from '../interfaces/cesium/ingv-catalog.js';

export const catalog: INGVCatalog = {
id: '@demo',
Expand Down
2 changes: 1 addition & 1 deletion src/catalogs/geoadminCatalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {INGVCatalog} from '../interfaces/ingv-catalog.js';
import type {INGVCatalog} from '../interfaces/cesium/ingv-catalog.js';

export const catalog: INGVCatalog = {
id: '@geoadmin',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/interfaces/search/ingv-search-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {INGVSearchProviderConfigs} from './ingv-search-provider.js';

export interface IngvSearchContext {
providers: INGVSearchProviderConfigs[];
}
68 changes: 68 additions & 0 deletions src/interfaces/search/ingv-search-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type {Geometry} from 'geojson';

/**
* To add a providers, you need to:
* 1. Create a new provider file in src/plugins/search/providers/ that implements the INGVSearchProvider interface
* 2. Add the provider to the getProvider function in src/plugins/search/ngv-search-providers.ts
* 3. Add the provider to the IngvSearchContext in src/interfaces/search/ingv-search-context.ts
*/

export interface INGVSearchResult {
title: string;

geom: Geometry;

// From which provider the result comes from
provider: string;

// The provider-specific category, if provided
category?: string | null;

extra?: Record<string, any>;
}

export interface INGVGeoAdminSearchProviderConfig {
type: 'geoadmin';

options?: {
sr?: string;
limit?: number;
locationOrigins?: string;
};
}

export function isGeoAdminSearchProvider(
config: INGVSearchProviderConfigs,
): config is INGVGeoAdminSearchProviderConfig {
return config.type === 'geoadmin';
}

export interface INGVNominatimSearchProviderConfig {
type: 'nominatim';

options?: {
/** URL to the Nominatim search API. The following placeholders are supported:
* - `{input}`: the search query
* - `{lang}`: the language code
* - `{limit}`: see below
*/
url?: string;

/** Maximum number of results to return */
limit?: number;
};
}
export function isNominatimSearchProvider(
config: INGVSearchProviderConfigs,
): config is INGVNominatimSearchProviderConfig {
return config.type === 'nominatim';
}

// Unions of all possible configs
export type INGVSearchProviderConfigs =
| INGVGeoAdminSearchProviderConfig
| INGVNominatimSearchProviderConfig;

export interface INGVSearchProvider {
search: (input: string, lang: string) => Promise<INGVSearchResult[]>;
}
6 changes: 3 additions & 3 deletions src/plugins/cesium/ngv-cesium-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import type {
INGVCesiumImageryTypes,
INGVCesiumTerrain,
INGVIFC,
} from 'src/interfaces/ingv-layers.js';
} from '../../interfaces/cesium/ingv-layers.js';
import {
Cesium3DTileset,
CesiumTerrainProvider,
UrlTemplateImageryProvider,
WebMapServiceImageryProvider,
WebMapTileServiceImageryProvider,
} from '@cesium/engine';
import type {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js';
import type {INGVCatalog} from 'src/interfaces/ingv-catalog.js';
import type {IngvCesiumContext} from '../../interfaces/cesium/ingv-cesium-context.js';
import type {INGVCatalog} from '../../interfaces/cesium/ingv-catalog.js';

function withExtra<T>(options: T, extra: Record<string, any>): T {
if (!extra) {
Expand Down
31 changes: 16 additions & 15 deletions src/plugins/cesium/ngv-plugin-cesium-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ import {customElement, property, query} from 'lit/decorators.js';

// @ts-expect-error Vite specific ?inline parameter
import style from '@cesium/engine/Source/Widget/CesiumWidget.css?inline';
import type {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js';
import type {IngvCesiumContext} from '../../interfaces/cesium/ingv-cesium-context.js';
import type {CesiumWidget, Model} from '@cesium/engine';
import {initCesiumWidget} from './ngv-cesium-factories.js';

@customElement('ngv-plugin-cesium-widget')
export class NgvPluginCesiumWidget extends LitElement {
public viewer: CesiumWidget;

static styles = css`
${unsafeCSS(style)}
static styles = [
unsafeCSS(style),
css`
#globe {
width: 100%;
height: 100%;
}
#globe {
width: 100%;
height: 100%;
}
.cesium-widget canvas {
position: absolute;
}
.cesium-widget canvas {
position: absolute;
}
.cesium-credit-logoContainer {
display: none !important;
}
`;
.cesium-credit-logoContainer {
display: none !important;
}
`,
];

@property({type: Object})
cesiumContext: IngvCesiumContext;
Expand Down
Loading

0 comments on commit 4bacc21

Please sign in to comment.