@map.ir/services-sdk
Version:
JavaScript/TypeScript SDK for map.ir services
4 lines (3 loc) • 2.47 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).servicesSdk=t()}(this,function(){var e=function(e){return Object.fromEntries(Object.entries(e).map(function(e){return[e[0],String(e[1])]}))},t=function(t){return new URLSearchParams(e(function(e,t){return void 0===t&&(t=!0),Object.fromEntries(Object.entries(e).filter(function(e){var n=e[1];return t?Boolean(n):null!=n}))}(t))).toString()};function n(n,i,r){void 0===i&&(i="car"),void 0===r&&(r={});var o={car:"route",walking:"walking",bicycle:"bicycle"}[i];try{var a=n.map(function(e){return[e.lng,e.lat].join()}).join(";"),s=Object.assign({alternatives:!0,steps:!0,overview:!1},r),c=t(e(s)),u=new URL("/routes/"+o+"/v1/driving/"+a+"?"+c,this.baseURL);return fetch(u,{method:"GET",headers:{"x-api-key":this.apiKey,"content-type":"application/json"}}).then(function(e){return e.json()}).then(function(e){return e})}catch(e){return void console.error("🚀 ~ file: route.ts:34 ~ err:",e)}}/*#__PURE__*/
return function(){function e(e){this.apiKey="",this.baseURL="https://map.ir",this.route=n;var t=null!=e?e:{},i=t.apiKey,r=t.baseURL;i&&(this.apiKey=i),r&&(this.baseURL=r)}var i=e.prototype;return i.search=function(e,t,n){var i=new URL("/search"+(n?"/autocomplete":""),this.baseURL);return fetch(i,{method:"POST",headers:{"x-api-key":this.apiKey,"content-type":"application/json"},body:JSON.stringify({text:e,returnid:!0,location:{type:"Point",coordinates:[t.lng,t.lat]}})}).then(function(e){return e.json()}).then(function(e){return e})},i.reverseGeocode=function(e){var n=t({lat:e.lat.toString(),lon:e.lng.toString()}),i=new URL("/reverse?"+n,this.baseURL);return fetch(i,{method:"GET",headers:{"x-api-key":this.apiKey,"content-type":"application/json"}}).then(function(e){return e.json()}).then(function(e){return e})},i.staticMap=function(e,n){var i=null!=n?n:{},r=i.width,o=void 0===r?700:r,a=i.height,s=void 0===a?500:a,c=i.zoom,u=void 0===c?13:c,l=i.colors,h=void 0===l?["red","red"]:l,f=i.labels,d=e.map(function(e,t){return["color:"+h[t],[e.lng,e.lat].join(),null==f?void 0:f[t]].filter(Boolean).join("|")}).join(),p=t({markers:d,width:String(o),height:String(s),zoom_level:String(u)}),v=new URL("/static?"+p,this.baseURL);return fetch(v,{method:"GET",headers:{"x-api-key":this.apiKey}}).then(function(e){return e.blob()}).then(function(e){return e})},e}()});
//# sourceMappingURL=mapir_services_sdk.umd.js.map