Skip to content
Snippets Groups Projects
Commit 17970f2a authored by Jakob Severin Steffensen Hjelseth's avatar Jakob Severin Steffensen Hjelseth
Browse files

Merge branch '13-union' into 'dev'

Resolve "Union"

See merge request !38
parents 041abaf4 c67d666f
No related branches found
No related tags found
2 merge requests!39Dev,!38Resolve "Union"
......@@ -180,6 +180,17 @@
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"/>
</svg>
</div>
<p>Choose the first layer to union:</p>
<select id="unionSelect_1"></select>
<p>Choose the second layer:</p>
<select id="unionSelect_2"></select>
<p>Choose a name for the union:</p>
<input id="unionName"><br>
<button class="button" style="font-size: 25px;" onclick="union()">Make union</button>
</div>
<div id="tutorialBox" class="box">
......@@ -234,6 +245,7 @@
<script src="javascript/difference.js"></script>
<script src="javascript/turfFormatConverter.js"></script>
<script src="javascript/intersect.js"></script>
<script src="javascript/union.js"></script>
<!-- Imported js -->
<!-- <script src="https://unpkg.com/shpjs@latest/dist/shp.js"></script> -->
......
......@@ -23,6 +23,6 @@ function difference() {
document.getElementById("differenceName").value = "";
fillDoubleSelect("differenceSelect");
} catch(failure) {
alert(failure)
alert(failure);
}
}
......@@ -21,7 +21,7 @@ function intersection() {
updateSidebar();
handleLayer(name);
document.getElementById("intersectionName").value = "";
fillDoubleSelect("intersectionSelect")
fillDoubleSelect("intersectionSelect");
} catch(failure) {
alert(failure);
}
......
......@@ -19,7 +19,7 @@ function closeNav() {
function openBox(id) {
if (boolskBox) {
closeBox(box)
closeBox(box);
}
if (boolskNav) {
closeNav();
......@@ -34,6 +34,8 @@ function openBox(id) {
fillSelect("dissolveSelect");
} else if (id == "intersectionBox") {
fillDoubleSelect("intersectionSelect");
} else if (id == "unionBox") {
fillDoubleSelect("unionSelect");
}
document.getElementById(String(id)).style.width = "40vw";
......
......@@ -6,7 +6,7 @@ konvertere mellom feature collections og format godtatt av turf
function featureCollectionToMultiPolygon(layer) { // layer er her et GeoJSON-lag
if (layer["type"] == "FeatureCollection") {
var coords = [];
var features = layer["features"]
var features = layer["features"];
for (var i = 0; i < features.length; i++) {
coords.push(features[i]["geometry"]["coordinates"]);
......
function union() {
var input1 = document.getElementById("unionSelect_1").value;
var layer1 = overlayMaps[input1].toGeoJSON();
var input2 = document.getElementById("unionSelect_2").value;
var layer2 = overlayMaps[input2].toGeoJSON();
var name = document.getElementById("unionName").value;
// Må konverteres fra feature collection til multipolygon:
var coords1 = featureCollectionToMultiPolygon(layer1);
var coords2 = featureCollectionToMultiPolygon(layer2);
var multiPolygon1 = turf.multiPolygon(coords1);
var multiPolygon2 = turf.multiPolygon(coords2);
try {
var union = turf.union(multiPolygon1, multiPolygon2);
var newLayer = L.geoJSON(union);
overlayMaps[name] = newLayer;
updateSidebar();
handleLayer(name);
document.getElementById("unionName").value = "";
fillDoubleSelect("unionSelect");
} catch(failure) {
alert(failure);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment