@progress/kendo-react-map
Version:
KendoReact Map package
16 lines (15 loc) • 15.3 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@progress/kendo-react-common"),require("prop-types"),require("@progress/kendo-charts"),require("@progress/kendo-react-popup"),require("@progress/kendo-svg-icons")):"function"==typeof define&&define.amd?define(["exports","react","@progress/kendo-react-common","prop-types","@progress/kendo-charts","@progress/kendo-react-popup","@progress/kendo-svg-icons"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).KendoReactMap={},e.React,e.KendoReactCommon,e.PropTypes,e.KendoCharts,e.KendoReactPopup,e.KendoSvgIcons)}(this,(function(e,t,n,r,o,s,a){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var p=i(t);const c=p.createContext(null);c.displayName="MapContext";const l=class extends p.Component{get optionsStore(){var e;return null==(e=this.context)?void 0:e.optionsStore}renderChildren(e,t){const{children:n}=e.props,{_mapKey:r,_parentStore:o}=this.props,s={...e.props,_mapCollectionIdxKey:`${r}_${t}`,_parentStore:o};return p.cloneElement(e,s,n)}render(){const{_mapKey:e,_parentStore:t,children:n}=this.props;return(t||this.optionsStore).dispatch({mapKey:e,payload:[]}),p.Children.map(n,((e,t)=>p.isValidElement(e)?this.renderChildren(e,t):e))}};l.contextType=c;let h=l;const u=e=>{let t,r=[];const o=o=>{t=e(t,o),n.canUseDOM&&r.forEach((e=>e()))};return o({}),{getState:()=>t,dispatch:o,subscribe:e=>(r.push(e),()=>r=r.filter((t=>t!==e)))}},d=(e,t)=>t.mapCollectionIdxKey?v.collectionConfigurationItem(e,t):t.mapKey?v.configurationItem(e,t):{},m=(e,t)=>{if(!t.type)return[];switch(t.type){case"add":return[...e,t.payload];case"remove":return e.filter((e=>e!==t.payload));default:return e}},v={configurationItem:(e,t)=>Object.assign(e,{[t.mapKey]:t.payload}),collectionConfigurationItem(e,t){let n=!1;const[r,o]=t.mapCollectionIdxKey.split("_"),s=e[r].map(((e,r)=>parseInt(o,10)===r?(n=!0,t.payload):e));return!1===n&&s.splice(parseInt(o,10),0,t.payload),Object.assign(e,{[r]:s})},themeItem(e,t){let n={};const r=Object.assign(n,e),{field:o,value:s}=t.payload,a=o.split(".");let i=a.shift();for(;a.length>0;)n=n[i]=n[i]||{},i=a.shift();return n[i]=s,r}},y=class extends p.Component{get optionsStore(){var e;return null==(e=this.context)?void 0:e.optionsStore}constructor(e){super(e),this.childStore=u(d)}render(){const{children:e}=this.props;return void 0!==e?p.Children.map(e,(e=>p.isValidElement(e)?this.renderChildren(e):e)):null}componentDidMount(){this.dispatch()}componentDidUpdate(){this.dispatch()}dispatch(){const{_mapKey:e,_mapCollectionIdxKey:t,_parentStore:n,children:r,...o}=this.props;(n||this.optionsStore).dispatch({mapKey:e,mapCollectionIdxKey:t,payload:Object.assign({},o,this.childStore.getState())})}renderChildren(e){const{children:t}=e.props,n={...e.props,_parentStore:this.childStore};return p.cloneElement(e,n,t)}};y.contextType=c;let g=y,f=class{constructor(e){this.target=e}},I=class extends f{constructor(e,t){super(t)}},b=class extends f{constructor(e,t){super(t),this.location=e.location,this.originalEvent=e.originalEvent}},E=class extends f{constructor(e,t){super(t),this.marker=e.marker,this.layer=e.layer}},S=class extends f{constructor(e,t){super(t),this.marker=e.marker,this.layer=e.layer}},M=class extends f{constructor(){super(...arguments),this.prevented=!1}preventDefault(){this.prevented=!0}isDefaultPrevented(){return this.prevented}},k=class extends M{constructor(e,t){super(t),this.marker=e.marker,this.layer=e.layer}},x=class extends f{constructor(e,t){super(t),this.origin=e.origin,this.center=e.center,this.originalEvent=e.originalEvent}},C=class extends f{constructor(e,t){super(t),this.origin=e.origin,this.center=e.center,this.originalEvent=e.originalEvent}},T=class extends f{constructor(e,t){super(t)}},O=class extends f{constructor(e,t){super(t),this.layer=e.layer,this.shape=e.shape,this.originalEvent=e.originalEvent}},w=class extends f{constructor(e,t){super(t),this.layer=e.layer,this.shape=e.shape,this.location=null,e.shape&&(this.dataItem=e.shape.dataItem,this.location=e.shape.location)}},L=class extends f{constructor(e,t){super(t),this.dataItem=e.dataItem,this.layer=e.layer,this.group=e.group,this.properties=e.properties}},A=class extends f{constructor(e,t){super(t),this.layer=e.layer,this.shape=e.shape,this.originalEvent=e.originalEvent}},K=class extends f{constructor(e,t){super(t),this.layer=e.layer,this.shape=e.shape,this.originalEvent=e.originalEvent}},D=class extends f{constructor(e,t){super(t),this.originalEvent=e.originalEvent}},N=class extends M{constructor(e,t){super(t),this.originalEvent=e.originalEvent}};const _={beforeReset:I,mapClick:b,markerActivate:E,markerClick:S,markerCreated:k,panEnd:x,pan:C,reset:T,shapeClick:O,shapeCreated:w,shapeFeatureCreated:L,shapeMouseEnter:A,shapeMouseLeave:K,zoomEnd:D,zoomStart:N};function P(e,t,n,r){const o=e[t];if(o&&Array.isArray(o))for(const e of o)if(!e.type||e.type!==r)return new Error(`${n} children should be Array of type ${r.displayName}.`);return null}const R={horizontal:"fit",vertical:"fit"},U=["k-tooltip","k-map-tooltip"],j=class extends p.Component{constructor(e){super(e),this.context=null,this.element=null,this.onMapMouseLeave=e=>{const{syntheticEvent:t}=e;return!!function(e,t){let n=e;for(;n&&n!==t;)n=n.parentNode;return!!n}(t.relatedTarget,this.element)},this.mapObserver=new o.InstanceObserver(this,{onMouseLeave:"onMapMouseLeave"})}componentDidMount(){var e;null==(e=this.context)||e.observersStore.dispatch({type:"add",payload:this.mapObserver})}render(){const{popupShown:e,popupAlign:t,popupOffset:n,popupStyles:r,popupContent:o,className:a}=this.props,i=[...U,a].join(" ").trim();return p.createElement(s.Popup,{animate:!0,popupAlign:t,offset:n,show:e,collision:R,className:"k-tooltip-wrapper"},p.createElement("div",{className:i,style:r,ref:e=>{this.element=e}},o()))}componentWillUnmount(){this.context.observersStore.dispatch({type:"remove",payload:this.mapObserver})}};j.contextType=c;let z=j;const V=class extends p.Component{constructor(){super(...arguments),this.context=null,this.state={popupShown:!1}}componentDidMount(){this.mapObserver=new o.InstanceObserver(this,{showTooltip:"onShowTooltip",hideTooltip:"onHideTooltip"}),this.context.observersStore.dispatch({type:"add",payload:this.mapObserver})}render(){const{popupContext:e,shared:t,className:n,...r}=this.state;if(!e||!this.state.popupShown)return null;const o=e.layerIndex,s=this.findRenderFunctionByLayer(o);if(!s)return null;const a=`k-map-${e.type}-tooltip`;return p.createElement(z,{...r,popupContent:()=>p.createElement("div",{className:"k-tooltip-content"},s(e)),className:a})}componentWillUnmount(){this.context.observersStore.dispatch({type:"remove",payload:this.mapObserver})}onShowTooltip(e){const{anchor:t,className:n}=e,r=this.createTooltipContext(e);this.setState({popupShown:!0,popupAlign:{vertical:"bottom",horizontal:"center"},popupOffset:t,popupContext:r,popupStyles:{position:"relative"},className:n})}onHideTooltip(){this.setState({popupShown:!1,popupStyles:{},className:void 0})}createTooltipContext(e){return e}findRenderFunctionByLayer(e){const t=this.context.optionsStore.getState().layers;return void 0!==t&&Array.isArray(t)&&void 0!==t[e]&&t[e].hasOwnProperty("tooltip")&&t[e].tooltip.hasOwnProperty("render")?t[e].tooltip.render:null}};V.contextType=c;let q=V;const W=Object.freeze({name:"@progress/kendo-react-map",productName:"KendoReact",productCode:"KENDOUIREACT",productCodes:["KENDOUIREACT"],publishDate:1651750998,version:"13.1.0",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning"});let B=class{constructor(e,t){this.sender=e,this.syntheticEvent=t}};const F={mapMarkerTargetIcon:a.mapMarkerTargetIcon,mapMarkerIcon:a.mapMarkerIcon,plusIcon:a.plusIcon,minusIcon:a.minusIcon,caretAltUpIcon:a.caretAltUpIcon,caretAltDownIcon:a.caretAltDownIcon,caretAltLeftIcon:a.caretAltLeftIcon,caretAltRightIcon:a.caretAltRightIcon},Z=class extends p.Component{constructor(e){super(e),this.mapInstance=null,this._element=null,this.optionsStore={},this.optionsUnsubscriber=Function.prototype,this.observersStore={},this.showLicenseWatermark=!1,this.iconsType="svg",this.svgIcons=F,this.onInit=e=>{this.mapInstance=e.sender},this.onRender=e=>{null!==this.mapInstance&&this.trigger("render",e)},this.onMapMouseLeave=e=>{const t=function(e,t){return new B(e,t)}(this,e);this.triggerDomEvent("onMouseLeave",t)?e.preventDefault():null!==this.mapInstance&&this.mapInstance.hideTooltip()},this.showLicenseWatermark=!n.validatePackage(W,{component:"Map"}),this.licenseMessage=n.getLicenseMessage(W),this.optionsStore=u(d),this.observersStore=u(m),this.childrenObserver=new o.InstanceObserver(this,{onMouseLeave:"onChildMouseLeave"}),this.contextValue={optionsStore:this.optionsStore,observersStore:this.observersStore,childrenObserver:this.childrenObserver},this.mapObserver=new o.InstanceObserver(this,{init:"onInit"})}get element(){return this._element}componentDidMount(){this.instantiateCoreMap(),this.optionsUnsubscriber=this.optionsStore.subscribe(this.refresh.bind(this))}componentWillUnmount(){this.optionsUnsubscriber(),null!==this.mapInstance&&(this.mapInstance.destroy(),this.mapInstance=null)}componentDidUpdate(e){const{dir:t,children:n,...r}=this.props;null!==this.mapInstance&&(Object.entries(e).filter((e=>"dir"!==e[0]&&"children"!==e[0])).some((e=>{const[t,n]=e;return!(r.hasOwnProperty(t)&&r[t]===n)}))&&this.refresh(),e.dir)}render(){const{style:e={},className:t,children:r}=this.props,o=Object.assign({},e,{position:"relative"}),s=p.createElement("div",{className:t,style:o,key:"mapElement"},p.createElement("div",{ref:e=>{this._element=e},className:"k-map",onMouseLeave:this.onMapMouseLeave},r));return p.createElement(p.Fragment,null,p.createElement(n.IconsContext.Consumer,null,(e=>p.createElement(c.Provider,{value:this.contextValue},p.createElement(q,{key:"tooltip"}),s,this.setIcons(e)))),this.showLicenseWatermark&&p.createElement(n.WatermarkOverlay,{message:this.licenseMessage}))}getMapOptions(){const{center:e,controls:t,minZoom:n,maxZoom:r,minSize:o,pannable:s,wraparound:a,zoom:i,zoomable:p}=this.props;let c={center:e,controls:t,minZoom:n,maxZoom:r,minSize:o,pannable:s,wraparound:a,zoom:i,zoomable:p,icons:{type:this.iconsType,svgIcons:this.svgIcons}};return c=Object.assign(c,this.optionsStore.getState()),c}get layers(){var e;return null==(e=this.mapInstance)?void 0:e.layers}get extent(){var e;return null==(e=this.mapInstance)?void 0:e.extent()}set extent(e){var t;null==(t=this.mapInstance)||t.extent(e)}resize(){}viewSize(){var e;return null==(e=this.mapInstance)?void 0:e.viewSize()}eventOffset(e){var t;return null==(t=this.mapInstance)?void 0:t.eventOffset(e)}eventToLayer(e){var t;return null==(t=this.mapInstance)?void 0:t.eventToLayer(e)}eventToLocation(e){var t;return null==(t=this.mapInstance)?void 0:t.eventToLocation(e)}eventToView(e){var t;return null==(t=this.mapInstance)?void 0:t.eventToView(e)}layerToLocation(e,t){var n;return null==(n=this.mapInstance)?void 0:n.layerToLocation(e,t)}locationToLayer(e,t){var n;return null==(n=this.mapInstance)?void 0:n.locationToLayer(e,t)}locationToView(e){var t;return null==(t=this.mapInstance)?void 0:t.locationToView(e)}viewToLocation(e,t){var n;return null==(n=this.mapInstance)?void 0:n.viewToLocation(e,t)}loadMarkers(e){const t=this.mapInstance.markers;t&&t._load(e)}refresh(){if(null!==this.mapInstance){const e=this.getMapOptions();this.props.onRefresh?this.props.onRefresh.call(void 0,e,this.mapInstance):this.mapInstance.setOptions(e)}}instantiateCoreMap(){const e=this.getMapOptions();this.mapInstance=new o.Map(this.element,e,{},{observer:this.mapObserver,sender:this})}trigger(e,t){const n="click"===e?"mapClick":e,r=function(e,t,n){if(_[e])return new _[e](t,n)}(n,t,this),o="on"+n.charAt(0).toUpperCase()+n.slice(1),s=this.observersStore.getState();let a=!1;for(let e=0;e<s.length;e++)s[e].trigger(n,t)&&(a=!0);return!1===a&&r&&this.props.hasOwnProperty(o)?(this.props[o].call(void 0,r),r.isDefaultPrevented&&r.isDefaultPrevented()):a}requiresHandlers(e){for(let t=0;t<e.length;t++){const n=e[t],r="on"+n.charAt(0).toUpperCase()+n.slice(1);if(this.props.hasOwnProperty(r))return!0}return!1}triggerDomEvent(e,t){const n=this.observersStore.getState();let r=!1;for(let o=0;o<n.length;o++)n[o].trigger(e,t)&&(r=!0);return r}setIcons(e){const{type:t,icons:n={}}=e,r={...F},o={mapMarkerTargetIcon:n.mapMarkerTargetIcon,mapMarkerIcon:n.mapMarkerIcon,plusIcon:n.plusIcon,minusIcon:n.minusIcon,caretAltUpIcon:n.caretAltUpIcon,caretAltDownIcon:n.caretAltDownIcon,caretAltLeftIcon:n.caretAltLeftIcon,caretAltRightIcon:n.caretAltRightIcon};let s;for(s in o)if(o[s]){const e=o[s];e&&"string"!=typeof e&&(r[s]=e)}return this.svgIcons=r,this.iconsType=t||"svg",null}};Z.propTypes={dir:r.string},Z.defaultProps={};let $=Z;const H=e=>p.createElement(h,{...e,_mapKey:"layers"});H.propTypes={children:r.node};const G=e=>p.createElement(g,{...e,_mapKey:"tooltip"}),J=e=>p.createElement(g,{type:"shape",...e});J.displayName="MapShapeLayer",J.propTypes={children:function(e,t,n){return P(e,t,n,G)}};const Q=e=>p.createElement(g,{type:"tile",...e});Q.displayName="MapTileLayer";const X=e=>p.createElement(g,{...e,_mapKey:"tooltip"}),Y=e=>p.createElement(g,{type:"bubble",...e});Y.displayName="MapBubbleLayer",Y.propTypes={children:function(e,t,n){return P(e,t,n,X)}};const ee=e=>p.createElement(g,{...e,_mapKey:"tooltip"}),te=e=>p.createElement(g,{type:"marker",...e});te.displayName="MapMarkerLayer",te.propTypes={children:function(e,t,n){return P(e,t,n,ee)}},Object.defineProperty(e,"Extent",{enumerable:!0,get:function(){return o.Extent}}),Object.defineProperty(e,"Location",{enumerable:!0,get:function(){return o.Location}}),e.BeforeResetEvent=I,e.CollectionConfigurationComponent=h,e.ConfigurationComponent=g,e.Map=$,e.MapBubbleLayer=Y,e.MapBubbleLayerTooltip=X,e.MapClickEvent=b,e.MapLayers=H,e.MapMarkerLayer=te,e.MapMarkerLayerTooltip=ee,e.MapShapeLayer=J,e.MapShapeLayerTooltip=G,e.MapTileLayer=Q,e.MapTooltip=q,e.MarkerActivateEvent=E,e.MarkerClickEvent=S,e.MarkerCreatedEvent=k,e.PanEndEvent=x,e.PanEvent=C,e.ResetEvent=T,e.ShapeClickEvent=O,e.ShapeCreatedEvent=w,e.ShapeFeatureCreatedEvent=L,e.ShapeMouseEnterEvent=A,e.ShapeMouseLeaveEvent=K,e.ZoomEndEvent=D,e.ZoomStartEvent=N}));