1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
|
|
!function(){var e={27538:function(e){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.default=e.exports,e.exports.__esModule=!0},79267:function(e,t,n){"use strict";var o=n(27538),r=n.n(o),i=n(69307),a=n(65736),s=n(92819),l=n(55609),c=n(81041),p=n(77714),d=n(73242),u=n(87929),m=n(45388);const __=a.__;class h extends i.Component{constructor(){super(...arguments),r()(this,"onMarkerClick",(e=>{const{onMarkerClick:t}=this.props;this.setState({activeMarker:e}),t()})),r()(this,"onMapClick",(()=>{this.setState({activeMarker:null})})),r()(this,"clearCurrentMarker",(()=>{this.setState({activeMarker:null})})),r()(this,"updateActiveMarker",(e=>{const{points:t}=this.props,{activeMarker:n}=this.state,{index:o}=n.props,r=t.slice(0);(0,s.assign)(r[o],e),this.props.onSetPoints(r)})),r()(this,"deleteActiveMarker",(()=>{const{points:e}=this.props,{activeMarker:t}=this.state,{index:n}=t.props,o=e.slice(0);o.splice(n,1),this.props.onSetPoints(o),this.setState({activeMarker:null})})),r()(this,"sizeMap",(()=>{const{mapHeight:e}=this.props,{map:t}=this.state,n=this.mapRef.current;if(e)n.style.height=e+"px";else{const e=n.offsetWidth,t=window.location.search.indexOf("map-block-counter")>-1?window.innerHeight:.8*window.innerHeight,o=Math.min(e*(3/4),t);n.style.height=o+"px"}t.resize(),this.setBoundsByMarkers()})),r()(this,"updateZoom",(()=>{const{zoom:e}=this.props,{map:t}=this.state;t.setZoom(e),t.updateZoom(e)})),r()(this,"setBoundsByMarkers",(()=>{const{admin:e,onSetMapCenter:t,onSetZoom:n,points:o,zoom:r}=this.props,{map:i,activeMarker:a,mapboxgl:s,zoomControl:l,boundsSetProgrammatically:c}=this.state;if(!i)return;if(o.length&&e?i.dragPan.disable():i.dragPan.enable(),!o.length)return;if(a)return;const p=new s.LngLatBounds;if(o.forEach((e=>{p.extend([e.coordinates.longitude,e.coordinates.latitude])})),t(p.getCenter()),o.length>1){i.fitBounds(p,{padding:{top:80,bottom:80,left:40,right:40}}),this.setState({boundsSetProgrammatically:!0});try{i.removeControl(l)}catch(e){}}else{if(i.setCenter(p.getCenter()),c){const e=12;i.setZoom(e),n(e)}else i.setZoom(parseInt(r,10));i.addControl(l),this.setState({boundsSetProgrammatically:!1})}})),r()(this,"scriptsLoaded",(()=>{const{mapCenter:e,points:t}=this.props;this.setState({loaded:!0}),t.length,this.initMap(e)})),r()(this,"googlePoint2Mapbox",(e=>e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")?e:{lat:e.latitude||0,lng:e.longitude||0})),this.state={map:null,fit_to_bounds:!1,loaded:!1,mapboxgl:null},this.mapRef=(0,i.createRef)(),this.debouncedSizeMap=(0,s.debounce)(this.sizeMap,250)}render(){const{points:e,admin:t,children:n,markerColor:o}=this.props,{map:r,activeMarker:a,mapboxgl:d}=this.state,{onMarkerClick:u,deleteActiveMarker:m,updateActiveMarker:h}=this,f=(0,s.get)(a,"props.point")||{},{title:g,caption:k}=f,b=i.Children.map(n,(e=>{if("AddPoint"===(0,s.get)(e,"props.tagName"))return e})),w=r&&d&&e.map(((e,t)=>(0,i.createElement)(c.Z,{mapRef:this.mapRef,key:t,point:e,index:t,map:r,mapboxgl:d,markerColor:o,onClick:u}))),v=d&&(0,i.createElement)(p.Z,{activeMarker:a,map:r,mapboxgl:d,unsetActiveMarker:()=>this.setState({activeMarker:null})},a&&t&&(0,i.createElement)(i.Fragment,null,(0,i.createElement)(l.TextControl,{label:__("Marker Title","jetpack"),value:g,onChange:e=>h({title:e})}),(0,i.createElement)(l.TextareaControl,{className:"wp-block-jetpack-map__marker-caption",label:__("Marker Caption","jetpack"),value:k,rows:"2",tag:"textarea",onChange:e=>h({caption:e})}),(0,i.createElement)(l.Button,{onClick:m,className:"wp-block-jetpack-map__delete-btn"},(0,i.createElement)(l.Dashicon,{icon:"trash",size:"15"})," ",__("Delete Marker","jetpack"))),a&&!t&&(0,i.createElement)(i.Fragment,null,(0,i.createElement)("h3",null,g),(0,i.createElement)("p",null,k)));return(0,i.createElement)(i.Fragment,null,(0,i.createElement)("div",{className:"wp-block-jetpack-map__gm-container",ref:this.mapRef},w),v,b)}componentDidMount(){const{apiKey:e}=this.props;e&&this.loadMapLibraries()}componentWillUnmount(){this.debouncedSizeMap.cancel(),win
|