MCPcopy Index your code
hub / github.com/Maps4HTML/MapML.js / click

Method click

src/map-feature.js:685–722  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

683
684 // a method that simulates a click, or invoking the user-defined click event
685 click() {
686 let g = this._groupEl,
687 rect = g.getBoundingClientRect();
688 let event = new MouseEvent('click', {
689 clientX: rect.x + rect.width / 2,
690 clientY: rect.y + rect.height / 2,
691 button: 0
692 });
693 let properties = this.querySelector('map-properties');
694 if (g.getAttribute('role') === 'link') {
695 for (let path of g.children) {
696 path.mousedown.call(this._geometry, event);
697 path.mouseup.call(this._geometry, event);
698 }
699 }
700 // dispatch click event for map-feature to allow events entered by 'addEventListener'
701 let clickEv = new PointerEvent('click', { cancelable: true });
702 clickEv.originalEvent = event;
703 this.dispatchEvent(clickEv);
704 // for custom projection, map-layer element may disconnect and re-attach to the map after the click
705 // so check whether map-feature element is still connected before any further operations
706 if (properties && this.isConnected) {
707 let geometry = this._geometry,
708 shapes = geometry._layers;
709 // close popup if the popup is currently open
710 for (let id in shapes) {
711 if (shapes[id].isPopupOpen()) {
712 shapes[id].closePopup();
713 }
714 }
715 if (geometry.isPopupOpen()) {
716 geometry.closePopup();
717 } else if (!clickEv.originalEvent.cancelBubble) {
718 // If stopPropagation is not set on originalEvent by user
719 geometry.openPopup();
720 }
721 }
722 }
723
724 // a method that sets the current focus to the <g> element, or invoking the user-defined focus event
725 // options (optional): as options parameter for native HTMLElement

Calls 1

getAttributeMethod · 0.80

Tested by

no test coverage detected