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