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

Feature/1526 measurer select feature #1532

Merged
merged 9 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
34 changes: 34 additions & 0 deletions apps/client/src/models/DrawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ class DrawModel {
this.#createDrawTooltip();
}

// Generates a random string that can be used as an ID.
generateRandomString = () => {
return Math.random().toString(36).slice(2, 9);
};

createHighlightStyle = () => {
return new Style({
stroke: new Stroke({
color: "rgba(255, 0, 0, 1)",
width: 3,
}),
fill: new Fill({
color: "rgba(255, 0, 0, 0.1)",
}),
});
};

// Creates a new feature with the same geometry as the supplied one. The new
// feature can be used an an highlight, to show where the supplied feature is.
createHighlightFeature = (feature) => {
// If no feature (or a feature with no get-geometry) is supplied, we abort.
if (feature && feature.getGeometry()) {
// Otherwise we create a new feature...
const highlightFeature = new Feature({
geometry: feature.getGeometry().clone(),
});
// ...set an id and a highlight-style...
highlightFeature.setId(this.generateRandomString());
highlightFeature.setStyle(this.createHighlightStyle());
// Finally we return the feature so that we can add it to the map etc.
return highlightFeature;
}
};

// Returns the supplied observerPrefix from the supplied settings or null if none was supplied.
#getObserverPrefix = (settings) => {
return typeof settings.observerPrefix === "string"
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/plugins/Measurer/Measurer.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function Measurer(props) {
title: state.title || "Mät",
description: "Mät längder och ytor",
height: "dynamic",
width: 360,
width: 400,
customPanelHeaderButtons: customHeaderButtons,

onWindowHide: onWindowHide,
Expand Down
11 changes: 11 additions & 0 deletions apps/client/src/plugins/Measurer/MeasurerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {

import { IconPolygon, IconPoint, IconLine, IconCircle } from "./MeasurerIcons";
import DeleteIcon from "@mui/icons-material/Delete";
import TouchAppIcon from "@mui/icons-material/TouchApp";
import ConfirmationDialog from "../../components/ConfirmationDialog";
import { useEffect, useState } from "react";
import HajkToolTip from "components/HajkToolTip";
import SelectFeaturesDialog from "utils/SelectFeaturesDialog";

const SvgImg = styled("img")(({ theme }) => ({
height: "24px",
Expand Down Expand Up @@ -149,6 +151,11 @@ function MeasurerView(props) {
<SvgImg src={IconCircle()} />
</StyledToggleButton>
</HajkToolTip>
<HajkToolTip title="Välj på kartan">
<StyledToggleButton value="Select">
<TouchAppIcon />
</StyledToggleButton>
</HajkToolTip>
<HajkToolTip title="Ta bort enskild mätning">
<StyledToggleButton value="Delete">
<DeleteIcon />
Expand Down Expand Up @@ -184,6 +191,10 @@ function MeasurerView(props) {
}}
/>
<HelpDialog open={showHelp} setShowHelp={setShowHelp} />
<SelectFeaturesDialog
localObserver={props.localObserver}
drawModel={drawModel}
/>
</>
);
}
Expand Down
29 changes: 0 additions & 29 deletions apps/client/src/plugins/Sketch/models/SketchModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,6 @@ class SketchModel {
});
};

#createHighlightStyle = () => {
return new Style({
stroke: new Stroke({
color: "rgba(255, 0, 0, 1)",
width: 3,
}),
fill: new Fill({
color: "rgba(255, 0, 0, 0.1)",
}),
});
};

// Accepts a feature with a Circle-geometry and updates the feature-geometry
// to a Point-geometry along with an additional property ("CIRCLE_RADIUS") that can
// be used to construct a "real" Circle-geometry when the feature is to be added to
Expand Down Expand Up @@ -484,23 +472,6 @@ class SketchModel {
return s1.toLowerCase() === s2.toLowerCase();
};

// Creates a new feature with the same geometry as the supplied one. The new
// feature can be used an an highlight, to show where the supplied feature is.
createHighlightFeature = (feature) => {
// If no feature (or a feature with no get-geometry) is supplied, we abort.
if (feature && feature.getGeometry()) {
// Otherwise we create a new feature...
const highlightFeature = new Feature({
geometry: feature.getGeometry().clone(),
});
// ...set an id and a highlight-style...
highlightFeature.setId(this.generateRandomString());
highlightFeature.setStyle(this.#createHighlightStyle());
// Finally we return the feature so that we can add it to the map etc.
return highlightFeature;
}
};

// Returns wether helper-snacks should be shown or not
getShowHelperSnacks = () => {
return this.#showHelperSnacks;
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/plugins/Sketch/views/AddView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DrawTypeSelector from "../components/DrawTypeSelector";
import Information from "../components/Information";
import FeatureStyleSelector from "../components/featureStyle/FeatureStyleSelector";
import FeatureTextSetter from "../components/FeatureTextSetter";
import SelectFeaturesDialog from "../components/SelectFeaturesDialog";
import SelectFeaturesDialog from "utils/SelectFeaturesDialog";

const AddView = (props) => {
// Let's destruct some properties from the props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import {
ListItemText,
} from "@mui/material";

export default function SelectFeaturesDialog({
localObserver,
drawModel,
model,
}) {
export default function SelectFeaturesDialog({ localObserver, drawModel }) {
// Let's keep everything in one state here since all properties are
// changing at the same time (almost).
const [state, setState] = React.useState({
Expand Down Expand Up @@ -81,7 +77,7 @@ export default function SelectFeaturesDialog({
// Let's get the clicked feature we're currently hoovering.
const hoveredFeature = state.clickedFeatures[index];
// Then we can create a corresponding highlight-feature.
const highlightFeature = model.createHighlightFeature(hoveredFeature);
const highlightFeature = drawModel.createHighlightFeature(hoveredFeature);
// We'll add the highlight-feature to the draw-layer...
drawModel.addFeature(highlightFeature, { silent: true });
// ...and update the state so that we can keep track of what we are highlighting.
Expand All @@ -105,8 +101,16 @@ export default function SelectFeaturesDialog({
// (If there's zero or one, the drawModel will take care of it).
React.useEffect(() => {
localObserver.subscribe("drawModel.select.click", handleDrawSelectClick);
localObserver.subscribe(
"measure.drawModel.select.click",
handleDrawSelectClick
);
return () => {
localObserver.unsubscribe("drawModel.select.click");
localObserver.unsubscribe(
"measure.drawModel.select.click",
handleDrawSelectClick
);
};
}, [localObserver, handleDrawSelectClick]);

Expand Down