@mapcreator/sdk 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MCMap.d.ts +15 -0
- package/dist/index.d.ts +2 -16
- package/dist/mapcreator-sdk.js +2 -2
- package/dist/mapcreator-sdk.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/MCMap.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Map as MapLibre } from '@mapcreator/maplibre-gl';
|
|
2
|
+
import { Env, JobObjectAugmented, Mode } from './types';
|
|
3
|
+
declare class MCMapClass {
|
|
4
|
+
map: MapLibre;
|
|
5
|
+
constructor(map: MapLibre);
|
|
6
|
+
}
|
|
7
|
+
export type MCMap = InstanceType<typeof MCMapClass>;
|
|
8
|
+
export declare function init(options: {
|
|
9
|
+
container: HTMLElement | string;
|
|
10
|
+
job: JobObjectAugmented | string;
|
|
11
|
+
accessToken: string;
|
|
12
|
+
mode?: Mode | undefined;
|
|
13
|
+
env?: Env | undefined;
|
|
14
|
+
}): Promise<MCMap>;
|
|
15
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type Options = {
|
|
4
|
-
container: HTMLElement | string;
|
|
5
|
-
job: JobObjectAugmented | string;
|
|
6
|
-
accessToken: string;
|
|
7
|
-
mode?: Mode | undefined;
|
|
8
|
-
env?: Env | undefined;
|
|
9
|
-
};
|
|
10
|
-
export type MCMap = InstanceType<typeof MCMapClass>;
|
|
11
|
-
declare class MCMapClass {
|
|
12
|
-
map: MapLibre;
|
|
13
|
-
constructor(map: MapLibre);
|
|
14
|
-
}
|
|
15
|
-
export declare function init(options: Options): Promise<MCMap>;
|
|
16
|
-
export {};
|
|
1
|
+
import { init, MCMap } from './MCMap';
|
|
2
|
+
export { init, type MCMap };
|
package/dist/mapcreator-sdk.js
CHANGED
|
@@ -39456,7 +39456,7 @@ function Nl(e, t) {
|
|
|
39456
39456
|
};
|
|
39457
39457
|
}
|
|
39458
39458
|
//#endregion
|
|
39459
|
-
//#region src/
|
|
39459
|
+
//#region src/MCMap.ts
|
|
39460
39460
|
var Pl = class {
|
|
39461
39461
|
map;
|
|
39462
39462
|
constructor(e) {
|
|
@@ -39492,7 +39492,7 @@ async function Fl(e) {
|
|
|
39492
39492
|
let e = Math.min(f.clientWidth / te, f.clientHeight / F);
|
|
39493
39493
|
ne = Math.log(e) / Math.LN2;
|
|
39494
39494
|
}
|
|
39495
|
-
if (d.setZoom(g - C + ne), d.setCenter(b), d.setDetailLevel(C), d.setMinZoom(C), d.addControl(new o.AttributionControl({ compact: !1 })), i
|
|
39495
|
+
if (d.setZoom(g - C + ne), d.setCenter(b), d.setDetailLevel(C), d.setMinZoom(C), d.addControl(new o.AttributionControl({ compact: !1 })), i === "app" && d.cooperativeGestures.enable(), qc(u, A, d, {
|
|
39496
39496
|
center: b,
|
|
39497
39497
|
zoom: g,
|
|
39498
39498
|
pitch: v,
|
|
@@ -1137,4 +1137,4 @@ vec4 finalPos=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matr
|
|
|
1137
1137
|
<div class="popup-scroll-wrapper">
|
|
1138
1138
|
<div class="mc-popup data-layer text-content">${n}</div>
|
|
1139
1139
|
</div>
|
|
1140
|
-
`}return n}htmlToElement(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content.firstElementChild}addPopupControls(){let e=this.htmlToElement(yl);if(e&&(e.addEventListener(`click`,()=>{this.hidePopup(),this.highlightManager.highlight(void 0)}),this.popupContainer.appendChild(e)),this.popupElements.length<2)return;let t=this.htmlToElement(bl);t&&(t.querySelector(`.prev`)?.addEventListener(`click`,()=>this.cyclePopups(!1)),t.querySelector(`.next`)?.addEventListener(`click`,()=>this.cyclePopups()),this.popupContainer.appendChild(t))}fillDatalayerTemplate(e,t,n){let r=`data-mention-id`,i=new DOMParser().parseFromString(t,`text/html`).body;for(let t of i.querySelectorAll(`[${r}]`)){let i=this.getProperty(e,t.getAttribute(r),n);i!==void 0&&(t.innerText=i)}return i.innerHTML}getProperty(e,t,n){if(!t)return;let r=t.endsWith(`:en`)?[t.replace(`:en`,n),t]:[t];for(let t of r){let n=e.properties[t]??this.getVectorProperty(e,t);if(n!==void 0)return n}}getVectorProperty(e,t){let n=this.promoteIdCache.get(e.source);n===void 0&&(n=this.map.getSource(e.source)?.serialize().promoteId||`id`,this.promoteIdCache.set(e.source,n));try{let r=e.properties[n];return e.layer.metadata.properties[t][r]}catch{return}}cyclePopups(e=!0){let t=this.popupElements?.findIndex(e=>e.modelId===this.currentModelId);if(t!==-1){let n=0;n=e?t===this.popupElements.length-1?0:t+1:t===0?this.popupElements.length-1:t-1;let r=this.popupElements?.[n];this.highlightManager.highlight(r);let i=vl(r.popup,r.popupMedia,r.dataBindings??{},this.mode),a=this.popupContainer;this.popupContainer.remove(),a.innerHTML=i,this.mapContainer.appendChild(a),this.currentModelId=r.modelId,this.addPopupControls(),e?this.popupContainer.querySelector(`.mc-popup-button.next`)?.focus():this.popupContainer.querySelector(`.mc-popup-button.prev`)?.focus(),this.currentFeatureId=void 0}}},Ol={solid:[1,0],dotted:[.7,.3],dashed:[3.5,1.5]};function kl(e,t,n,r){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(n=>Al(e,t,n,r))}}),Object.entries(Ol).forEach(([r,i])=>{t.models.some(e=>(e.lineStyle??`solid`)===r)&&e.addLayer({id:`${t.id}-${r}`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},filter:[`all`,[`==`,[`geometry-type`],`LineString`],[`==`,[`get`,`line-style`],r]],paint:{"line-width":[`get`,`line-width`],"line-color":[`get`,`line-color`],"line-dasharray":i}},n)}),e.addLayer({id:`${t.id}-clickable`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},paint:{"line-width":[`max`,[`get`,`line-width`],15],"line-opacity":0},filter:[`==`,[`geometry-type`],`LineString`]},n),t.models.some(e=>e.svg)&&e.addLayer({id:`${t.id}-icon`,type:`symbol`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},layout:{"icon-allow-overlap":!0,"icon-ignore-placement":!0,"icon-image":[`get`,`mc-image-key`],"icon-anchor":`center`,"icon-size":[`get`,`icon-size`],"icon-rotate":[`get`,`icon-rotate`],"icon-offset":[`get`,`icon-offset`]},filter:[`==`,[`geometry-type`],`Point`]},n)}function Al(e,t,n,r){let i=n.svg===void 0?void 0:r.getMapLibreImageKey(Pr(n.dataBindings??{},n.svg,void 0),window.devicePixelRatio*(n.iconScale??1));return{type:`Feature`,id:f(n.id),properties:{id:n.id,"line-width":n.lineWidth??3,"line-color":t.lineColor||n.lineColor?Mr(n.dataBindings??{},n.lineColor,t.lineColor):`#000000`,"line-style":n.lineStyle??`solid`,"mc-image-key":i,"icon-rotate":jl(n,e),"icon-offset":n.iconOffset,"icon-size":n.iconScale},geometry:{type:`GeometryCollection`,geometries:[{type:`LineString`,coordinates:n.geometry},{type:`Point`,coordinates:n.geometry[n.geometry.length-1]}]}}}function jl(e,t){return e.iconRotation?e.iconAlign?$n(e.geometry,t)+e.iconRotation:e.iconRotation:0}function Ml(e,t,n,r,i,a,o){let s=or(t),c=new Map,l=new Map;for(let e of t.models){let n=e.featureId,a=t.id,o=[],u=Zn(e),d=Xn(a,e),f=l.get(d)??{model:e,featureIds:o,modelIdToFillColor:{},modelIdToFillPattern:{},modelIdToOutlineColor:{},modelIdToOutlineWidth:{}};if(e.visible??!0){f.featureIds.push(n);let a=e.fillPattern===void 0?null:i.getMapLibreImageKey(r[e.fillPattern],2*window.devicePixelRatio);f.modelIdToFillColor[n]=t.fillColor||e.fillColor?Mr(e.dataBindings??{},e.fillColor,t.fillColor,s,t.choropleth?.unmatchedColor):`#000000`,f.modelIdToFillPattern[n]=a,f.modelIdToOutlineColor[n]=t.outlineColor||e.outlineColor?Mr(e.dataBindings??{},e.outlineColor,t.outlineColor):`#000000`,f.modelIdToOutlineWidth[n]=e.outlineWidth??.5}c.set(u,e),l.set(d,f)}for(let t of c.keys())e.getSource(t)||e.addSource(t,{type:`vector`,url:`${a}${c.get(t).vectorUrl}?access_token=${o}`});for(let r of l.keys()){let{model:i}=l.get(r),{sourceLayerId:a}=i,o=Zn(i);e.addLayer({id:r,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-color":`#ffffff`,"fill-outline-color":`#000000`,"fill-antialias":!1}},n),e.addLayer({id:`${r}-pattern`,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-pattern":[`get`,`fill-pattern`]},layout:{visibility:`visible`}},n),e.addLayer({id:`${r}-outline`,type:`line`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"line-color":`#000000`,"line-width":.5}},n)}l.forEach((t,n)=>{let{featureIds:r,modelIdToFillColor:i,modelIdToFillPattern:a,modelIdToOutlineColor:o,modelIdToOutlineWidth:s}=t;e.setFilter(n,[`in`,`id`,...r]),e.setFilter(`${n}-outline`,[`in`,`id`,...r]),e.setPaintProperty(n,`fill-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,i]]),e.setPaintProperty(`${n}-outline`,`line-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,o]]),e.setPaintProperty(`${n}-outline`,`line-width`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,s]]),e.setFilter(`${n}-pattern`,[`to-boolean`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]]]),e.setPaintProperty(`${n}-pattern`,`fill-pattern`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]])})}function Nl(e,t,n){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(e=>Pl(t,e))}}),e.addLayer({id:t.id,type:`circle`,source:t.id,metadata:{"mc-model-type":`dot`,"mc-group-id":t.id},paint:{"circle-color":[`get`,`circle-color`],"circle-radius":[`get`,`circle-radius`]}},n)}function Pl(e,t){return{type:`Feature`,id:t.id,properties:{id:t.id,"circle-radius":t.radius,"circle-color":e.fillColor||t.fillColor?Mr(t.dataBindings??{},t.fillColor,e.fillColor):`#000000`},geometry:{type:`Point`,coordinates:[t.center.lng,t.center.lat]}}}var Fl=class{map;constructor(e){this.map=e}};async function Il(e){let{accessToken:t,mode:r=`sdk`,env:a=`production`}=e,c=a===`bleeding`?`https://vapi.bleeding.mc-cdn.io`:a===`beta`?`https://vapi.beta.mc-cdn.io`:`https://vapi.mc-cdn.io`,l=a===`bleeding`?`https://cdn.bleeding.mapcreator.io`:a===`beta`?`https://cdn.beta.mapcreator.io`:`https://cdn.mapcreator.io`,u=typeof e.job==`string`?await Ll(e.job,l,t):e.job;await Rl();let d=new s.Map({container:e.container,attributionControl:!1,style:null,maxBounds:[-1/0,-90,1/0,90],maxPitch:85,maxZoom:22,locale:{"CooperativeGesturesHandler.WindowsHelpText":Oi(`windowsHelpText`),"CooperativeGesturesHandler.MacHelpText":Oi(`macHelpText`),"CooperativeGesturesHandler.MobileHelpText":Oi(`mobileHelpText`)}}),f=d.getContainer();f.classList.add(`mc-map`);let p=new Dr(d),m=new Dl(d,r),{map:{language:h,zoom:g,pitch:_=0,rotation:y=0,center:b,hideBasemap:x,layerInfo:S=[],detailLevel:C=0,projection:w=`mercator`,terrain:T=!1,terrainExaggeration:E=1},export:D,registry:O={},web:k,positionOffsets:A,title:j}=u,{models:M={},slots:N={},svgs:P={}}=O;Vl(a,c,t),d.resize(),r===`app`&&(document.title=j?`${j} - Mapcreator`:`Mapcreator`),d.setPitch(_),d.setBearing(y);let ee=D?.unit??`pixel`,te=v(ee,`pixel`,D?.size?.[0]??600),F=v(ee,`pixel`,D?.size?.[1]??400),ne=0;if(f.clientWidth>0&&f.clientHeight>0){let e=Math.min(f.clientWidth/te,f.clientHeight/F);ne=Math.log(e)/Math.LN2}if(d.setZoom(g-C+ne),d.setCenter(b),d.setDetailLevel(C),d.setMinZoom(C),d.addControl(new s.AttributionControl({compact:!1})),r!==`preview`&&d.cooperativeGestures.enable(),Jc(u,A,d,{center:b,zoom:g,pitch:_,rotation:y,detailLevel:C,width:te,height:F},c,l,t),m.setJobObject(u),k){let{restrictMapMovement:e,popupPosition:t}=k;e&&(d.boxZoom.disable(),d.doubleClickZoom.disable(),d.dragPan.disable(),d.dragRotate.disable(),d.keyboard.disable(),d.scrollZoom.disable(),d.touchPitch.disable(),d.touchZoomRotate.disable()),m.setParams(t,o(h,i.TWO),e,b)}let re=await fetch(`${c}/styles/${u.meta.mapstyleSet}.json?access_token=${t}`).then(e=>e.json());return d.setStyle(null),d.setStyle(re),await d.once(`style.load`),r===`app`&&Hl(d.getStyle().metadata?.customCssFilePath,t),n(h,d),await sl(u.meta.layers??[],d,c,t,re.metadata?.styleOverride),Wl(d,p,M,N,P,c,t),n(h,d),m.setPublication(re.metadata?.publication),m.setpopupElements(),m.setHighlightManager(),d.setProjection({type:w===`globe`?`globe`:`mercator`}),zl(d,w),T&&Bl(d,c,t,E),Ul(d,d.getStyle(),S,!x),new Fl(d)}function Ll(e,t,n){return fetch(`${t}/jobs/${e}.json?access_token=${n}`).then(e=>e.json())}function Rl(){return new Promise(e=>{let t=()=>{window.innerWidth>0&&window.innerHeight>0&&(window.removeEventListener(`resize`,t),e())};window.addEventListener(`resize`,t),t()})}function zl(e,t){let n=e.getStyle().metadata??{},r=n[`mc:background-color`]??`#f8f8f8`,i=n[`mc:background-color-globe`]??`#000000`;e.getContainer().style.backgroundColor=t===`globe`?i:r,e.setSky(e.getStyle().sky??Wc),e.setLight({position:[1.15,210,45]})}function Bl(e,t,n,r){e.addSource(`mc-dem`,{type:`raster-dem`,tiles:[`${t}/dataset/jaxa_terrainrgb/{z}/{x}/{y}?access_token=${n}`],attribution:`<a href="https://earth.jaxa.jp/en/data/policy" target="_blank">© AW3D30 (JAXA)</a>`,minzoom:0,maxzoom:12}),e.setTerrain({source:`mc-dem`,exaggeration:r})}function Vl(e,t,n){let r=`${t}/stylesheets/ff-${e===`beta`?`b-`:``}${n}.css?access_token=${n}`,i=document.createElement(`link`);i.setAttribute(`rel`,`stylesheet`),i.setAttribute(`href`,r),i.setAttribute(`type`,`text/css`),document.head.insertBefore(i,document.head.firstChild)}function Hl(e,t){if(document.getElementById(`custom-style`)?.remove(),!e)return;let n;e.startsWith(`http`)?(e=`${e}?access_token=${t}`,n=document.createElement(`link`),n.setAttribute(`rel`,`stylesheet`),n.setAttribute(`href`,e.replace(/https?:/,``))):(n=document.createElement(`style`),n.appendChild(document.createTextNode(e))),n.setAttribute(`id`,`custom-style`),n.setAttribute(`type`,`text/css`),document.head.appendChild(n)}function Ul(e,t,n,r){for(let i of n){let n=t.layers.find(e=>i.id===e.id||i.id.endsWith(` | ${e.id}`));n&&e.setLayoutProperty(n.id,`visibility`,i.visibility&&r?`visible`:`none`)}}function Wl(e,t,n,r,i,a,o){let{beforeNone:s=[],beforeNames:c=[],beforeBoundaries:l=[],beforeWaters:u=[]}=r;s.forEach(r=>{Gl(e,t,n,r,i,`mc-before-none`,a,o)}),c.forEach(r=>{Gl(e,t,n,r,i,`mc-before-names`,a,o)}),l.forEach(r=>{Gl(e,t,n,r,i,`mc-before-boundaries`,a,o)}),u.forEach(r=>{Gl(e,t,n,r,i,`mc-before-waters`,a,o)})}function Gl(e,t,n,r,i,a,o,s){if(r.type===`marker`){let o=n.marker?.find(e=>e.id===r.groupId);o&&il(e,o,a,i,t)}else if(r.type===`polygon`){let o=n.polygon?.find(e=>e.id===r.groupId);o&&$c(e,o,a,i,t)}else if(r.type===`circle`){let o=n.circle?.find(e=>e.id===r.groupId);o&&tl(e,o,a,i,t)}else if(r.type===`line`){let i=n.line?.find(e=>e.id===r.groupId);i&&kl(e,i,a,t)}else if(r.type===`dot`){let t=n.dot?.find(e=>e.id===r.groupId);t&&Nl(e,t,a)}else if(r.type===`area`){let c=n.area?.find(e=>e.id===r.groupId);c&&Ml(e,c,a,i,t,o,s)}}e.init=Il});
|
|
1140
|
+
`}return n}htmlToElement(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content.firstElementChild}addPopupControls(){let e=this.htmlToElement(yl);if(e&&(e.addEventListener(`click`,()=>{this.hidePopup(),this.highlightManager.highlight(void 0)}),this.popupContainer.appendChild(e)),this.popupElements.length<2)return;let t=this.htmlToElement(bl);t&&(t.querySelector(`.prev`)?.addEventListener(`click`,()=>this.cyclePopups(!1)),t.querySelector(`.next`)?.addEventListener(`click`,()=>this.cyclePopups()),this.popupContainer.appendChild(t))}fillDatalayerTemplate(e,t,n){let r=`data-mention-id`,i=new DOMParser().parseFromString(t,`text/html`).body;for(let t of i.querySelectorAll(`[${r}]`)){let i=this.getProperty(e,t.getAttribute(r),n);i!==void 0&&(t.innerText=i)}return i.innerHTML}getProperty(e,t,n){if(!t)return;let r=t.endsWith(`:en`)?[t.replace(`:en`,n),t]:[t];for(let t of r){let n=e.properties[t]??this.getVectorProperty(e,t);if(n!==void 0)return n}}getVectorProperty(e,t){let n=this.promoteIdCache.get(e.source);n===void 0&&(n=this.map.getSource(e.source)?.serialize().promoteId||`id`,this.promoteIdCache.set(e.source,n));try{let r=e.properties[n];return e.layer.metadata.properties[t][r]}catch{return}}cyclePopups(e=!0){let t=this.popupElements?.findIndex(e=>e.modelId===this.currentModelId);if(t!==-1){let n=0;n=e?t===this.popupElements.length-1?0:t+1:t===0?this.popupElements.length-1:t-1;let r=this.popupElements?.[n];this.highlightManager.highlight(r);let i=vl(r.popup,r.popupMedia,r.dataBindings??{},this.mode),a=this.popupContainer;this.popupContainer.remove(),a.innerHTML=i,this.mapContainer.appendChild(a),this.currentModelId=r.modelId,this.addPopupControls(),e?this.popupContainer.querySelector(`.mc-popup-button.next`)?.focus():this.popupContainer.querySelector(`.mc-popup-button.prev`)?.focus(),this.currentFeatureId=void 0}}},Ol={solid:[1,0],dotted:[.7,.3],dashed:[3.5,1.5]};function kl(e,t,n,r){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(n=>Al(e,t,n,r))}}),Object.entries(Ol).forEach(([r,i])=>{t.models.some(e=>(e.lineStyle??`solid`)===r)&&e.addLayer({id:`${t.id}-${r}`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},filter:[`all`,[`==`,[`geometry-type`],`LineString`],[`==`,[`get`,`line-style`],r]],paint:{"line-width":[`get`,`line-width`],"line-color":[`get`,`line-color`],"line-dasharray":i}},n)}),e.addLayer({id:`${t.id}-clickable`,type:`line`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},paint:{"line-width":[`max`,[`get`,`line-width`],15],"line-opacity":0},filter:[`==`,[`geometry-type`],`LineString`]},n),t.models.some(e=>e.svg)&&e.addLayer({id:`${t.id}-icon`,type:`symbol`,source:t.id,metadata:{"mc-model-type":`line`,"mc-group-id":t.id},layout:{"icon-allow-overlap":!0,"icon-ignore-placement":!0,"icon-image":[`get`,`mc-image-key`],"icon-anchor":`center`,"icon-size":[`get`,`icon-size`],"icon-rotate":[`get`,`icon-rotate`],"icon-offset":[`get`,`icon-offset`]},filter:[`==`,[`geometry-type`],`Point`]},n)}function Al(e,t,n,r){let i=n.svg===void 0?void 0:r.getMapLibreImageKey(Pr(n.dataBindings??{},n.svg,void 0),window.devicePixelRatio*(n.iconScale??1));return{type:`Feature`,id:f(n.id),properties:{id:n.id,"line-width":n.lineWidth??3,"line-color":t.lineColor||n.lineColor?Mr(n.dataBindings??{},n.lineColor,t.lineColor):`#000000`,"line-style":n.lineStyle??`solid`,"mc-image-key":i,"icon-rotate":jl(n,e),"icon-offset":n.iconOffset,"icon-size":n.iconScale},geometry:{type:`GeometryCollection`,geometries:[{type:`LineString`,coordinates:n.geometry},{type:`Point`,coordinates:n.geometry[n.geometry.length-1]}]}}}function jl(e,t){return e.iconRotation?e.iconAlign?$n(e.geometry,t)+e.iconRotation:e.iconRotation:0}function Ml(e,t,n,r,i,a,o){let s=or(t),c=new Map,l=new Map;for(let e of t.models){let n=e.featureId,a=t.id,o=[],u=Zn(e),d=Xn(a,e),f=l.get(d)??{model:e,featureIds:o,modelIdToFillColor:{},modelIdToFillPattern:{},modelIdToOutlineColor:{},modelIdToOutlineWidth:{}};if(e.visible??!0){f.featureIds.push(n);let a=e.fillPattern===void 0?null:i.getMapLibreImageKey(r[e.fillPattern],2*window.devicePixelRatio);f.modelIdToFillColor[n]=t.fillColor||e.fillColor?Mr(e.dataBindings??{},e.fillColor,t.fillColor,s,t.choropleth?.unmatchedColor):`#000000`,f.modelIdToFillPattern[n]=a,f.modelIdToOutlineColor[n]=t.outlineColor||e.outlineColor?Mr(e.dataBindings??{},e.outlineColor,t.outlineColor):`#000000`,f.modelIdToOutlineWidth[n]=e.outlineWidth??.5}c.set(u,e),l.set(d,f)}for(let t of c.keys())e.getSource(t)||e.addSource(t,{type:`vector`,url:`${a}${c.get(t).vectorUrl}?access_token=${o}`});for(let r of l.keys()){let{model:i}=l.get(r),{sourceLayerId:a}=i,o=Zn(i);e.addLayer({id:r,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-color":`#ffffff`,"fill-outline-color":`#000000`,"fill-antialias":!1}},n),e.addLayer({id:`${r}-pattern`,type:`fill`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"fill-pattern":[`get`,`fill-pattern`]},layout:{visibility:`visible`}},n),e.addLayer({id:`${r}-outline`,type:`line`,source:o,"source-layer":a,filter:[`literal`,!1],metadata:{"mc-model-type":`area`,"mc-model-id-prefix":i.vectorUrl,"mc-group-id":t.id},paint:{"line-color":`#000000`,"line-width":.5}},n)}l.forEach((t,n)=>{let{featureIds:r,modelIdToFillColor:i,modelIdToFillPattern:a,modelIdToOutlineColor:o,modelIdToOutlineWidth:s}=t;e.setFilter(n,[`in`,`id`,...r]),e.setFilter(`${n}-outline`,[`in`,`id`,...r]),e.setPaintProperty(n,`fill-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,i]]),e.setPaintProperty(`${n}-outline`,`line-color`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,o]]),e.setPaintProperty(`${n}-outline`,`line-width`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,s]]),e.setFilter(`${n}-pattern`,[`to-boolean`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]]]),e.setPaintProperty(`${n}-pattern`,`fill-pattern`,[`get`,[`case`,[`==`,[`typeof`,[`get`,`id`]],`number`],[`to-string`,[`get`,`id`]],[`get`,`id`]],[`literal`,a]])})}function Nl(e,t,n){e.addSource(t.id,{type:`geojson`,data:{type:`FeatureCollection`,features:t.models.filter(e=>e.visible??!0).map(e=>Pl(t,e))}}),e.addLayer({id:t.id,type:`circle`,source:t.id,metadata:{"mc-model-type":`dot`,"mc-group-id":t.id},paint:{"circle-color":[`get`,`circle-color`],"circle-radius":[`get`,`circle-radius`]}},n)}function Pl(e,t){return{type:`Feature`,id:t.id,properties:{id:t.id,"circle-radius":t.radius,"circle-color":e.fillColor||t.fillColor?Mr(t.dataBindings??{},t.fillColor,e.fillColor):`#000000`},geometry:{type:`Point`,coordinates:[t.center.lng,t.center.lat]}}}var Fl=class{map;constructor(e){this.map=e}};async function Il(e){let{accessToken:t,mode:r=`sdk`,env:a=`production`}=e,c=a===`bleeding`?`https://vapi.bleeding.mc-cdn.io`:a===`beta`?`https://vapi.beta.mc-cdn.io`:`https://vapi.mc-cdn.io`,l=a===`bleeding`?`https://cdn.bleeding.mapcreator.io`:a===`beta`?`https://cdn.beta.mapcreator.io`:`https://cdn.mapcreator.io`,u=typeof e.job==`string`?await Ll(e.job,l,t):e.job;await Rl();let d=new s.Map({container:e.container,attributionControl:!1,style:null,maxBounds:[-1/0,-90,1/0,90],maxPitch:85,maxZoom:22,locale:{"CooperativeGesturesHandler.WindowsHelpText":Oi(`windowsHelpText`),"CooperativeGesturesHandler.MacHelpText":Oi(`macHelpText`),"CooperativeGesturesHandler.MobileHelpText":Oi(`mobileHelpText`)}}),f=d.getContainer();f.classList.add(`mc-map`);let p=new Dr(d),m=new Dl(d,r),{map:{language:h,zoom:g,pitch:_=0,rotation:y=0,center:b,hideBasemap:x,layerInfo:S=[],detailLevel:C=0,projection:w=`mercator`,terrain:T=!1,terrainExaggeration:E=1},export:D,registry:O={},web:k,positionOffsets:A,title:j}=u,{models:M={},slots:N={},svgs:P={}}=O;Vl(a,c,t),d.resize(),r===`app`&&(document.title=j?`${j} - Mapcreator`:`Mapcreator`),d.setPitch(_),d.setBearing(y);let ee=D?.unit??`pixel`,te=v(ee,`pixel`,D?.size?.[0]??600),F=v(ee,`pixel`,D?.size?.[1]??400),ne=0;if(f.clientWidth>0&&f.clientHeight>0){let e=Math.min(f.clientWidth/te,f.clientHeight/F);ne=Math.log(e)/Math.LN2}if(d.setZoom(g-C+ne),d.setCenter(b),d.setDetailLevel(C),d.setMinZoom(C),d.addControl(new s.AttributionControl({compact:!1})),r===`app`&&d.cooperativeGestures.enable(),Jc(u,A,d,{center:b,zoom:g,pitch:_,rotation:y,detailLevel:C,width:te,height:F},c,l,t),m.setJobObject(u),k){let{restrictMapMovement:e,popupPosition:t}=k;e&&(d.boxZoom.disable(),d.doubleClickZoom.disable(),d.dragPan.disable(),d.dragRotate.disable(),d.keyboard.disable(),d.scrollZoom.disable(),d.touchPitch.disable(),d.touchZoomRotate.disable()),m.setParams(t,o(h,i.TWO),e,b)}let re=await fetch(`${c}/styles/${u.meta.mapstyleSet}.json?access_token=${t}`).then(e=>e.json());return d.setStyle(null),d.setStyle(re),await d.once(`style.load`),r===`app`&&Hl(d.getStyle().metadata?.customCssFilePath,t),n(h,d),await sl(u.meta.layers??[],d,c,t,re.metadata?.styleOverride),Wl(d,p,M,N,P,c,t),n(h,d),m.setPublication(re.metadata?.publication),m.setpopupElements(),m.setHighlightManager(),d.setProjection({type:w===`globe`?`globe`:`mercator`}),zl(d,w),T&&Bl(d,c,t,E),Ul(d,d.getStyle(),S,!x),new Fl(d)}function Ll(e,t,n){return fetch(`${t}/jobs/${e}.json?access_token=${n}`).then(e=>e.json())}function Rl(){return new Promise(e=>{let t=()=>{window.innerWidth>0&&window.innerHeight>0&&(window.removeEventListener(`resize`,t),e())};window.addEventListener(`resize`,t),t()})}function zl(e,t){let n=e.getStyle().metadata??{},r=n[`mc:background-color`]??`#f8f8f8`,i=n[`mc:background-color-globe`]??`#000000`;e.getContainer().style.backgroundColor=t===`globe`?i:r,e.setSky(e.getStyle().sky??Wc),e.setLight({position:[1.15,210,45]})}function Bl(e,t,n,r){e.addSource(`mc-dem`,{type:`raster-dem`,tiles:[`${t}/dataset/jaxa_terrainrgb/{z}/{x}/{y}?access_token=${n}`],attribution:`<a href="https://earth.jaxa.jp/en/data/policy" target="_blank">© AW3D30 (JAXA)</a>`,minzoom:0,maxzoom:12}),e.setTerrain({source:`mc-dem`,exaggeration:r})}function Vl(e,t,n){let r=`${t}/stylesheets/ff-${e===`beta`?`b-`:``}${n}.css?access_token=${n}`,i=document.createElement(`link`);i.setAttribute(`rel`,`stylesheet`),i.setAttribute(`href`,r),i.setAttribute(`type`,`text/css`),document.head.insertBefore(i,document.head.firstChild)}function Hl(e,t){if(document.getElementById(`custom-style`)?.remove(),!e)return;let n;e.startsWith(`http`)?(e=`${e}?access_token=${t}`,n=document.createElement(`link`),n.setAttribute(`rel`,`stylesheet`),n.setAttribute(`href`,e.replace(/https?:/,``))):(n=document.createElement(`style`),n.appendChild(document.createTextNode(e))),n.setAttribute(`id`,`custom-style`),n.setAttribute(`type`,`text/css`),document.head.appendChild(n)}function Ul(e,t,n,r){for(let i of n){let n=t.layers.find(e=>i.id===e.id||i.id.endsWith(` | ${e.id}`));n&&e.setLayoutProperty(n.id,`visibility`,i.visibility&&r?`visible`:`none`)}}function Wl(e,t,n,r,i,a,o){let{beforeNone:s=[],beforeNames:c=[],beforeBoundaries:l=[],beforeWaters:u=[]}=r;s.forEach(r=>{Gl(e,t,n,r,i,`mc-before-none`,a,o)}),c.forEach(r=>{Gl(e,t,n,r,i,`mc-before-names`,a,o)}),l.forEach(r=>{Gl(e,t,n,r,i,`mc-before-boundaries`,a,o)}),u.forEach(r=>{Gl(e,t,n,r,i,`mc-before-waters`,a,o)})}function Gl(e,t,n,r,i,a,o,s){if(r.type===`marker`){let o=n.marker?.find(e=>e.id===r.groupId);o&&il(e,o,a,i,t)}else if(r.type===`polygon`){let o=n.polygon?.find(e=>e.id===r.groupId);o&&$c(e,o,a,i,t)}else if(r.type===`circle`){let o=n.circle?.find(e=>e.id===r.groupId);o&&tl(e,o,a,i,t)}else if(r.type===`line`){let i=n.line?.find(e=>e.id===r.groupId);i&&kl(e,i,a,t)}else if(r.type===`dot`){let t=n.dot?.find(e=>e.id===r.groupId);t&&Nl(e,t,a)}else if(r.type===`area`){let c=n.area?.find(e=>e.id===r.groupId);c&&Ml(e,c,a,i,t,o,s)}}e.init=Il});
|