Skip to content
Snippets Groups Projects
Commit ded1605d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

download image considering bounds when current view is selected

parent a4ba3e5e
No related branches found
No related tags found
1 merge request!341Resolve "Export graphics - add "Current view""
......@@ -83,6 +83,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => {
handler: imageFormats?.[FIRST_ARRAY_ELEMENT]?.id,
zoom: getModelExportZoom(imageSize.width, model),
overlayIds: overlays.map(overlayId => `${overlayId}`),
currentView: currentView.value,
});
if (url) {
......
import { getBounds } from '@/services/pluginsManager/map/data/getBounds';
import { ZERO } from '@/constants/common';
import { DEFAULT_IMAGE_SIZE, DEFAULT_MODEL_ASPECT_RATIOS } from '../ImageSize.constants';
import { ImageSize, ModelAspectRatios } from '../ImageSize.types';
......@@ -8,14 +7,7 @@ export const getScreenAspectRatios = (): ModelAspectRatios => {
if (!bounds) {
return DEFAULT_MODEL_ASPECT_RATIOS;
}
let { x1, y1 } = bounds;
const { x2, y2 } = bounds;
if (x1 > x2) {
x1 = ZERO;
}
if (y1 > y2) {
y1 = ZERO;
}
const { x1, x2, y1, y2 } = bounds;
const width = x2 - x1;
const height = y2 - y1;
......@@ -30,14 +22,7 @@ export const getScreenDimension = (): ImageSize => {
if (!bounds) {
return DEFAULT_IMAGE_SIZE;
}
let { x1, y1 } = bounds;
const { x2, y2 } = bounds;
if (x1 > x2) {
x1 = ZERO;
}
if (y1 > y2) {
y1 = ZERO;
}
const { x1, x2, y1, y2 } = bounds;
const width = x2 - x1;
const height = y2 - y1;
......
import { BASE_API_URL, PROJECT_ID } from '@/constants';
import { getBounds } from '@/services/pluginsManager/map/data/getBounds';
export interface GetGraphicsDownloadUrlProps {
backgroundId?: number;
......@@ -6,6 +7,7 @@ export interface GetGraphicsDownloadUrlProps {
handler?: string;
zoom?: number;
overlayIds: string[];
currentView?: boolean;
}
export const getGraphicsDownloadUrl = ({
......@@ -14,6 +16,7 @@ export const getGraphicsDownloadUrl = ({
handler,
zoom,
overlayIds,
currentView,
}: GetGraphicsDownloadUrlProps): string | undefined => {
const isAllElementsTruthy = [backgroundId, modelId, handler, zoom].reduce(
(a, b) => Boolean(a) && Boolean(b),
......@@ -26,5 +29,14 @@ export const getGraphicsDownloadUrl = ({
const overlays = overlayIds.join(',');
return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadImage?backgroundOverlayId=${backgroundId}&handlerClass=${handler}&zoomLevel=${zoom}&overlayIds=${overlays}`;
let polygonSuffix = '';
if (currentView) {
const bounds = getBounds();
if (bounds) {
const { x1, y1, x2, y2 } = bounds;
polygonSuffix = `&polygonString=${x1},${y1};${x1},${y2};${x2},${y2};${x2},${y1}`;
}
}
return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadImage?backgroundOverlayId=${backgroundId}&handlerClass=${handler}&zoomLevel=${zoom}&overlayIds=${overlays}${polygonSuffix}`;
};
......@@ -2,6 +2,7 @@ import { mapDataSizeSelector } from '@/redux/map/map.selectors';
import { store } from '@/redux/store';
import { latLngToPoint } from '@/utils/map/latLngToPoint';
import { toLonLat } from 'ol/proj';
import { ZERO } from '@/constants/common';
import { MapManager } from '../mapManager';
type GetBoundsReturnType =
......@@ -29,8 +30,8 @@ export const getBounds = (): GetBoundsReturnType => {
const { x: x2, y: y2 } = latLngToPoint([latY2, lngX2], mapSize, { rounded: true });
return {
x1,
y1,
x1: x1 > x2 ? ZERO : x1, // handle lat,lng overflow
y1: y1 > y2 ? ZERO : y1, // handle lat,lng overflow
x2,
y2,
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment