Skip to content

Commit

Permalink
feat(reverse): limite les zones dessinées par rapport aux limites du …
Browse files Browse the repository at this point in the history
…service (#305)
  • Loading branch information
azarz authored Dec 18, 2024
1 parent 88040c2 commit 6242da1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "geopf-extensions-openlayers",
"description": "French Geoportal Extensions for OpenLayers libraries",
"version": "1.0.0-beta.1-303",
"date": "11/12/2024",
"version": "1.0.0-beta.1-305",
"date": "18/12/2024",
"module": "src/index.js",
"directories": {},
"engines": {
Expand Down
23 changes: 21 additions & 2 deletions src/packages/Controls/ReverseGeocode/ReverseGeocode.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,21 @@ var ReverseGeocode = class ReverseGeocode extends Control {
})
}),
type : ("Circle"),
source : this._inputFeaturesSource
source : this._inputFeaturesSource,
geometryFunction : function (coordinates, geometry) {
const center = coordinates[0];
const last = coordinates[coordinates.length - 1];
const dx = center[0] - last[0];
const dy = center[1] - last[1];
const maxRadius = 500;
const radius = Math.min(Math.sqrt(dx * dx + dy * dy), maxRadius);
if (!geometry) {
geometry = new ol.geom.Circle(center, radius);
} else {
geometry.setCenterAndRadius(center, radius);
}
return geometry;
}
});

this._mapInteraction.on(
Expand Down Expand Up @@ -783,9 +797,14 @@ var ReverseGeocode = class ReverseGeocode extends Control {
}
var start = coordinates[0];
var end = coordinates[1];
const dx = start[0] - end[0];
const dy = start[1] - end[1];
const maxLength = 1000;
const lengthX = Math.max(-maxLength, Math.min(dx, maxLength));
const lengthY = Math.max(-maxLength, Math.min(dy, maxLength));
// on crée les 5 coordonnées de la ligne à partir des 2 points saisis.
geometry.setCoordinates([
[start, [start[0], end[1]], end, [end[0], start[1]], start]
[start, [start[0], start[1] - lengthY], [start[0] - lengthX, start[1] - lengthY], [start[0] - lengthX, start[1]], start]
]);
return geometry;
};
Expand Down

0 comments on commit 6242da1

Please sign in to comment.