Skip to content

Commit 01990ed

Browse files
rowanwinsw8r
andauthored
Use original geojson as input (#119)
* Use original geojson as input * keep the original leaflet CRS settings as it helps zoom correctly * Fix handling when drawing own features Co-authored-by: Alexander Milevski <[email protected]>
1 parent 89338f6 commit 01990ed

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

demo/js/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './coordinates';
22
import './polygoncontrol';
33
import './booleanopcontrol';
44
import * as martinez from '../../index';
5-
//var martinez = require('../../dist/martinez.min');
5+
// import * as martinez from '../../dist/martinez.min';
66

77
let mode = window.location.hash.substring(1);
88
let path = '../test/fixtures/';
@@ -127,35 +127,42 @@ map.addControl(new L.BooleanControl({
127127
}));
128128

129129
var drawnItems = window.drawnItems = L.geoJson().addTo(map);
130-
130+
var rawData = null;
131131
function loadData(path) {
132132
console.log(path);
133133
fetch(path)
134134
.then((r) => r.json())
135135
.then((json) => {
136136
drawnItems.addData(json);
137+
rawData = json;
137138
map.fitBounds(drawnItems.getBounds().pad(0.05), { animate: false });
138139
});
139140
}
140141

141142
function clear() {
142143
drawnItems.clearLayers();
143144
results.clearLayers();
145+
rawData = null;
144146
}
145147

146148
var reader = new jsts.io.GeoJSONReader();
147149
var writer = new jsts.io.GeoJSONWriter();
148150

151+
function getClippingPoly (layers) {
152+
if (rawData !== null && rawData.features.length > 1) return rawData.features[1];
153+
return layers[1].toGeoJSON();
154+
}
155+
149156
function run (op) {
150157
var layers = drawnItems.getLayers();
151158
if (layers.length < 2) return;
152-
var subject = layers[0].toGeoJSON();
153-
var clipping = layers[1].toGeoJSON();
159+
var subject = rawData !== null ? rawData.features[0] : layers[0].toGeoJSON();
160+
var clipping = getClippingPoly(layers);
154161

155162
//console.log('input', subject, clipping, op);
156163

157-
subject = JSON.parse(JSON.stringify(subject));
158-
clipping = JSON.parse(JSON.stringify(clipping));
164+
// subject = JSON.parse(JSON.stringify(subject));
165+
// clipping = JSON.parse(JSON.stringify(clipping));
159166

160167
var operation;
161168
if (op === OPERATIONS.INTERSECTION) {
@@ -178,9 +185,8 @@ function run (op) {
178185
var result = operation(subject.geometry.coordinates, clipping.geometry.coordinates);
179186
console.timeEnd('martinez');
180187

181-
//if (op === OPERATIONS.UNION) result = result[0];
182188
console.log('result', result);
183-
// console.log(JSON.stringify(result))
189+
// console.log(JSON.stringify(result));
184190
results.clearLayers();
185191

186192
if (result !== null) {
@@ -208,17 +214,11 @@ function run (op) {
208214
}
209215
res = writer.write(res);
210216
console.timeEnd('jsts');
211-
console.log(res);
217+
// console.log('JSTS result', res);
212218
}, 500);
213219
}
214220
}
215221

216-
//drawnItems.addData(oneInside);
217-
//drawnItems.addData(twoPointedTriangles);
218-
//drawnItems.addData(selfIntersecting);
219-
//drawnItems.addData(holes);
220-
//drawnItems.addData(data);
221-
222222
map.on('editable:created', function(evt) {
223223
drawnItems.addLayer(evt.layer);
224224
evt.layer.on('click', function(e) {

0 commit comments

Comments
 (0)