Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

progress on curved distance/area lines

Jason Kentdbbb63f7aee2
diff --git a/package-lock.json b/package-lock.json
index a27f7e915..f06dc9187 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2032,6 +2032,11 @@
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==",
"dev": true
},
+ "arc": {
+ "version": "0.1.1",
+ "resolved": "https://registry.npmjs.org/arc/-/arc-0.1.1.tgz",
+ "integrity": "sha512-gJsNNbnJW7UMU9ccjBaRh2evSyltbinzRGNPX9aiW28QxbGMtwMDC0YL6lkF73b+y+BUAOT/dUN2DMQDB1Is5w=="
+ },
"are-we-there-yet": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
diff --git a/package.json b/package.json
index 9978f4c6e..2a3743414 100644
--- a/package.json
+++ b/package.json
@@ -154,6 +154,7 @@
"dependencies": {
"@entryline/gifstream": "^1.2.0",
"@fortawesome/fontawesome-free": "^5.10.1",
+ "arc": "^0.1.1",
"bluebird": "3.4.6",
"bootstrap": "4.3.1",
"cachai": "^1.0.2",
diff --git a/web/js/map/measure/measure.js b/web/js/map/measure/measure.js
index 1252cf8e5..98d593b96 100644
--- a/web/js/map/measure/measure.js
+++ b/web/js/map/measure/measure.js
@@ -1,17 +1,14 @@
import { unByKey } from 'ol/Observable';
import Overlay from 'ol/Overlay';
import { getArea, getLength } from 'ol/sphere';
-import { LineString, Polygon } from 'ol/geom';
+import { MultiLineString, LineString, Polygon, MultiPoint } from 'ol/geom';
import Draw from 'ol/interaction/Draw';
import { Vector as VectorLayer } from 'ol/layer';
import { Vector as VectorSource } from 'ol/source';
import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';
+import arc from 'arc';
export function measure (map) {
- const self = {};
- const source = new VectorSource();
- const vector = getVectorLayer(source);
- const projection = map.getView().getProjection().getCode();
let draw;
let sketch;
let helpTooltipElement;
@@ -20,10 +17,11 @@ export function measure (map) {
let measureTooltip;
let allMeasureTooltips = [];
let drawChangeListener;
+ let vector;
+ const self = {};
+ const source = new VectorSource();
+ const projection = map.getView().getProjection();
- /**
- * Handle pointer move.
- */
function pointerMoveHandler (evt) {
if (evt.dragging) {
return;
@@ -31,7 +29,6 @@ export function measure (map) {
const helpMsg = !sketch
? 'Click to start drawing.'
: 'Click to continue drawing. <br/> Double-click to complete.';
-
helpTooltipElement.innerHTML = helpMsg;
helpTooltip.setPosition(evt.coordinate);
helpTooltipElement.classList.remove('hidden');
@@ -73,10 +70,10 @@ export function measure (map) {
const geom = evt.target;
let output;
if (geom instanceof Polygon) {
- output = formatArea(geom, projection);
+ output = formatArea(geom, projection.getCode());
tooltipCoord = geom.getInteriorPoint().getCoordinates();
} else if (geom instanceof LineString) {
- output = formatLength(geom, projection);
+ output = formatLength(geom, projection.getCode());
tooltipCoord = geom.getLastCoordinate();
}
measureTooltipElement.innerHTML = output;
@@ -95,13 +92,121 @@ export function measure (map) {
unByKey(drawChangeListener);
};
+ function getVectorLayer (type) {
+ return new VectorLayer({
+ source,
+ style: new Style({
+ fill: new Fill({
+ color: 'rgba(213, 78, 33, 0.1)'
+ }),
+ stroke: new Stroke({
+ color: 'rgba(255, 100, 6, 1)',
+ lineJoin: 'round',
+ width: 3
+ }),
+ geometry: transformGeometry(type)
+ })
+ });
+ }
+
+ function getDraw (type) {
+ return new Draw({
+ source,
+ type,
+ style: new Style({
+ fill: new Fill({
+ color: 'rgba(213, 78, 33, 0.1)'
+ }),
+ stroke: new Stroke({
+ color: 'rgba(255, 100, 6, 1)',
+ lineDash: [10, 20],
+ lineJoin: 'round',
+ width: 4
+ }),
+ image: new CircleStyle({
+ radius: 7,
+ stroke: new Stroke({
+ color: 'rgba(0, 0, 0, 0.7)'
+ }),
+ fill: new Fill({
+ color: 'rgba(255, 255, 255, 0.3)'
+ })
+ })
+ })
+ });
+ };
+
+ /**
+ *
+ * @param {*} feature
+ */
+ function transformLineStringArc (geom) {
+ const coords = [];
+ geom.forEachSegment((segStart, segEnd) => {
+ const start = {
+ x: segStart[0],
+ y: segStart[1]
+ };
+ const end = {
+ x: segEnd[0],
+ y: segEnd[1]
+ };
+ const arcGen = new arc.GreatCircle(start, end);
+ const arcline = arcGen.Arc(25, {});
+ arcline.geometries.forEach((arcGeom) => {
+ coords.push(arcGeom.coords);
+ });
+ });
+ return new MultiLineString(coords);
+ };
+
+ function transformPolygonArc (geom) {
+ let coords = [];
+ const polyCoords = geom.getCoordinates()[0];
+ for (let i = 0; i < polyCoords.length - 1; i++) {
+ const start = {
+ x: polyCoords[i][0],
+ y: polyCoords[i][1]
+ };
+ const end = {
+ x: polyCoords[i + 1][0],
+ y: polyCoords[i + 1][1]
+ };
+ const arcGen = new arc.GreatCircle(start, end);
+ const arcline = arcGen.Arc(25, {});
+ arcline.geometries.forEach((arcGeom) => {
+ coords = coords.concat(arcGeom.coords);
+ });
+ }
+ const poly = new Polygon(coords);
+ return poly;
+ };
+
+ /**
+ *
+ * @param {*} feature
+ */
+ function transformGeometry (type) {
+ return (feature) => {
+ const geometry = feature.getGeometry();
+ if (geometry instanceof LineString && type === 'LineString') {
+ return transformLineStringArc(geometry);
+ }
+ if (geometry instanceof Polygon && type === 'Polygon') {
+ return transformPolygonArc(geometry);
+ }
+ return geometry;
+ };
+ }
+
/**
* Add the map interactionn
* @param {String} measureType
*/
function addInteraction(measureType) {
const type = (measureType === 'area' ? 'Polygon' : 'LineString');
- draw = getDraw(source, type);
+ draw = getDraw(type);
+ vector = getVectorLayer(type);
vector.setMap(map);
map.addInteraction(draw);
createMeasureTooltip();
@@ -110,9 +215,9 @@ export function measure (map) {
draw.on('drawend', drawEndCallback, this);
}
- self.initMeasurement = (type) => {
+ self.initMeasurement = (measureType) => {
map.on('pointermove', pointerMoveHandler);
- addInteraction(type);
+ addInteraction(measureType);
};
self.toggleUnits = (unit) => {
@@ -132,13 +237,13 @@ export function measure (map) {
return self;
}
-const convertKmToMiles = (km) => km * 0.62137;
+// const convertKmToMiles = (km) => km * 0.62137;
-const convertSquareKmToMiles = (squareKm) => squareKm * 0.38610;
+// const convertSquareKmToMiles = (squareKm) => squareKm * 0.38610;
-const convertMilesToKm = (miles) => miles / 0.62137;
+// const convertMilesToKm = (miles) => miles / 0.62137;
-const convertSquareMilesToKm = (squareMiles) => squareMiles / 0.38610;
+// const convertSquareMilesToKm = (squareMiles) => squareMiles / 0.38610;
const formatLength = (line, projection) => {
const length = getLength(line, { projection });
@@ -157,46 +262,3 @@ const formatArea = (polygon, projection) => {
return `${(Math.round(area * 100) / 100).toLocaleString()} m<sup>2</sup>`;
}
};
-
-const getVectorLayer = (source) => {
- return new VectorLayer({
- source,
- style: new Style({
- fill: new Fill({
- color: 'rgba(213, 78, 33, 0.1)'
- }),
- stroke: new Stroke({
- color: 'rgba(255, 100, 6, 1)',
- lineJoin: 'round',
- width: 3
- })
- })
- });
-};
-
-const getDraw = (source, type) => {
- return new Draw({
- source,
- type,
- style: new Style({
- fill: new Fill({
- color: 'rgba(213, 78, 33, 0.1)'
- }),
- stroke: new Stroke({
- color: 'rgba(255, 100, 6, 1)',
- lineDash: [10, 20],
- lineJoin: 'round',
- width: 4
- }),
- image: new CircleStyle({
- radius: 7,
- stroke: new Stroke({
- color: 'rgba(0, 0, 0, 0.7)'
- }),
- fill: new Fill({
- color: 'rgba(255, 255, 255, 0.3)'
- })
- })
- })
- });
-};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index ebb76384d..7ad16e7df 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -818,7 +818,7 @@ export function mapui(models, config, store, ui) {
const measureArea = () => {
const proj = self.selected.getView().getProjection().getCode();
- measureTools[proj].initMeasurement('distance');
+ measureTools[proj].initMeasurement('area');
};
const clearMeasurements = () => {