Skip to content

Commit

Permalink
Merge pull request #23 from wlfrdssn/wlfrdssn-patch-1
Browse files Browse the repository at this point in the history
Bugfix and paper sizes
  • Loading branch information
perliedman authored Dec 26, 2024
2 parents 9769c02 + 0ff1b8b commit 59c9140
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 21 deletions.
7 changes: 7 additions & 0 deletions src/CourseOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ export default function CourseOptions({
index={1}
onChange={(extent) => setPrintArea({ extent })}
/>

<div />
Size on paper
<div>Height: {((extent[3]-extent[1])*(mapScale/printScale)).toFixed(2)} mm ({(printArea.pageHeight/3.937).toFixed()} mm) </div>
<div>Width: {((extent[2]-extent[0])*(mapScale/printScale)).toFixed(2)} mm ({(printArea.pageWidth/3.937).toFixed()} mm) </div>
</div>
</>

);
}



function ExtentInput({ extent, index, onChange }) {
return (
<Input
Expand Down
4 changes: 3 additions & 1 deletion src/services/ppen.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export function parsePPen(doc) {
pageWidth: Number(printAreaTag.getAttribute("page-width")),
pageHeight: Number(printAreaTag.getAttribute("page-height")),
pageMargins: Number(printAreaTag.getAttribute("page-margins")),
pageLandscape: printAreaTag.getAttribute("page-landscape") === "true",
// Landscape temporarily disabled since O-Scout does not support it yet
// pageLandscape: printAreaTag.getAttribute("page-landscape") === "true",
pageLandscape: false,
};
}

Expand Down
34 changes: 18 additions & 16 deletions src/tools/Objects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ export default function Objects(): JSX.Element {
cursor: "crosshair",
});
interaction.on("extentchangeend", ({ extent }: { extent: Extent }) => {
const locations = mapExtentToDescriptionLocations(
extent,
map.getView().getProjection(),
(selectedCourse?.controls.length || 0) + 2
);
addSpecialObject(
{
kind: "descriptions",
locations,
isAllCourses: false,
},
selectedCourse.id
);
const objects = useEvent.getState().specialObjects;
setSelectedObjectId(objects[objects.length - 1].id);
setMode("edit");
if (extent) {
const locations = mapExtentToDescriptionLocations(
extent,
map.getView().getProjection(),
(selectedCourse?.controls.length || 0) + 2
);
addSpecialObject(
{
kind: "descriptions",
locations,
isAllCourses: false,
},
selectedCourse.id
);
const objects = useEvent.getState().specialObjects;
setSelectedObjectId(objects[objects.length - 1].id);
setMode("edit");
}
});
map.addInteraction(interaction);

Expand Down
60 changes: 56 additions & 4 deletions src/tools/PrintArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,99 @@ import useEvent, { useMap } from "../store";
import shallow from "zustand/shallow";
import ExtentInteraction from "../ol/ExtentInteraction";
import { getPrintAreaExtent } from "../models/course";
import { printCourse } from "../services/print";

import Feature from 'ol/Feature.js';
import {Vector as VectorLayer} from 'ol/layer.js';
import {Vector as VectorSource} from 'ol/source.js';
import {fromExtent} from 'ol/geom/Polygon.js';

export default function PrintArea() {
const { map, mapFile } = useMap(getMap);
const { course, setPrintAreaExtent } = useEvent(getSelectedCourse, shallow);

const crs = useMemo(() => mapFile?.getCrs(), [mapFile]);


useEffect(() => {
if (map && course) {
const initialExtent = transformExtent(
getPrintAreaExtent(course, crs.scale),
(c) => toProjectedCoord(crs, c)
);

const PrintAreaExtentI = getPrintAreaExtent(course)
const check_height = (course.printArea.pageHeight/3.937)-((PrintAreaExtentI[3]-PrintAreaExtentI[1])*(15000/course.printScale))
const check_width = (course.printArea.pageWidth/3.937)-((PrintAreaExtentI[2]-PrintAreaExtentI[0])*(15000/course.printScale))


let boxStyle;

if (check_height < 0 || check_width < 0) {
boxStyle = new Style({
stroke: new Stroke({ color: "#FF0000", lineDash: [6, 10], width: 3 }),
fill: null,
});
} else {
boxStyle = new Style({
stroke: new Stroke({ color: "#444", lineDash: [6, 10], width: 3 }),
fill: null,
});
}

const interaction = new ExtentInteraction({
extent: initialExtent,
boxStyle,
pointerStyle: new Style(),
});

const rectCoords = []


//Papersize on map. 15000 mapscale??
rectCoords[0] = initialExtent[0]
rectCoords[1] = initialExtent[1]
rectCoords[2] = initialExtent[0]+((course.printArea.pageWidth)*(course.printScale/15000)*(96*(1/25.4)))
rectCoords[3] = initialExtent[1]+((course.printArea.pageHeight)*(course.printScale/15000)*(96*(1/25.4)))


const printLayer = new VectorLayer({
source: new VectorSource({
features: [
new Feature(
fromExtent(rectCoords),
),
],
}),
});



interaction.on("extentchangeend", ({ extent }) => {

if (extent) {
setPrintAreaExtent(
course.id,
transformExtent(extent, (c) => fromProjectedCoord(crs, c))
);


}
});
map.addInteraction(interaction);
map.addLayer(printLayer);

return () => {
map.removeInteraction(interaction);
map.removeLayer(printLayer);
};
}
}, [crs, mapFile, map, course, setPrintAreaExtent]);

return null;
}

const boxStyle = new Style({
stroke: new Stroke({ color: "#444", lineDash: [6, 10], width: 3 }),
fill: null,
});


function getMap({ map, mapFile }) {
return { map, mapFile };
Expand Down

0 comments on commit 59c9140

Please sign in to comment.