From 0a7c7a6016549abb8e0a0a3f2d07dd3fad253ff1 Mon Sep 17 00:00:00 2001 From: rowanwins Date: Mon, 13 Jan 2020 14:05:12 +1100 Subject: [PATCH 1/3] Use original geojson as input --- demo/js/index.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/demo/js/index.js b/demo/js/index.js index 1397981..60564a5 100644 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -2,7 +2,7 @@ import './coordinates'; import './polygoncontrol'; import './booleanopcontrol'; import * as martinez from '../../index'; -//var martinez = require('../../dist/martinez.min'); +// import * as martinez from '../../dist/martinez.min'; let mode = window.location.hash.substring(1); let path = '../test/fixtures/'; @@ -111,9 +111,7 @@ var map = window.map = L.map('image-map', { maxZoom: 20, center: [0, 0], zoom: 2, - crs: mode === 'geo' ? L.CRS.EPSG4326 : L.extend({}, L.CRS.Simple, { - transformation: new L.Transformation(1/8, 0, -1/8, 0) - }), + crs: L.CRS.Simple, editable: true }); @@ -127,13 +125,14 @@ map.addControl(new L.BooleanControl({ })); var drawnItems = window.drawnItems = L.geoJson().addTo(map); - +var rawData = null; function loadData(path) { console.log(path); fetch(path) .then((r) => r.json()) .then((json) => { drawnItems.addData(json); + rawData = json; map.fitBounds(drawnItems.getBounds().pad(0.05), { animate: false }); }); } @@ -141,21 +140,27 @@ function loadData(path) { function clear() { drawnItems.clearLayers(); results.clearLayers(); + rawData = null; } var reader = new jsts.io.GeoJSONReader(); var writer = new jsts.io.GeoJSONWriter(); +function getClippingPoly (layers) { + if (rawData.features.length > 1) return rawData.features[1]; + return layers[1].toGeoJSON(); +} + function run (op) { var layers = drawnItems.getLayers(); if (layers.length < 2) return; - var subject = layers[0].toGeoJSON(); - var clipping = layers[1].toGeoJSON(); + var subject = rawData !== null ? rawData.features[0] : layers[0].toGeoJSON(); + var clipping = getClippingPoly(layers); //console.log('input', subject, clipping, op); - subject = JSON.parse(JSON.stringify(subject)); - clipping = JSON.parse(JSON.stringify(clipping)); + // subject = JSON.parse(JSON.stringify(subject)); + // clipping = JSON.parse(JSON.stringify(clipping)); var operation; if (op === OPERATIONS.INTERSECTION) { @@ -178,9 +183,8 @@ function run (op) { var result = operation(subject.geometry.coordinates, clipping.geometry.coordinates); console.timeEnd('martinez'); - //if (op === OPERATIONS.UNION) result = result[0]; console.log('result', result); - // console.log(JSON.stringify(result)) + // console.log(JSON.stringify(result)); results.clearLayers(); if (result !== null) { @@ -208,17 +212,11 @@ function run (op) { } res = writer.write(res); console.timeEnd('jsts'); - console.log(res); + // console.log('JSTS result', res); }, 500); } } -//drawnItems.addData(oneInside); -//drawnItems.addData(twoPointedTriangles); -//drawnItems.addData(selfIntersecting); -//drawnItems.addData(holes); -//drawnItems.addData(data); - map.on('editable:created', function(evt) { drawnItems.addLayer(evt.layer); evt.layer.on('click', function(e) { From 85098c0c52d0558457867d91a09b42c8d99cd54f Mon Sep 17 00:00:00 2001 From: rowanwins Date: Mon, 13 Jan 2020 15:08:03 +1100 Subject: [PATCH 2/3] keep the original leaflet CRS settings as it helps zoom correctly --- demo/js/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demo/js/index.js b/demo/js/index.js index 60564a5..863f7d1 100644 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -111,7 +111,9 @@ var map = window.map = L.map('image-map', { maxZoom: 20, center: [0, 0], zoom: 2, - crs: L.CRS.Simple, + crs: mode === 'geo' ? L.CRS.EPSG4326 : L.extend({}, L.CRS.Simple, { + transformation: new L.Transformation(1/8, 0, -1/8, 0) + }), editable: true }); From a1b332b5ad77333da6dc98f3dcb2ff678b9512aa Mon Sep 17 00:00:00 2001 From: rowanwins Date: Mon, 13 Jan 2020 15:48:28 +1100 Subject: [PATCH 3/3] Fix handling when drawing own features --- demo/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/js/index.js b/demo/js/index.js index 863f7d1..4af1f22 100644 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -149,7 +149,7 @@ var reader = new jsts.io.GeoJSONReader(); var writer = new jsts.io.GeoJSONWriter(); function getClippingPoly (layers) { - if (rawData.features.length > 1) return rawData.features[1]; + if (rawData !== null && rawData.features.length > 1) return rawData.features[1]; return layers[1].toGeoJSON(); }