Skip to content

Conversation

@mxfh
Copy link
Contributor

@mxfh mxfh commented Oct 16, 2025

test print module.

deploy: ['geoportal']

@mxfh mxfh requested review from PavelOlkhovoi and Copilot October 16, 2025 10:16
@mxfh mxfh marked this pull request as ready for review October 16, 2025 10:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Progress toward enabling strict TypeScript in geoportal by tightening types and simplifying null handling.

  • Add explicit typing to helper and component functions, including L.Map and event types
  • Change getPolygonPoints to return null when no polygon is present and update call sites accordingly
  • Fix a state setter name typo and improve preview size computation flow

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
apps/geoportal/src/app/helper/print.tsx Type getPolygonPoints(map: L.Map), return null when no polygon, and adjust addPreviewWrapper usage to handle null.
apps/geoportal/src/app/components/map-print/PrintPreview.tsx Type function params (map, events, flags), rename preview state setter, and update logic to handle nullable polygon points.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +693 to +697
export const getPolygonPoints = (map: L.Map) => {
const polygon = getPolygonByLeafletId(map);
if (polygon) {
const bounds = polygon.getBounds();

const { _northEast, _southWest } = bounds;
const northEast = map.latLngToContainerPoint(_northEast);
const southWest = map.latLngToContainerPoint(_southWest);
const northWest = {
x: southWest.x,
y: northEast.y,
};
const southEast = {
x: northEast.x,
y: southWest.y,
};
if (!polygon) {
return null;
}
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPolygonPoints now returns null when no polygon is found, changing its contract from 'always object' to 'object | null'. Please make this explicit in the signature to improve clarity and catch misuses at compile time, e.g. add a named return type and annotate the function as returning that type or null.

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +167
const target = e.originalEvent.target as HTMLElement;
const routedMap = target?.id === "routedMap";
const glLayer = target?.classList.contains("leaflet-gl-layer");
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Leaflet click targets can be SVG elements (or other non-HTMLElement Elements). Prefer typing this as Element, or guard with an instanceof check, to avoid incorrect narrowing and to better match the DOM surface you're using (id, classList). For example: const target = e.originalEvent.target; if (!(target instanceof Element)) return; // then use target.id and target.classList.

Suggested change
const target = e.originalEvent.target as HTMLElement;
const routedMap = target?.id === "routedMap";
const glLayer = target?.classList.contains("leaflet-gl-layer");
const target = e.originalEvent.target;
if (!(target instanceof Element)) {
return;
}
const routedMap = target.id === "routedMap";
const glLayer = target.classList.contains("leaflet-gl-layer");

Copilot uses AI. Check for mistakes.
if (polygon) {
const { northWest, northEast, southWest } = getPolygonPoints(map);
const wrapWidth = northEast.x - northWest.x;
const changePreviewSizes = (map: L.Map, orientation: string) => {
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] orientation is compared to 'portrait' and 'landscape'; narrow the parameter type to a string literal union ('portrait' | 'landscape') to improve type safety and reduce accidental misuse.

Suggested change
const changePreviewSizes = (map: L.Map, orientation: string) => {
const changePreviewSizes = (map: L.Map, orientation: 'portrait' | 'landscape') => {

Copilot uses AI. Check for mistakes.
Comment on lines +700 to +702
const { _northEast, _southWest } = bounds;
const northEast = map.latLngToContainerPoint(_northEast);
const southWest = map.latLngToContainerPoint(_southWest);
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Avoid relying on Leaflet's private LatLngBounds fields (_northEast/_southWest). Use the public API for forward compatibility: const northEastLatLng = bounds.getNorthEast(); const southWestLatLng = bounds.getSouthWest(); then pass those to latLngToContainerPoint.

Suggested change
const { _northEast, _southWest } = bounds;
const northEast = map.latLngToContainerPoint(_northEast);
const southWest = map.latLngToContainerPoint(_southWest);
const northEastLatLng = bounds.getNorthEast();
const southWestLatLng = bounds.getSouthWest();
const northEast = map.latLngToContainerPoint(northEastLatLng);
const southWest = map.latLngToContainerPoint(southWestLatLng);

Copilot uses AI. Check for mistakes.
@mxfh
Copy link
Contributor Author

mxfh commented Oct 17, 2025

@PavelOlkhovoi not using the private fields seems like a good idea. leaflet has methods for getting the corners

@mxfh mxfh added the app:geoportal app geoportal label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app:geoportal app geoportal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants