UNPKG

@jdthfe/gmap

Version:

JDC gmap bundle

1 lines 11.3 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(self,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>p});const n='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="49px" height="75px" viewBox="0 0 49 75" version="1.1">\n<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <g transform="translate(-349.000000, -584.000000)">\n <g transform="translate(342.500000, 584.000000)">\n <g transform="translate(7.000000, 0.000000)">\n <ellipse fill="#9D0D00" cx="24" cy="72" rx="4" ry="3"/>\n <circle fill="#FA2C19" cx="24" cy="24" r="24"/>\n <path d="M21.5,33 L26.5,33 L26.5,70.5 C26.5,71.8807119 25.3807119,73 24,73 C22.6192881,73 21.5,71.8807119 21.5,70.5 L21.5,33 L21.5,33 Z" fill="#FA2C19"/>\n <circle fill="#FFFFFF" cx="24" cy="24" r="10"/>\n </g>\n </g>\n </g>\n</g>\n</svg>',i={line:{symbol:{path:"M 0,-1 0,1",strokeOpacity:1,strokeWeight:1,strokeColor:"#E1251B",scale:5},router:`data:image/svg+xml;charset=UTF-8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="19">\n<g>\n <title>background</title>\n <rect fill="#3882e5" height="21" width="18" y="-1" x="-1"/>\n <g display="none" overflow="visible" y="0" x="0" height="100%" width="100%">\n <rect fill="url(#gridpattern)" stroke-width="0" y="0" x="0" height="100%" width="100%"/>\n </g>\n</g>\n<g>\n <rect height="8" width="1.669517" y="0.714751" x="7" stroke-width="1.5" stroke="#ffffff" fill="#ffffff"/>\n</g>\n</svg>')}`,pinSVGString:`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(n)}`},marker:{icons:{round:{size:{w:17,h:17},scaledSize:{w:17,h:68},anchor:{x:8.5,y:8.5},origin:{x:0,y:0},url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAABoCAMAAADYfhA2AAAApVBMVEUAAADgOALgOALgOALgOAIAAADgOAIAAADgOALgOALgOALgOALgOALgOALgOALgOALq6uq0tLQAAAAAAAAAAAAAAAAAAADl5eXPz8/gOALgOALgOALZ2dm9vb25ubm2trZwcHBiYmLgOALgOALl5eXZ2dnY2NjQ0ND/2NTgOALr6+uxsbHvf3D7yML2raT0npTue2vvhHbmUTXlTC7temnhOwvNzc3GefWAAAAAKHRSTlMAxr/65zE/PwqYdi8nEgiB+5Y6Jh8QC+y+m5lAzqGdmWNdggntz82/i3i4gwAAAaRJREFUSMftlNmSgjAQAAMY4y2iAt7Hupogh/f/f9qCAgGcTG1t7aP92pXUJOkKyei09Jph1PRWh5Sp61c/DDgPQv+q1wui1xQRz4lEs5eZrnbjJW5a92Uams8r+FrjqSYn/sZp8pxAcACRzKJFkIo0QtoXDnJpk/4ZVuc+0UNYhTqpBbAKasTgCgxEIRsiY6iH3yJHRi5Keb0zEjOFHmWKPSUcwCkOIOWrmk2jGJsmY9NmBYElitcrcqr1FinVKyrIesUbWb0CIK0X4lUvrJJ6hYK4XpWK61WpuF6ViutVKQNRyIbIGOrht8iRkYtSXW9aL2SmyFMiAch6i1TrleIX9X7+3n/7e/27yLn7pb83MdLJv/dt1efv/dvfa4+oxZhFR3ZFjOlmtXdM09mvNnRcNEPmejkuG8qu6cArMaBZ2XTpVVjSdDe5Rq4bPidgHgBLZqEupFxKiL32QNY2GS1gtRgROofVNyWWAyvHIsz0Yh7HAg8vxmSpOpZIleXAqxwLGQMZHjmy6qIOFLle/FHgp0QCgLM5sGE1tvnONHdzGRuS6A98eT9Oyla16QAAAABJRU5ErkJggg=="},pin:{size:{w:50,h:76},scaledSize:{w:25,h:38},anchor:{x:12.5,y:38},url:`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(n)}`},arrow:{scaledSize:{w:32,h:32},anchor:{x:16,y:16},url:t=>`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(function(t=0){return`<?xml version="1.0" encoding="UTF-8"?>\n <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" transform="rotate(${t})" width="65px" height="64px" viewBox="0 0 65 64" version="1.1">\n <title>Group 4</title>\n <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <g transform="translate(-341.000000, -624.000000)">\n <g transform="translate(341.500000, 584.000000)">\n <g transform="translate(0.000000, 40.000000)">\n <rect fill="#D8D8D8" opacity="0" x="0" y="0" width="64" height="64"/>\n <circle fill="#0079D7" opacity="0.100000001" cx="32" cy="32" r="22"/>\n <path d="M21.5,46 L1.873,32.158 L1.5,32.1047893 L1.648,32 L1.5,31.8952107 L1.873,31.841 L21.5,18 L21.5,46 Z" fill="#0079D7"/>\n <circle fill="#FFFFFF" cx="32" cy="32" r="18"/>\n <circle fill="#0079D7" cx="32" cy="32" r="14"/>\n </g>\n </g>\n </g>\n </g>\n</svg>`}(t))}`}}}},o={lightRedNoMinus:{origin:{x:0,y:0}},darkRedNoMinus:{origin:{x:0,y:17}},disabledWithMinus:{origin:{x:0,y:34}},lightRedWithMinus:{origin:{x:0,y:51}}};function r(t,e){if("function"==typeof t.url){return Object.assign({},t,{url:t.url(e)})}return t}const s={red:"#E1251B",blue:"#3C7EEA"},a=function(t){const{red:e,blue:n}=s;return Object.assign(t,{addJDCMarker:(e,n="pin",o)=>t.addMarker(Object.assign(e,{icon:{...r(i.marker.icons[n],o),labelOrigin:{x:0,y:0}}})),addJDCRoundMarker(e,n="lightRedNoMinus"){const r=i.marker.icons.round;return r.origin=o[n].origin,t.addMarker(Object.assign(e,{icon:{labelOrigin:{x:0,y:0},...r}}))},drawJDCPolygon:(n,i)=>t.drawPolygon(n,Object.assign({},{strokeColor:e},i||{})),drawJDCLine:(n,o)=>t.drawLine(n,Object.assign({},{strokeOpacity:0,strokeColor:e,icons:[{icon:i.line.symbol,offset:"0",repeat:"18px"}]})),drawJDCRouter:(e,i)=>t.drawLine(e,Object.assign({},{strokeWeight:8,strokeOpacity:1,strokeColor:n},i||{}))})},l={que:{},listen(t,e){this.que[t]=e},trigger(t,e){this.que[t](e)}};function g(t,e){return new google.maps.Map(t,e)}const c=function(t,{content:e,extraClass:n}){class i extends google.maps.OverlayView{constructor(t,{content:e,extraClass:n}){super(),this.position=t;const o=document.createElement("div");o.innerHTML=e,o.classList.add("popup-bubble",n||"");const r=document.createElement("div");r.setAttribute("style","position: relative, overflow: visible"),r.classList.add("popup-bubble-anchor"),r.appendChild(o),this.containerDiv=document.createElement("div"),this.containerDiv.classList.add("popup-container"),this.containerDiv.appendChild(r),i.preventMapHitsAndGesturesFrom(this.containerDiv)}onAdd(){const t=this.getPanes();t&&t.floatPane.appendChild(this.containerDiv)}onRemove(){this.containerDiv.parentElement&&this.containerDiv.parentElement.removeChild(this.containerDiv)}draw(){const t=this.getProjection().fromLatLngToDivPixel(this.position);if(t){const e=Math.abs(t.x)<4e3&&Math.abs(t.y)<4e3?"block":"none";"block"===e&&(this.containerDiv.style.left=t.x+"px",this.containerDiv.style.top=t.y+"px"),this.containerDiv.style.display!==e&&(this.containerDiv.style.display=e)}}}return new i(t,{content:e,extraClass:n})};async function h(t,{callback:e,key:n,libraries:i,language:o},r){const s=await function(t,{callback:e,key:n,libraries:i,language:o},r){return new Promise(((s,a)=>{try{if("undefined"!=typeof google&&google.maps&&google.maps.Map)s(g(t,r));else{const a=window[e];window[e]=()=>{const e=g(t,r);l.trigger("event-gmap-inited",e)};const c=document.createElement("script");let h=`key=${n}&callback=${e}`;i&&(h+=`&libraries=${i}`),o&&(h+=`&language=${o}`),c.src=`https://maps.googleapis.com/maps/api/js?${h}`;const p=document.getElementsByTagName("head");p&&p.length>0&&p[0].appendChild(c),l.listen("event-gmap-inited",(t=>{s(t),window[e]=a}))}}catch(t){a(t)}}))}(t,{callback:e,key:n,libraries:i,language:o},r),h=function(t){return{map:t,markers:[],lines:[],polygons:[],customInfoWindows:[],getMap(){return this.map},createLatLng:t=>new google.maps.LatLng(+t.lat,+t.lng),addMarker(t){const e=this.createLatLng(t),n=Object.assign(t,{position:e,map:this.map});t.icon&&Object.assign(n,{icon:this.getIcon(t.icon)});const i=new google.maps.Marker(n);return this.markers.push(i),i},addEvent(t,e,n){return google.maps.event.addListener(t,e,(function(e){n&&n.call(t,e)})),this},removeEvent(t,e){return google.maps.event.clearListeners(t,e),this},getIcon(t){if("string"==typeof t)return t;const e={url:t.url};return["anchor","labelOrigin","origin"].forEach((n=>{if(t[n]){const{x:i,y:o}=t[n];Object.assign(e,{[n]:new google.maps.Point(i,o)})}})),["size","scaledSize"].forEach((n=>{if(t[n]){const{w:i,h:o}=t[n];Object.assign(e,{[n]:new google.maps.Size(i,o)})}})),Object.assign(t,e)},searchMarkerByPosition(t){if(this.markers.length>0){let e;const n=[],i=this.createLatLng(t);for(let t=0;t<this.markers.length;t++){const o=this.markers[t];e=o.getPosition(),e&&i.toString()==e.toString()&&n.push(o)}return 0===n.length?null:n}return null},changeMarkerIcon(t,e){return t.setIcon(this.getIcon(e)),this},createInfoWindow:t=>new google.maps.InfoWindow(t),showInfoWindow(t,e){return t.open(this.map,e),this},closeInfoWindow(t){return t.close(),this},delMarker(t){t.setMap(null)},drawLine(t,e){const n=t.map((t=>new google.maps.LatLng(+t.lat,+t.lng))),i=Object.assign({},e||{},{path:n}),o=new google.maps.Polyline(i);return o.setMap(this.map),this.lines.push(o),o},clearLine(){this.lines.forEach((t=>{t.setMap(null)})),this.lines=[]},drawPolygon(t,e){const n=t.map((t=>this.createLatLng({lat:t.lat,lng:t.lng}))),i=new google.maps.Polygon(Object.assign({strokeWeight:2},e||{},{paths:n}));return i.setMap(this.map),this.polygons.push(i),i},clearAllPolygon(){this.polygons.forEach((t=>{t.setMap(null)})),this.polygons=[]},clearPolygon(t){t&&t.setMap(null),this.polygons=this.polygons.filter((e=>e!==t))},fitBounds(t){const e=new google.maps.LatLngBounds;t.forEach((t=>{e.extend(this.createLatLng(t))})),this.map.fitBounds(e)},setCenter(t){let e=0,n=0;const i=t.length;t.forEach((t=>{e+=+t.lat,n+=+t.lng})),this.map.setCenter(new google.maps.LatLng(e/i,n/i))},setZoom(t){"number"==typeof t&&this.map.setZoom(t)},clearMarker(){for(let t,e=0;t=this.markers[e++];)this.delMarker(t);this.markers=[]},empty(){this.clearLine(),this.clearMarker(),this.clearInfoWindow(),this.clearAllPolygon()},customInfoWindow(t,{content:e,extraClass:n}){const i=c(this.createLatLng(t),{content:e,extraClass:n});i.setMap(this.map),this.customInfoWindows.push(i)},clearInfoWindow(){this.customInfoWindows.forEach((t=>{t.setMap(null)})),this.customInfoWindows=[]},getDistance(t,e){const n=Math.PI/180*Number(t.lat),i=Math.PI/180*Number(e.lat),o=Math.PI/180*Number(t.lng),r=Math.PI/180*Number(e.lng);return 6371*Math.acos(Math.sin(n)*Math.sin(i)+Math.cos(n)*Math.cos(i)*Math.cos(r-o))*1e3},getPointFromDistance({lat:t,lng:e},n,i){const[o,r]=[180,6371],s=n*(Math.PI/o),a=Number(t)*(Math.PI/o),l=Number(e)*(Math.PI/o),g=Math.cos(i/r),c=Math.sin(i/r),h=Math.sin(a),p=Math.cos(a);let d=Math.asin(h*g+p*c*Math.cos(s)),m=l+Math.atan2(Math.sin(s)*c*p,g-h*Math.sin(d));return d*=o/Math.PI,m*=o/Math.PI,{lat:d,lng:m}},getRightTopPointFromDistance(t,e){return this.getPointFromDistance(e,135,t)},getRightBottomPointFromDistance(t,e){return this.getPointFromDistance(e,225,t)},getLeftTopPointFromDistance(t,e){return this.getPointFromDistance(e,45,t)},getLeftBottomPointFromDistance(t,e){return this.getPointFromDistance(e,315,t)},createPolygonByCenter(t,e,n,i){return Array.from({length:e}).map(((o,r)=>{let s=360/e;return s=s+s*r+i,this.getPointFromDistance(t,s,n)}))}}}(s);return{map:s,util:a(h)}}if(window.renderMap)throw new Error("window.renderMap被占用,加载地图失败");window.renderMap=h;const p=h;return e})()}));