Skip to content

Commit

Permalink
rename private layer & set color in options
Browse files Browse the repository at this point in the history
  • Loading branch information
cXiaof committed Mar 31, 2021
1 parent 388f88b commit 00baac6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 69 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ new maptalks.PolygonBool()
- alterNative **Array** layer names of layer which you need to choose geometry on

`intersection(geometry, targets)` if no targets, start choose mode on map

`union(geometry, targets)` same as above

`diff(geometry, targets)` same as above

`xor(geometry, targets)` same as above

`submit(callback)` callback can get three attr, the result, deals(targets or choose-targets) and task name.

`cancel()`

`remove()`

## Contributing
Expand Down
35 changes: 12 additions & 23 deletions dist/maptalks.polygonbool.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -3569,9 +3569,12 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }

var uid = 'polygonbool@cXiaof';
var options = {
includeSame: true,
alterNative: []
alterNative: [],
colorHit: '#ffa400',
colorChosen: '#00bcd4'
};

var PolygonBool = function (_maptalks$Class) {
Expand All @@ -3582,10 +3585,8 @@ var PolygonBool = function (_maptalks$Class) {

var _this = _possibleConstructorReturn(this, _maptalks$Class.call(this, options));

_this._layerName = maptalks.INTERNAL_LAYER_PREFIX + '_POLYGONBOOL';
_this._layerName = '' + maptalks.INTERNAL_LAYER_PREFIX + uid;
_this._chooseGeos = [];
_this._colorHit = '#ffa400';
_this._colorChoose = '#00bcd4';
return _this;
}

Expand Down Expand Up @@ -3618,16 +3619,13 @@ var PolygonBool = function (_maptalks$Class) {
var result = this._dealWithTargets(targets);
callback(result, this._deals, this._task);
this.remove();
return this;
};

PolygonBool.prototype.cancel = function cancel() {
this.remove();
return this;
};

PolygonBool.prototype.remove = function remove() {
var map = this._map;
if (this._chooseLayer) this._chooseLayer.remove();
this._chooseGeos = [];
this._offMapEvents();
Expand All @@ -3636,7 +3634,6 @@ var PolygonBool = function (_maptalks$Class) {
delete this._chooseLayer;
delete this._mousemove;
delete this._click;
return this;
};

PolygonBool.prototype._setTaskSafety = function _setTaskSafety(task) {
Expand Down Expand Up @@ -3682,21 +3679,13 @@ var PolygonBool = function (_maptalks$Class) {
};

PolygonBool.prototype._registerMapEvents = function _registerMapEvents() {
if (!this._mousemove) {
var map = this._map;
this._mousemove = this._mousemoveEvents.bind(this);
this._click = this._clickEvents.bind(this);
map.on('mousemove', this._mousemove, this);
map.on('click', this._click, this);
}
map.on('mousemove', this._mousemoveEvents, this);
map.on('click', this._clickEvents, this);
};

PolygonBool.prototype._offMapEvents = function _offMapEvents() {
if (this._mousemove) {
var map = this._map;
map.off('mousemove', this._mousemove, this);
map.off('click', this._click, this);
}
map.off('mousemove', this._mousemoveEvents, this);
map.off('click', this._clickEvents, this);
};

PolygonBool.prototype._mousemoveEvents = function _mousemoveEvents(e) {
Expand Down Expand Up @@ -3754,7 +3743,7 @@ var PolygonBool = function (_maptalks$Class) {

PolygonBool.prototype._getSymbolOrDefault = function _getSymbolOrDefault(geo, type) {
var symbol = geo.getSymbol();
var color = this['_color' + type];
var color = this.options['color' + type];
var lineWidth = 4;
if (symbol) {
for (var key in symbol) {
Expand All @@ -3772,7 +3761,7 @@ var PolygonBool = function (_maptalks$Class) {
return result.updateSymbol(symbol).addTo(this._chooseLayer);
};

PolygonBool.prototype._clickEvents = function _clickEvents(e) {
PolygonBool.prototype._clickEvents = function _clickEvents() {
if (this.hitGeo) {
var coordHit = this._getSafeCoords(this.hitGeo);
this._setChooseGeosExceptHit(coordHit);
Expand All @@ -3797,7 +3786,7 @@ var PolygonBool = function (_maptalks$Class) {

this._chooseLayer.clear();
this._chooseGeos.forEach(function (geo) {
var chooseSymbol = _this4._getSymbolOrDefault(geo, 'Choose');
var chooseSymbol = _this4._getSymbolOrDefault(geo, 'Chosen');
_this4._copyGeoUpdateSymbol(geo, chooseSymbol);
});
};
Expand Down
35 changes: 12 additions & 23 deletions dist/maptalks.polygonbool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3575,9 +3575,12 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }

var uid = 'polygonbool@cXiaof';
var options = {
includeSame: true,
alterNative: []
alterNative: [],
colorHit: '#ffa400',
colorChosen: '#00bcd4'
};

var PolygonBool = function (_maptalks$Class) {
Expand All @@ -3588,10 +3591,8 @@ var PolygonBool = function (_maptalks$Class) {

var _this = _possibleConstructorReturn(this, _maptalks$Class.call(this, options));

_this._layerName = maptalks.INTERNAL_LAYER_PREFIX + '_POLYGONBOOL';
_this._layerName = '' + maptalks.INTERNAL_LAYER_PREFIX + uid;
_this._chooseGeos = [];
_this._colorHit = '#ffa400';
_this._colorChoose = '#00bcd4';
return _this;
}

Expand Down Expand Up @@ -3624,16 +3625,13 @@ var PolygonBool = function (_maptalks$Class) {
var result = this._dealWithTargets(targets);
callback(result, this._deals, this._task);
this.remove();
return this;
};

PolygonBool.prototype.cancel = function cancel() {
this.remove();
return this;
};

PolygonBool.prototype.remove = function remove() {
var map = this._map;
if (this._chooseLayer) this._chooseLayer.remove();
this._chooseGeos = [];
this._offMapEvents();
Expand All @@ -3642,7 +3640,6 @@ var PolygonBool = function (_maptalks$Class) {
delete this._chooseLayer;
delete this._mousemove;
delete this._click;
return this;
};

PolygonBool.prototype._setTaskSafety = function _setTaskSafety(task) {
Expand Down Expand Up @@ -3688,21 +3685,13 @@ var PolygonBool = function (_maptalks$Class) {
};

PolygonBool.prototype._registerMapEvents = function _registerMapEvents() {
if (!this._mousemove) {
var map = this._map;
this._mousemove = this._mousemoveEvents.bind(this);
this._click = this._clickEvents.bind(this);
map.on('mousemove', this._mousemove, this);
map.on('click', this._click, this);
}
map.on('mousemove', this._mousemoveEvents, this);
map.on('click', this._clickEvents, this);
};

PolygonBool.prototype._offMapEvents = function _offMapEvents() {
if (this._mousemove) {
var map = this._map;
map.off('mousemove', this._mousemove, this);
map.off('click', this._click, this);
}
map.off('mousemove', this._mousemoveEvents, this);
map.off('click', this._clickEvents, this);
};

PolygonBool.prototype._mousemoveEvents = function _mousemoveEvents(e) {
Expand Down Expand Up @@ -3760,7 +3749,7 @@ var PolygonBool = function (_maptalks$Class) {

PolygonBool.prototype._getSymbolOrDefault = function _getSymbolOrDefault(geo, type) {
var symbol = geo.getSymbol();
var color = this['_color' + type];
var color = this.options['color' + type];
var lineWidth = 4;
if (symbol) {
for (var key in symbol) {
Expand All @@ -3778,7 +3767,7 @@ var PolygonBool = function (_maptalks$Class) {
return result.updateSymbol(symbol).addTo(this._chooseLayer);
};

PolygonBool.prototype._clickEvents = function _clickEvents(e) {
PolygonBool.prototype._clickEvents = function _clickEvents() {
if (this.hitGeo) {
var coordHit = this._getSafeCoords(this.hitGeo);
this._setChooseGeosExceptHit(coordHit);
Expand All @@ -3803,7 +3792,7 @@ var PolygonBool = function (_maptalks$Class) {

this._chooseLayer.clear();
this._chooseGeos.forEach(function (geo) {
var chooseSymbol = _this4._getSymbolOrDefault(geo, 'Choose');
var chooseSymbol = _this4._getSymbolOrDefault(geo, 'Chosen');
_this4._copyGeoUpdateSymbol(geo, chooseSymbol);
});
};
Expand Down
2 changes: 1 addition & 1 deletion dist/maptalks.polygonbool.min.js

Large diffs are not rendered by default.

Binary file modified dist/maptalks.polygonbool.min.js.gz
Binary file not shown.
33 changes: 11 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import boolean from 'martinez-polygon-clipping'
import isEqual from 'lodash.isequal'
import tail from 'lodash.tail'

const uid = 'polygonbool@cXiaof'
const options = {
includeSame: true,
alterNative: [],
colorHit: '#ffa400',
colorChosen: '#00bcd4',
}

export class PolygonBool extends maptalks.Class {
constructor(options) {
super(options)
this._layerName = `${maptalks.INTERNAL_LAYER_PREFIX}_POLYGONBOOL`
this._layerName = `${maptalks.INTERNAL_LAYER_PREFIX}${uid}`
this._chooseGeos = []
this._colorHit = '#ffa400'
this._colorChoose = '#00bcd4'
}

intersection(geometry, targets) {
Expand Down Expand Up @@ -41,16 +42,13 @@ export class PolygonBool extends maptalks.Class {
const result = this._dealWithTargets(targets)
callback(result, this._deals, this._task)
this.remove()
return this
}

cancel() {
this.remove()
return this
}

remove() {
const map = this._map
if (this._chooseLayer) this._chooseLayer.remove()
this._chooseGeos = []
this._offMapEvents()
Expand All @@ -59,7 +57,6 @@ export class PolygonBool extends maptalks.Class {
delete this._chooseLayer
delete this._mousemove
delete this._click
return this
}

_setTaskSafety(task) {
Expand Down Expand Up @@ -112,21 +109,13 @@ export class PolygonBool extends maptalks.Class {
}

_registerMapEvents() {
if (!this._mousemove) {
const map = this._map
this._mousemove = this._mousemoveEvents.bind(this)
this._click = this._clickEvents.bind(this)
map.on('mousemove', this._mousemove, this)
map.on('click', this._click, this)
}
map.on('mousemove', this._mousemoveEvents, this)
map.on('click', this._clickEvents, this)
}

_offMapEvents() {
if (this._mousemove) {
const map = this._map
map.off('mousemove', this._mousemove, this)
map.off('click', this._click, this)
}
map.off('mousemove', this._mousemoveEvents, this)
map.off('click', this._clickEvents, this)
}

_mousemoveEvents(e) {
Expand Down Expand Up @@ -185,7 +174,7 @@ export class PolygonBool extends maptalks.Class {

_getSymbolOrDefault(geo, type) {
let symbol = geo.getSymbol()
const color = this[`_color${type}`]
const color = this.options[`color${type}`]
const lineWidth = 4
if (symbol) {
for (let key in symbol) {
Expand All @@ -206,7 +195,7 @@ export class PolygonBool extends maptalks.Class {
return result.updateSymbol(symbol).addTo(this._chooseLayer)
}

_clickEvents(e) {
_clickEvents() {
if (this.hitGeo) {
const coordHit = this._getSafeCoords(this.hitGeo)
this._setChooseGeosExceptHit(coordHit)
Expand All @@ -229,7 +218,7 @@ export class PolygonBool extends maptalks.Class {
_updateChooseGeos() {
this._chooseLayer.clear()
this._chooseGeos.forEach((geo) => {
const chooseSymbol = this._getSymbolOrDefault(geo, 'Choose')
const chooseSymbol = this._getSymbolOrDefault(geo, 'Chosen')
this._copyGeoUpdateSymbol(geo, chooseSymbol)
})
}
Expand Down

0 comments on commit 00baac6

Please sign in to comment.