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

Masse (ferdig?) + småfiks

parent 8a449302
No related branches found
No related tags found
2 merge requests!39Dev,!38Resolve "Union"
...@@ -180,6 +180,17 @@ ...@@ -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"/> <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> </svg>
</div> </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>
<div id="tutorialBox" class="box"> <div id="tutorialBox" class="box">
...@@ -234,6 +245,7 @@ ...@@ -234,6 +245,7 @@
<script src="javascript/difference.js"></script> <script src="javascript/difference.js"></script>
<script src="javascript/turfFormatConverter.js"></script> <script src="javascript/turfFormatConverter.js"></script>
<script src="javascript/intersect.js"></script> <script src="javascript/intersect.js"></script>
<script src="javascript/union.js"></script>
<!-- Imported js --> <!-- Imported js -->
<!-- <script src="https://unpkg.com/shpjs@latest/dist/shp.js"></script> --> <!-- <script src="https://unpkg.com/shpjs@latest/dist/shp.js"></script> -->
......
...@@ -23,6 +23,6 @@ function difference() { ...@@ -23,6 +23,6 @@ function difference() {
document.getElementById("differenceName").value = ""; document.getElementById("differenceName").value = "";
fillDoubleSelect("differenceSelect"); fillDoubleSelect("differenceSelect");
} catch(failure) { } catch(failure) {
alert(failure) alert(failure);
} }
} }
...@@ -21,7 +21,7 @@ function intersection() { ...@@ -21,7 +21,7 @@ function intersection() {
updateSidebar(); updateSidebar();
handleLayer(name); handleLayer(name);
document.getElementById("intersectionName").value = ""; document.getElementById("intersectionName").value = "";
fillDoubleSelect("intersectionSelect") fillDoubleSelect("intersectionSelect");
} catch(failure) { } catch(failure) {
alert(failure); alert(failure);
} }
......
...@@ -19,7 +19,7 @@ function closeNav() { ...@@ -19,7 +19,7 @@ function closeNav() {
function openBox(id) { function openBox(id) {
if (boolskBox) { if (boolskBox) {
closeBox(box) closeBox(box);
} }
if (boolskNav) { if (boolskNav) {
closeNav(); closeNav();
...@@ -34,6 +34,8 @@ function openBox(id) { ...@@ -34,6 +34,8 @@ function openBox(id) {
fillSelect("dissolveSelect"); fillSelect("dissolveSelect");
} else if (id == "intersectionBox") { } else if (id == "intersectionBox") {
fillDoubleSelect("intersectionSelect"); fillDoubleSelect("intersectionSelect");
} else if (id == "unionBox") {
fillDoubleSelect("unionSelect");
} }
document.getElementById(String(id)).style.width = "40vw"; document.getElementById(String(id)).style.width = "40vw";
......
...@@ -6,7 +6,7 @@ konvertere mellom feature collections og format godtatt av turf ...@@ -6,7 +6,7 @@ konvertere mellom feature collections og format godtatt av turf
function featureCollectionToMultiPolygon(layer) { // layer er her et GeoJSON-lag function featureCollectionToMultiPolygon(layer) { // layer er her et GeoJSON-lag
if (layer["type"] == "FeatureCollection") { if (layer["type"] == "FeatureCollection") {
var coords = []; var coords = [];
var features = layer["features"] var features = layer["features"];
for (var i = 0; i < features.length; i++) { for (var i = 0; i < features.length; i++) {
coords.push(features[i]["geometry"]["coordinates"]); 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