// The MIT License (MIT)
//
// Copyright (c) 2022-2024 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import {html, TemplateResult, unsafeCSS, CSSResult, css} from 'lit';
import {customElement, state} from 'lit/decorators.js';
import i18next from 'i18next';
import 'bootstrap/js/src/tooltip';
import gmfLidarprofileConfig from 'ngeo/lidar/Config';
import gmfLidarprofileManager from 'ngeo/lidar/Manager';
import {LidarprofileConfigService} from 'ngeo/lidar/Config';
import {LidarprofileManager} from 'ngeo/lidar/Manager';
import {
LidarprofileServerConfigPointAttributes,
LidarprofileServerConfigPointAttribute,
LidarprofileServerConfigClassifications,
LidarprofileServerConfigClassification,
} from 'ngeo/lidar/Config';
import OlMap from 'ol/Map';
import OlGeomLineString from 'ol/geom/LineString';
import DownloadCsvService from 'ngeo/download/Csv';
import GmfDrawLine from './DrawLineComponent';
import {Configuration} from 'gmfapi/store/config';
import line from 'ngeo/lidar/line';
import map from 'gmfapi/store/map';
import panels from 'gmfapi/store/panels';
import ToolPanelElement from 'gmfapi/elements/ToolPanelElement';
@customElement('gmf-lidar-panel')
export default class GmfLidarPanel extends ToolPanelElement {
@state() private customCSS_ = '';
@state() private profileConfig_: LidarprofileConfigService = null;
@state() private profile: LidarprofileManager = null;
@state() private ready = false;
@state() private active = false;
@state() private map: undefined | OlMap = null;
@state() private drawlineClass = '';
// The OpenLayers LineString geometry of the profle
@state() private line: undefined | OlGeomLineString = null;
@state() private classifications: LidarprofileServerConfigClassifications = [];
@state() private availablePointAttributes: LidarprofileServerConfigPointAttributes[] = [];
connectedCallback(): void {
this.initSubscribe();
super.connectedCallback();
}
// Subscribe and initialize all properties
initSubscribe(): void {
this.profile = gmfLidarprofileManager;
this.profileConfig_ = gmfLidarprofileConfig;
this.subscriptions.push(
line.getLine().subscribe({
next: (line: OlGeomLineString) => {
this.line = line;
if (line) {
this.drawlineClass = '';
this.update_();
} else {
this.clearAll();
}
},
}),
);
this.subscriptions.push(
map.getMap().subscribe({
next: (map: OlMap) => {
if (map) {
this.map = map;
this.profile.init(this.profileConfig_, this.map);
}
},
}),
);
this.subscriptions.push(
panels.getActiveToolPanel().subscribe({
next: (panel: string) => {
this.active = panel === 'lidar';
if (this.active) {
// Set the drawline button class to active
this.drawlineClass = 'active';
this.updateEventsListening_(this.active);
} else {
line.setLine(null);
}
},
}),
);
}
// Override default initConfig
initConfig(configuration: Configuration): void {
if (configuration.gmfCustomCSS && configuration.gmfCustomCSS.lidarPanel !== undefined) {
this.customCSS_ = configuration.gmfCustomCSS.lidarPanel;
}
}
static styles: CSSResult[] = [
...ToolPanelElement.styles,
css`
.btn.btn-default {
background-color: var(--map-tools-bg-color);
border-color: var(--onhover-color);
color: var(--map-tools-color);
}
.btn.btn-default.active {
box-shadow: inset 0 0.37rem 0.75rem var(--light-box-shadow-color);
}
.btn.btn-default:hover,
.btn.btn-default.active {
background-color: var(--onhover-color);
border-color: var(--onhover-color-darken);
}
`,
];
protected render(): TemplateResult {
return html`
${this.getTitle(i18next.t('LIDAR profile'))}
${GmfDrawLine.interaction.getActive()
? html`
${i18next.t(
'Draw a line on the map to display the corresponding LIDAR profile. Use double-click to finish the drawing.',
)}
`
: html``}