Skip to content

Commit

Permalink
remove module imports from drawing.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinElms committed Jan 13, 2025
1 parent 25a3385 commit e8952e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion oceannavigator/frontend/src/components/map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ const Map = forwardRef((props, ref) => {
const startDrawing = () => {
let newDrawAction = drawAction(
vectorSource,
props.vectorType,
props.mapSettings.projection,
props.action
);
Expand Down
27 changes: 11 additions & 16 deletions oceannavigator/frontend/src/components/map/drawing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Feature from "ol/Feature.js";
import * as olExtent from "ol/extent";
import { getCenter } from "ol/extent";
import Draw from "ol/interaction/Draw";
import * as olgeom from "ol/geom";
import * as olProj from "ol/proj";
import { Point, LineString, Polygon } from "ol/geom";
import { transform } from "ol/proj";
import { getDistance } from "ol/sphere";

export const drawAction = (vectorSource, projection, action) => {
Expand All @@ -15,13 +15,8 @@ export const drawAction = (vectorSource, projection, action) => {

drawAction.on("drawend", function (e) {
// Disable zooming when drawing
const latlon = olProj
.transform(
e.feature.getGeometry().getCoordinates(),
projection,
"EPSG:4326"
)
.reverse();
let coords = e.feature.getGeometry().getCoordinates();
const latlon = transform(coords, projection, "EPSG:4326").reverse();
// Draw point on map(s)
action("addNewFeature", [latlon]);
});
Expand All @@ -42,7 +37,7 @@ export const pointFeature = (features, vectorSource, projection) => {
switch (vectorType) {
case "point":
let c = feature.coords[0];
geom = new olgeom.Point([c[1], c[0]]);
geom = new Point([c[1], c[0]]);
geom = geom.transform("EPSG:4326", projection);
feat = new Feature({
geometry: geom,
Expand All @@ -54,7 +49,7 @@ export const pointFeature = (features, vectorSource, projection) => {

break;
case "line":
geom = new olgeom.LineString(
geom = new LineString(
feature.coords.map(function (c) {
return [c[1], c[0]];
})
Expand All @@ -69,12 +64,12 @@ export const pointFeature = (features, vectorSource, projection) => {
vectorSource.addFeature(feat);
break;
case "area":
geom = new olgeom.Polygon([
geom = new Polygon([
feature.coords.map(function (c) {
return [c[1], c[0]];
}),
]);
const centroid = olExtent.getCenter(geom.getExtent());
const centroid = getCenter(geom.getExtent());
geom.transform("EPSG:4326", projection);
feat = new Feature({
geometry: geom,
Expand Down Expand Up @@ -107,7 +102,7 @@ export const obsPointDrawAction = (map, obsDrawSource, projection, action) => {
drawAction.set("type", "Point");
drawAction.on("drawend", function (e) {
// Disable zooming when drawing
const lonlat = olProj.transform(
const lonlat = transform(
e.feature.getGeometry().getCoordinates(),
projection,
"EPSG:4326"
Expand Down Expand Up @@ -136,7 +131,7 @@ export const obsAreaDrawAction = (map, obsDrawSource, projection, action) => {
.getGeometry()
.getCoordinates()[0]
.map(function (c) {
const lonlat = olProj.transform(c, projection, "EPSG:4326");
const lonlat = transform(c, projection, "EPSG:4326");
return [lonlat[1], lonlat[0]];
});
// Send area to Observation Selector
Expand Down

0 comments on commit e8952e9

Please sign in to comment.