Skip to content

Commit

Permalink
Apply max scale constraint in zoomToGeometryOrExtent function
Browse files Browse the repository at this point in the history
  • Loading branch information
nboisteault committed Oct 23, 2024
1 parent 36f95f1 commit 23f9a99
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions assets/src/modules/config/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const optionalProperties = {
'wmsMaxHeight': {type: 'number', default: 3000},
'wmsMaxWidth': {type: 'number', default: 3000},
'fixed_scale_overview_map': {type: 'boolean', default: true},
'max_scale_points': {type: 'number', default: 5000},
'max_scale_lines_polygons': {type: 'number', default: 5000},
'use_native_zoom_levels': {type: 'boolean', nullable: true, default: null},
'hide_numeric_scale_value': {type: 'boolean', default: false},
'hideGroupCheckbox': { type: 'boolean', default: false },
Expand Down Expand Up @@ -62,6 +64,8 @@ export class OptionsConfig extends BaseObjectConfig {
* @param {number} [cfg.wmsMaxHeight] - the image max height for WMS GetMap request
* @param {number} [cfg.wmsMaxWidth] - the image max width for WMS GetMap request
* @param {boolean} [cfg.fixed_scale_overview_map] - does the Overview map have fixed scale ?
* @param {number} [cfg.max_scale_points] - maximum scale when zooming on points
* @param {boolean} [cfg.max_scale_lines_polygons] - maximum scale when zooming on lines or polygons
* @param {boolean} [cfg.use_native_zoom_levels] - does the map use native zoom levels ?
* @param {boolean} [cfg.hide_numeric_scale_value] - does the scale line hide numeric scale value ?
* @param {boolean} [cfg.hideGroupCheckbox] - are groups checkbox hidden ?
Expand Down Expand Up @@ -207,6 +211,22 @@ export class OptionsConfig extends BaseObjectConfig {
return this._fixed_scale_overview_map;
}

/**
* Maximum scale when zooming on points
* @type {boolean}
*/
get max_scale_points() {
return this._max_scale_points;
}

/**
* Maximum scale when zooming on lines or polygons
* @type {boolean}
*/
get max_scale_lines_polygons() {
return this._max_scale_lines_polygons;
}

/**
* The map uses native zoom levels
* @type {boolean}
Expand Down
22 changes: 22 additions & 0 deletions assets/src/modules/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,28 @@ export default class map extends olMap {
* @param {object} [options] Options.
*/
zoomToGeometryOrExtent(geometryOrExtent, options) {
// Apply max scale constraint
const geometryType = geometryOrExtent?.getType();
if (geometryType && (mainLizmap.initialConfig.options.max_scale_lines_polygons || mainLizmap.initialConfig.options.max_scale_lines_polygons)) {
let maxScale;
if (['Polygon', 'Linestring'].includes(geometryType)){
maxScale = mainLizmap.initialConfig.options.max_scale_lines_polygons;
} else if (geometryType === 'Point'){
maxScale = mainLizmap.initialConfig.options.max_scale_points;
}
const resolution = mainLizmap.utils.getResolutionFromScale(
maxScale,
mainLizmap.map.getView().getProjection().getMetersPerUnit()
);
if (!options?.minResolution) {
if (!options) {
options = { minResolution: resolution };
} else {
options.minResolution = resolution;
}
}
}

this.getView().fit(geometryOrExtent, options);
}
}

0 comments on commit 23f9a99

Please sign in to comment.