Skip to content

Commit 5cec011

Browse files
authored
uimaker support min/max zoom (#1323)
1 parent fc6e8f2 commit 5cec011

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

src/ui/UIComponent.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const options = {
4444
'animationDuration': 500,
4545
'pitchWithMap': false,
4646
'rotateWithMap': false,
47+
'visible': true
4748
};
4849

4950
/**
@@ -133,7 +134,7 @@ class UIComponent extends Eventable(Class) {
133134
if (!map) {
134135
return this;
135136
}
136-
137+
this.options['visible'] = true;
137138
if (!this._mapEventsOn) {
138139
this._switchMapEvents('on');
139140
}
@@ -201,8 +202,10 @@ class UIComponent extends Eventable(Class) {
201202
dom.style[TRANSFORM] = this._toCSSTranslate(this._pos) + ' scale(0)';
202203
}
203204
}
204-
205-
dom.style.display = '';
205+
//not support zoom filter show dom
206+
if (!this.isSupportZoomFilter()) {
207+
dom.style.display = '';
208+
}
206209

207210
if (this.options['eventsToStop']) {
208211
on(dom, this.options['eventsToStop'], stopPropagation);
@@ -243,7 +246,7 @@ class UIComponent extends Eventable(Class) {
243246
if (!this.getDOM() || !this.getMap()) {
244247
return this;
245248
}
246-
249+
this.options['visible'] = false;
247250
const anim = this._getAnimation(),
248251
dom = this.getDOM();
249252
if (!this.options['animationOnHide']) {
@@ -284,6 +287,9 @@ class UIComponent extends Eventable(Class) {
284287
* @returns {Boolean} true|false
285288
*/
286289
isVisible() {
290+
if (!this.options['visible']) {
291+
return false;
292+
}
287293
const dom = this.getDOM();
288294
return this.getMap() && dom && dom.parentNode && dom.style.display !== 'none';
289295
}
@@ -629,6 +635,10 @@ class UIComponent extends Eventable(Class) {
629635
}
630636
}
631637

638+
isSupportZoomFilter() {
639+
return false;
640+
}
641+
632642
/*
633643
*
634644
* @param {Geometry||ui.UIMarker} owner

src/ui/UIMarker.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isString, flash } from '../core/util';
1+
import { isString, flash, isNil, extend } from '../core/util';
22
import { on, off, createEl, stopPropagation } from '../core/util/dom';
33
import Browser from '../core/Browser';
44
import Handler from '../handler/Handler';
@@ -23,7 +23,9 @@ const options = {
2323
'draggable': false,
2424
'single': false,
2525
'content': null,
26-
'altitude': 0
26+
'altitude': 0,
27+
'minZoom': 0,
28+
'maxZoom': null
2729
};
2830

2931
const domEvents =
@@ -438,6 +440,47 @@ class UIMarker extends Handlerable(UIComponent) {
438440
return this.getMap().coordToViewPoint(this._coordinate, undefined, alt)
439441
._add(this.options['dx'], this.options['dy']);
440442
}
443+
444+
_getDefaultEvents() {
445+
return extend({}, super._getDefaultEvents(), { 'zooming zoomend': this.onZoomFilter });
446+
}
447+
448+
_setPosition() {
449+
//show/hide zoomFilter
450+
this.onZoomFilter();
451+
super._setPosition();
452+
}
453+
454+
onZoomFilter() {
455+
const dom = this.getDOM();
456+
if (!dom) return;
457+
if (!this.isVisible() && dom.style.display !== 'none') {
458+
dom.style.display = 'none';
459+
} else if (this.isVisible() && dom.style.display === 'none') {
460+
dom.style.display = '';
461+
}
462+
}
463+
464+
isVisible() {
465+
const map = this.getMap();
466+
if (!map) {
467+
return false;
468+
}
469+
if (!this.options['visible']) {
470+
return false;
471+
}
472+
const zoom = map.getZoom();
473+
const { minZoom, maxZoom } = this.options;
474+
if (!isNil(minZoom) && zoom < minZoom || (!isNil(maxZoom) && zoom > maxZoom)) {
475+
return false;
476+
}
477+
const dom = this.getDOM();
478+
return dom && true;
479+
}
480+
481+
isSupportZoomFilter() {
482+
return true;
483+
}
441484
}
442485

443486
UIMarker.mergeOptions(options);

0 commit comments

Comments
 (0)