Skip to content

Commit

Permalink
Merge pull request #5092 from nboisteault/backport-4897-to-release_3_9
Browse files Browse the repository at this point in the history
[Backport release_3_9] Zoom to features with a max scale constraint
  • Loading branch information
nboisteault authored Dec 6, 2024
2 parents 1d63aa3 + b6a567b commit 861558c
Show file tree
Hide file tree
Showing 9 changed files with 572 additions and 551 deletions.
23 changes: 14 additions & 9 deletions assets/src/components/FeatureToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { getCenter } from 'ol/extent.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import GPX from 'ol/format/GPX.js';
import KML from 'ol/format/KML.js';
import Point from 'ol/geom/Point.js';
import {fromExtent} from 'ol/geom/Polygon.js';

import '../images/svg/map-print.svg';

Expand Down Expand Up @@ -397,12 +399,6 @@ export default class FeatureToolbar extends HTMLElement {
}

zoom() {
// FIXME: necessary?
// Remove map popup to avoid confusion
if (lizMap.map.popups.length != 0){
lizMap.map.removePopup(lizMap.map.popups[0]);
}

if (this.getAttribute('crs')){
const featureExtent = [
parseFloat(this.getAttribute('bbox-minx')),
Expand All @@ -415,9 +411,18 @@ export default class FeatureToolbar extends HTMLElement {
this.getAttribute('crs'),
lizMap.mainLizmap.projection
);
lizMap.mainLizmap.extent = targetMapExtent;
}else{
lizMap.zoomToFeature(this.featureType, this.fid, 'zoom');

let geom;
// The geom is a Point
if (targetMapExtent[0] == targetMapExtent[2] && targetMapExtent[1] == targetMapExtent[3]) {
geom = new Point([targetMapExtent[0], targetMapExtent[1]])
} else {
geom = fromExtent(targetMapExtent);
}

mainLizmap.map.zoomToGeometryOrExtent(geom);
} else {
mainLizmap.map.zoomToFid(this.featureType + '.' + this.fid);
}
}

Expand Down
18 changes: 6 additions & 12 deletions assets/src/legacy/atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import DOMPurify from 'dompurify';
import GeoJSON from 'ol/format/GeoJSON.js';
import { getCenter } from 'ol/extent.js';

(function () {

Expand Down Expand Up @@ -531,26 +533,18 @@ import DOMPurify from 'dompurify';
* @param feature
*/
function runAtlasItem(feature) {

// Use OL tools to reproject feature geometry
var format = new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true
});
var feat = format.read(feature)[0];
var f = feat.clone();
var proj = lizMap.config.layers[lizAtlasConfig.layername]['featureCrs'];
f.geometry.transform(proj, lizMap.map.getProjection());
const olFeature = (new GeoJSON()).readFeature(feature);

// Zoom to feature
if (lizAtlasConfig['zoom']) {
if (lizAtlasConfig['zoom'].toLowerCase() == 'center') {
// center
var lonlat = f.geometry.getBounds().getCenterLonLat();
lizMap.map.setCenter(lonlat);
const center = getCenter(olFeature.getGeometry().getExtent());
lizMap.map.setCenter(center);
}
else {
// zoom
lizMap.map.zoomToExtent(f.geometry.getBounds());
lizMap.mainLizmap.map.zoomToGeometryOrExtent(olFeature.getGeometry());
}
}

Expand Down
3 changes: 1 addition & 2 deletions assets/src/legacy/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,8 +1462,7 @@ var lizLayerFilterTool = function () {
if (!bounds || abounds.length != 4) {
return false;
}
var extent = new OpenLayers.Bounds(abounds[0], abounds[1], abounds[2], abounds[3]);
lizMap.map.zoomToExtent(extent);
lizMap.mainLizmap.map.zoomToGeometryOrExtent(abounds);
return false;
}

Expand Down
Loading

0 comments on commit 861558c

Please sign in to comment.