Skip to content

Commit

Permalink
Added serialization, deserialization and export to GeoJSON to the lin…
Browse files Browse the repository at this point in the history
…e layer
  • Loading branch information
matafokka committed Feb 15, 2022
1 parent a30e218 commit 2132507
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
6 changes: 6 additions & 0 deletions SynthBase/SynthBaseLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ L.ALS.SynthBaseLayer = L.ALS.Layer.extend(/** @lends L.ALS.SynthBaseLayer.protot

this.serializationIgnoreList.push("_airportMarker", "toUpdateThickness");

/**
* Properties to copy to GeoJSON when exporting
* @type {string[]}
*/
this.propertiesToExport = ["cameraWidth", "cameraHeight", "pixelWidth", "focalLength", "flightHeight", "overlayBetweenPaths", "overlayBetweenImages", "imageScale", "ly", "Ly", "By", "lx", "Lx", "Bx", "GSI", "IFOV", "GIFOV", "FOV", "GFOV", "selectedArea", "timeBetweenCaptures"];

// Add airport
let icon = L.divIcon({
iconSize: null,
Expand Down
2 changes: 1 addition & 1 deletion SynthGridLayer/onMapZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ L.ALS.SynthGridLayer.prototype._onMapZoom = function () {
this._onMapPan(); // Redraw polygons
}

L.ALS.SynthGridLayer.prototype.hideOrShowGroups = function (hide, shouldHideWidgets) {
L.ALS.SynthGridLayer.prototype.hideOrShowGroups = function (hide) {
let groups = [this.polygonGroup, this.bordersGroup, this.labelsGroup];

for (let group of groups)
Expand Down
42 changes: 39 additions & 3 deletions SynthLineLayer/SynthLineLayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require("./SynthLineWizard.js");
require("./SynthLineSettings.js");
const turfHelpers = require("@turf/helpers");
const MathTools = require("../MathTools.js");
const geojsonMerge = require("@mapbox/geojson-merge"); // Using this since turfHelpers.featureCollection() discards previously defined properties.

/**
* Geodesic line layer
Expand All @@ -27,7 +26,7 @@ L.ALS.SynthLineLayer = L.ALS.SynthBaseLayer.extend(/** @lends L.ALS.SynthLineLay
shapeOptions: {
color: "#ff0000",
weight: this.lineThicknessValue,
segmentsNumber: L.GEODESIC_SEGMENTS,
segmentsNumber: Math.round(L.GEODESIC_SEGMENTS / 4),
}
}
}, this.drawingGroup);
Expand Down Expand Up @@ -107,8 +106,45 @@ L.ALS.SynthLineLayer = L.ALS.SynthBaseLayer.extend(/** @lends L.ALS.SynthLineLay
this.onEditEnd();
},

toGeoJSON: function () {
let pathsMeta = {};
for (let prop of this.propertiesToExport) {
if (this[prop] !== undefined)
pathsMeta[prop] = this[prop];
}

return geojsonMerge.merge([
L.ALS.SynthBaseLayer.prototype.toGeoJSON.call(this, pathsMeta),
this.pointsGroup.toGeoJSON(),
]);
},

serialize: function (seenObjects) {
let layers = this.drawingGroup.getLayers(), lines = [];

for (let layer of layers)
lines.push(layer.getLatLngs());

let serialized = this.getObjectToSerializeTo(seenObjects);
serialized.lines = L.ALS.Serializable.serializeAnyObject(lines, seenObjects);
return serialized;
},

statics: {
wizard: L.ALS.SynthLineWizard,
settings: new L.ALS.SynthLineSettings(),

deserialize: function (serialized, layerSystem, settings, seenObjects) {
let object = L.ALS.Layer.deserialize(serialized, layerSystem, settings, seenObjects),
lines = L.ALS.Serializable.deserialize(serialized.lines, seenObjects);

for (let line of lines)
object.drawingGroup.addLayer(new L.Geodesic(line, object.drawControls.polyline.shapeOptions));

object.onEditEnd();

delete object.lines;
return object;
}
}
});
6 changes: 2 additions & 4 deletions SynthPolygonLayer/toGeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ L.ALS.SynthPolygonLayer.prototype.toGeoJSON = function () {
}

// See _calculateParameters
let parallelsProps = {name: "Flight paths by parallels"},
meridiansProps = {name: "Flight paths by meridians"},
params = ["cameraWidth", "cameraHeight", "pixelWidth", "focalLength", "flightHeight", "overlayBetweenPaths", "overlayBetweenImages", "imageScale", "ly", "Ly", "By", "lx", "Lx", "Bx", "GSI", "IFOV", "GIFOV", "FOV", "GFOV", "selectedArea", "timeBetweenCaptures"];
let parallelsProps = {name: "Flight paths by parallels"}, meridiansProps = {name: "Flight paths by meridians"};

for (let prop of [parallelsProps, meridiansProps]) {
for (let param of params)
for (let param of this.propertiesToExport)
prop[param] = this[param];
}

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@
},
"dependencies": {
"@electron/remote": "^2.0.1",
"leaflet-advanced-layer-system": "^2.1.7"
"leaflet-advanced-layer-system": "^2.1.8"
}
}

0 comments on commit 2132507

Please sign in to comment.