Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#10136: Search for Map CRS coordinates #10305

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Message from "../../I18N/Message";
import CoordinateEntry from "../../misc/coordinateeditors/CoordinateEntry";
import DropdownToolbarOptions from "../../misc/toolbar/DropdownToolbarOptions";
import { zoomAndAddPoint, changeCoord } from '../../../actions/search';
import { reproject} from '../../../utils/CoordinatesUtils';

/**
* CoordinateOptions for Search bar
Expand Down Expand Up @@ -138,6 +139,7 @@ const CoordinatesSearch = ({
onZoomToPoint,
onChangeCoord,
defaultZoomLevel,
currentMapCRS,
aeronauticalOptions = {
seconds: {
decimals: 4,
Expand All @@ -164,6 +166,24 @@ const CoordinatesSearch = ({
if (!areValidCoordinates()) {
onClearCoordinatesSearch({owner: "search"});
}
// if there is mapCRS available --> calculate X/Y values by reproject to display in case switch to MapCRS
if (currentMapCRS !== 'EPSG:4326') {
// if there are lat, lon values --> reproject the point and get xCoord and yCoord for map CRS
const latNumVal = coord === 'lat' ? parseFloat(value) : coordinate.lat;
const lonNumVal = coord === 'lon' ? parseFloat(value) : coordinate.lon;
const isLatNumberVal = isNumber(latNumVal) && !isNaN(latNumVal);
const isLonNumberVal = isNumber(lonNumVal) && !isNaN(lonNumVal);
if (isLatNumberVal && isLonNumberVal) {
const reprojectedValue = reproject([lonNumVal, latNumVal], 'EPSG:4326', currentMapCRS, true);
const parsedXCoord = parseFloat((reprojectedValue?.x));
const parsedYCoord = parseFloat((reprojectedValue?.y));
onChangeCoord('xCoord', parsedXCoord);
onChangeCoord('yCoord', parsedYCoord);
return;
}
coordinate.xCoord && onChangeCoord('xCoord', '');
coordinate.yCoord && onChangeCoord('yCoord', '');
}
};

const onZoom = () => {
Expand Down Expand Up @@ -226,7 +246,8 @@ CoordinatesSearch.propTypes = {
onClearCoordinatesSearch: PropTypes.func,
onZoomToPoint: PropTypes.func,
onChangeCoord: PropTypes.func,
defaultZoomLevel: PropTypes.number
defaultZoomLevel: PropTypes.number,
currentMapCRS: PropTypes.string
};

export default connect((state)=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,8 @@ const CurrentMapCRSCoordinatesSearch = ({
};
React.useEffect(() => {
if (!currentMapCRS || currentMapCRS === 'EPSG:4326') return;
// if there are lat, lon values --> reproject the point and get xCoord and yCoord for map CRS
const isLatNumberVal = isNumber(coordinate.lat) && !isNaN(coordinate.lat);
const isLonNumberVal = isNumber(coordinate.lon) && !isNaN(coordinate.lon);
if (isLatNumberVal && isLonNumberVal) {
const reprojectedValue = reproject([coordinate.lon, coordinate.lat], 'EPSG:4326', currentMapCRS, true);
const parsedXCoord = parseFloat((reprojectedValue?.x));
const parsedYCoord = parseFloat((reprojectedValue?.y));
onChangeCoord('xCoord', parsedXCoord);
onChangeCoord('yCoord', parsedYCoord);
// if coords are out of crs extent --> clear the marker
if (!isCoordWithinCrs(parsedXCoord, 'xCoord') || !isCoordWithinCrs(parsedYCoord, 'yCoord')) onClearCoordinatesSearch({owner: "search"});
return;
}
coordinate.xCoord && onChangeCoord('xCoord', '');
coordinate.yCoord && onChangeCoord('yCoord', '');
if (!isCoordWithinCrs(coordinate?.xCoord, 'xCoord') || !isCoordWithinCrs(coordinate?.yCoord, 'yCoord')) onClearCoordinatesSearch({owner: "search"});

}, [currentMapCRS]);

const changeCoordinates = (coord, value) => {
Expand All @@ -95,24 +82,15 @@ const CurrentMapCRSCoordinatesSearch = ({
const numValue = parseFloat(value);
onChangeCoord(coord, numValue);
// reproject the new point and set lat/lon
if (coord === 'yCoord') {
const yCoordValidNum = isNumber(numValue) && !isNaN(numValue) && isCoordWithinCrs(numValue, 'yCoord');
const xCoordValidNum = isNumber(coordinate.xCoord) && !isNaN(coordinate.xCoord) && isCoordWithinCrs(coordinate.xCoord, 'xCoord');
if (yCoordValidNum && xCoordValidNum) {
const projectedPt = reproject([coordinate.xCoord, numValue], currentMapCRS, 'EPSG:4326', true);
onChangeCoord('lat', (projectedPt.y));
onChangeCoord('lon', (projectedPt.x));
return;
}
} else {
const xCoordValidNum = isNumber(numValue) && !isNaN(numValue) && isCoordWithinCrs(numValue, 'xCoord');
const yCoordValidNum = isNumber(coordinate.yCoord) && !isNaN(coordinate.yCoord) && isCoordWithinCrs(coordinate.yCoord, 'yCoord');
if (yCoordValidNum && xCoordValidNum) {
const projectedPt = reproject([numValue, coordinate.yCoord], currentMapCRS, 'EPSG:4326', true);
onChangeCoord('lat', (projectedPt.y));
onChangeCoord('lon', (projectedPt.x));
return;
}
const yCoodNumVal = coord === 'yCoord' ? numValue : coordinate.yCoord;
const xCoodNumVal = coord === 'xCoord' ? numValue : coordinate.xCoord;
const yCoordValidNum = isNumber(yCoodNumVal) && !isNaN(yCoodNumVal) && isCoordWithinCrs(yCoodNumVal, 'yCoord');
const xCoordValidNum = isNumber(xCoodNumVal) && !isNaN(xCoodNumVal) && isCoordWithinCrs(xCoodNumVal, 'xCoord');
if (yCoordValidNum && xCoordValidNum) {
const projectedPt = reproject([xCoodNumVal, yCoodNumVal], currentMapCRS, 'EPSG:4326', true);
onChangeCoord('lat', (projectedPt.y));
onChangeCoord('lon', (projectedPt.x));
return;
}
const resetValue = '';
onChangeCoord('lat', resetValue);
Expand Down
Loading