@@ -41,7 +41,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
4141 xAxisIds = dragOptions . xaxes . map ( getAxId ) ,
4242 yAxisIds = dragOptions . yaxes . map ( getAxId ) ,
4343 allAxes = dragOptions . xaxes . concat ( dragOptions . yaxes ) ,
44- filterPoly , testPoly , mergedPolygons , currentPolygon ;
44+ filterPoly , testPoly , mergedPolygons , currentPolygon ,
45+ subtract = e . altKey ;
4546
4647 if ( mode === 'lasso' ) {
4748 filterPoly = filteredPolygon ( [ [ x0 , y0 ] ] , constants . BENDPX ) ;
@@ -193,7 +194,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
193194
194195 // create outline & tester
195196 if ( dragOptions . polygons && dragOptions . polygons . length ) {
196- mergedPolygons = joinPolygons ( dragOptions . mergedPolygons , currentPolygon ) ;
197+ mergedPolygons = mergePolygons ( dragOptions . mergedPolygons , currentPolygon , subtract ) ;
198+ currentPolygon . subtract = subtract ;
197199 testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
198200 }
199201 else {
@@ -262,6 +264,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
262264
263265 if ( currentPolygon && dragOptions . polygons ) {
264266 // save last polygons
267+ currentPolygon . subtract = subtract ;
265268 dragOptions . polygons . push ( currentPolygon ) ;
266269
267270 // we have to keep reference to arrays container
@@ -272,8 +275,22 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
272275 } ;
273276} ;
274277
275- function joinPolygons ( list , poly ) {
276- var res = polybool . union ( {
278+ function mergePolygons ( list , poly , subtract ) {
279+ var res ;
280+
281+ if ( subtract ) {
282+ res = polybool . difference ( {
283+ regions : list ,
284+ inverted : false
285+ } , {
286+ regions : [ poly ] ,
287+ inverted : false
288+ } ) ;
289+
290+ return res . regions ;
291+ }
292+
293+ res = polybool . union ( {
277294 regions : list ,
278295 inverted : false
279296 } , {
0 commit comments