diff --git a/base_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js b/base_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js index 58070075a3..f94fa52330 100644 --- a/base_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js +++ b/base_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js @@ -4,16 +4,16 @@ * Copyright 2023 ACSONE SA/NV */ -import {loadBundle, templates} from "@web/core/assets"; -import {GeoengineRecord} from "../geoengine_record/geoengine_record.esm"; -import {LayersPanel} from "../layers_panel/layers_panel.esm"; -import {RecordsPanel} from "../records_panel/records_panel.esm"; -import {rasterLayersStore} from "../../../raster_layers_store.esm"; -import {vectorLayersStore} from "../../../vector_layers_store.esm"; -import {useService, useOwnedDialogs} from "@web/core/utils/hooks"; -import {registry} from "@web/core/registry"; -import {RelationalModel} from "@web/views/relational_model"; -import {evaluateExpr} from "@web/core/py_js/py"; +import { loadBundle, templates } from "@web/core/assets"; +import { GeoengineRecord } from "../geoengine_record/geoengine_record.esm"; +import { LayersPanel } from "../layers_panel/layers_panel.esm"; +import { RecordsPanel } from "../records_panel/records_panel.esm"; +import { rasterLayersStore } from "../../../raster_layers_store.esm"; +import { vectorLayersStore } from "../../../vector_layers_store.esm"; +import { useService, useOwnedDialogs } from "@web/core/utils/hooks"; +import { registry } from "@web/core/registry"; +import { RelationalModel } from "@web/views/relational_model"; +import { evaluateExpr } from "@web/core/py_js/py"; import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog"; @@ -40,7 +40,7 @@ const LEGEND_MAX_ITEMS = 10; export class GeoengineRenderer extends Component { setup() { - this.state = useState({selectedFeatures: [], isModified: false, isFit: false}); + this.state = useState({ selectedFeatures: [], isModified: false, isFit: false }); this.models = []; this.cfg_models = []; this.vectorModel = {}; @@ -57,8 +57,8 @@ export class GeoengineRenderer extends Component { this.orm = useService("orm"); this.view = useService("view"); this.user = useService("user"); - - this.addDialog = useOwnedDialogs(); + + this.addDialog = useOwnedDialogs(); // For related model we need to load all the service needed by RelationalModel @@ -169,7 +169,7 @@ export class GeoengineRenderer extends Component { createBackgroundLayers(backgrounds) { const source = []; - source.push(new ol.layer.Tile({source: new ol.source.OSM()})); + source.push(new ol.layer.Tile({ source: new ol.source.OSM() })); const backgroundLayers = backgrounds.map((background) => { switch (background.raster_type) { case "osm": @@ -180,7 +180,7 @@ export class GeoengineRenderer extends Component { source: new ol.source.OSM(), }); case "wmts": - const {source_opt, tilegrid_opt, layer_opt} = + const { source_opt, tilegrid_opt, layer_opt } = this.createOptions(background); this.getUrl(background, source_opt); if (background.format_suffix) { @@ -263,7 +263,7 @@ export class GeoengineRenderer extends Component { type: "base", style: "default", }; - return {source_opt, tilegrid_opt, layer_opt}; + return { source_opt, tilegrid_opt, layer_opt }; } /** @@ -280,7 +280,7 @@ export class GeoengineRenderer extends Component { } createEditControl() { - const {element, button} = this.createHtmlControl( + const { element, button } = this.createHtmlControl( '', "edit-control ol-unselectable ol-control" ); @@ -326,7 +326,7 @@ export class GeoengineRenderer extends Component { } createDrawControl() { - const {element, button} = this.createHtmlControl( + const { element, button } = this.createHtmlControl( '', "draw-control ol-unselectable ol-control" ); @@ -368,7 +368,7 @@ export class GeoengineRenderer extends Component { } createSelectControl() { - const {element, button} = this.createHtmlControl( + const { element, button } = this.createHtmlControl( '', "select-control ol-unselectable ol-control" ); @@ -433,7 +433,7 @@ export class GeoengineRenderer extends Component { const element = document.createElement("div"); element.className = className; element.appendChild(button); - return {element, button}; + return { element, button }; } /** @@ -547,7 +547,7 @@ export class GeoengineRenderer extends Component { * @param {*} attributes * @param {*} record */ - mountGeoengineRecord({popup, archInfo, templateDocs, model, attributes, record}) { + mountGeoengineRecord({ popup, archInfo, templateDocs, model, attributes, record }) { this.record = record === undefined ? model.records.find((record) => record._values.id === attributes.id) @@ -567,70 +567,70 @@ export class GeoengineRenderer extends Component { * When you click on a record in the RecordsPanel, this method is called to display the popup. * @param {*} record */ - onDisplayPopupRecord(record) { - const popup = this.getPopup(); - const feature = this.vectorSource.getFeatureById(record.resId); - - if (feature) { - this.overlay.setVisible(false); - - this.mountGeoengineRecord({ - popup, - archInfo: this.props.archInfo, - templateDocs: this.props.archInfo.templateDocs, - record, - }); - var coord = ol.extent.getCenter(feature.getGeometry().getExtent()); - this.overlay.setPosition(coord); - var map_view = this.map.getView(); - if (map_view) { - map_view.animate({ - center: feature.getGeometry().getFirstCoordinate(), - duration: 500, - }); - } - } else { - this.overlay.setVisible(false); - const body = "No geometry. Would you like to add geometry?"; - this.openConformationDialog(body, () => this.openEditRecord(record)); - } - } - - openEditRecord(record) { - const formDialogProps = { - resModel: record.resModel, - resId: record.resId, - title: this.env._t("Edit Record"), - context: {}, - onRecordSaved: async () => { - const offset = record.model.root.count + 1; - await record.model.root.load({ offset }); - this.render(true); - }, - }; - - this.addDialog(FormViewDialog, formDialogProps); - } - - openConformationDialog(body, callback) { - const conformationDialogProps = { - body: this.env._t(body), - confirm: callback, - cancel: () => { - return; - }, - }; - - this.addDialog(ConfirmationDialog, conformationDialogProps); - } - - zoomOnFeature(record) { - const feature = this.vectorSource.getFeatureById(record.resId); - var map_view = this.map.getView(); - if (map_view && feature) { - map_view.fit(feature.getGeometry(), { maxZoom: 14 }); - } - } + onDisplayPopupRecord(record) { + const popup = this.getPopup(); + const feature = this.vectorSource.getFeatureById(record.resId); + + if (feature) { + this.overlay.setVisible(false); + + this.mountGeoengineRecord({ + popup, + archInfo: this.props.archInfo, + templateDocs: this.props.archInfo.templateDocs, + record, + }); + var coord = ol.extent.getCenter(feature.getGeometry().getExtent()); + this.overlay.setPosition(coord); + var map_view = this.map.getView(); + if (map_view) { + map_view.animate({ + center: feature.getGeometry().getFirstCoordinate(), + duration: 500, + }); + } + } else { + this.overlay.setVisible(false); + const body = "No geometry. Would you like to add geometry?"; + this.openConformationDialog(body, () => this.openEditRecord(record)); + } + } + + openEditRecord(record) { + const formDialogProps = { + resModel: record.resModel, + resId: record.resId, + title: this.env._t("Edit Record"), + context: {}, + onRecordSaved: async () => { + const offset = record.model.root.count + 1; + await record.model.root.load({ offset }); + this.render(true); + }, + }; + + this.addDialog(FormViewDialog, formDialogProps); + } + + openConformationDialog(body, callback) { + const conformationDialogProps = { + body: this.env._t(body), + confirm: callback, + cancel: () => { + return; + }, + }; + + this.addDialog(ConfirmationDialog, conformationDialogProps); + } + + zoomOnFeature(record) { + const feature = this.vectorSource.getFeatureById(record.resId); + var map_view = this.map.getView(); + if (map_view && feature) { + map_view.fit(feature.getGeometry(), { maxZoom: 14 }); + } + } getOriginalZoom() { var extent = this.vectorLayersResult @@ -641,7 +641,7 @@ export class GeoengineRenderer extends Component { if (extent !== infinite_extent) { var map_view = this.map.getView(); if (map_view) { - map_view.fit(extent, {maxZoom: 15}); + map_view.fit(extent, { maxZoom: 15 }); } } } @@ -967,11 +967,11 @@ export class GeoengineRenderer extends Component { "related", ], }); - const {relatedModels, views} = await this.view.loadViews({ + const { relatedModels, views } = await this.view.loadViews({ resModel: model, views: [[false, view]], }); - const {ArchParser, Model} = viewRegistry.get(view); + const { ArchParser, Model } = viewRegistry.get(view); const archInfo = new ArchParser().parse(views[view].arch, relatedModels, model); if (model === "geoengine.vector.layer") { @@ -1002,7 +1002,7 @@ export class GeoengineRenderer extends Component { } else if (this.models.find((e) => e.model.resModel === model) === undefined) { const toLoadModel = new Model(this.env, searchParams, this.services); await toLoadModel.load().then(() => { - this.models.push({model: toLoadModel.root, archInfo}); + this.models.push({ model: toLoadModel.root, archInfo }); }); } } @@ -1128,7 +1128,7 @@ export class GeoengineRenderer extends Component { var color_hex = cfg.begin_color || DEFAULT_BEGIN_COLOR; var color = chroma(color_hex).alpha(cfg.layer_opacity).css(); - const {fill, stroke} = this.createFillAndStroke(color); + const { fill, stroke } = this.createFillAndStroke(color); values.forEach((value) => { if (value in styles_map) { @@ -1164,7 +1164,7 @@ export class GeoengineRenderer extends Component { var color = chroma(color_hex).alpha(cfg.layer_opacity).css(); // Basic - const {fill, stroke} = this.createFillAndStroke(color); + const { fill, stroke } = this.createFillAndStroke(color); var olStyleText = this.createStyleText(); var styles = [ @@ -1215,7 +1215,7 @@ export class GeoengineRenderer extends Component { if (color in styles_map) { return; } - const {fill, stroke} = this.createFillAndStroke(color); + const { fill, stroke } = this.createFillAndStroke(color); var olStyleText = this.createStyleText(); const styles = [ new ol.style.Style({ @@ -1242,7 +1242,7 @@ export class GeoengineRenderer extends Component { color: "#333333", width: 2, }); - return {fill, stroke}; + return { fill, stroke }; } /** * Allows you to find the index of the color to be used according to its value. @@ -1286,14 +1286,14 @@ export class GeoengineRenderer extends Component { GeoengineRenderer.template = "base_geoengine.GeoengineRenderer"; GeoengineRenderer.props = { - isSavedOrDiscarded: {type: Boolean}, - archInfo: {type: Object}, - data: {type: Object}, - openRecord: {type: Function}, - editable: {type: Boolean, optional: true}, - updateRecord: {type: Function}, - onClickDiscard: {type: Function}, - createRecord: {type: Function}, - onDrawStart: {type: Function}, + isSavedOrDiscarded: { type: Boolean }, + archInfo: { type: Object }, + data: { type: Object }, + openRecord: { type: Function }, + editable: { type: Boolean, optional: true }, + updateRecord: { type: Function }, + onClickDiscard: { type: Function }, + createRecord: { type: Function }, + onDrawStart: { type: Function }, }; -GeoengineRenderer.components = {LayersPanel, GeoengineRecord, RecordsPanel}; +GeoengineRenderer.components = { LayersPanel, GeoengineRecord, RecordsPanel };