itowns 2.42.1-next.12 → 2.42.1-next.14
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/debug.js +1 -1
- package/dist/itowns.js +1 -1
- package/dist/itowns.js.map +1 -1
- package/dist/itowns_widgets.js +1 -1
- package/lib/Core/Style.js +3 -4
- package/lib/Layer/C3DTilesLayer.js +4 -4
- package/lib/Main.js +18 -5
- package/lib/Parser/B3dmParser.js +70 -113
- package/lib/Parser/GLTFParser.js +103 -0
- package/lib/Provider/3dTilesProvider.js +18 -4
- package/lib/Source/C3DTilesGoogleSource.js +84 -0
- package/package.json +3 -1
package/dist/itowns_widgets.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("itowns_widgets",[],e):"object"==typeof exports?exports.itowns_widgets=e():t.itowns_widgets=e()}(self,(()=>(self.webpackChunkitowns=self.webpackChunkitowns||[]).push([[318],{81499:(t,e,o)=>{o.r(e),o.d(e,{C3DTilesStyle:()=>A,Minimap:()=>f,Navigation:()=>c,Scale:()=>y,Searchbar:()=>T,Widget:()=>n});var i=o(36873);const n=class{#t;constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;this.parentElement=e.parentElement||t.domElement,this.position=e.position||o.position,["top-left","top-right","bottom-left","bottom-right","top","bottom","left","right"].includes(this.position)||(console.warn(`'position' optional parameter for 'Widget' constructor is not a valid option. It will be set to '${o.position}'.`),this.position=o.position),this.domElement=document.createElement("div"),this.parentElement.appendChild(this.domElement),this.domElement.style.width=`${e.width||e.size||o.width}px`,this.domElement.style.height=`${e.height||e.size||o.height}px`;const i=this.position.split("-");if(this.domElement.classList.add(`${i[0]}-widget`),i[1])this.domElement.classList.add(`${i[1]}-widget`);else switch(i[0]){case"top":case"bottom":this.domElement.style.left=`calc(50% - ${this.domElement.offsetWidth/2}px)`;break;case"left":case"right":this.domElement.style.top=`calc(50% - ${this.domElement.offsetHeight/2}px)`}e.translate&&(this.domElement.style.transform=`translate(${e.translate.x||0}px, ${e.translate.y||0}px)`),this.domElement.addEventListener("pointerdown",(t=>{t.stopPropagation()})),this.domElement.addEventListener("mousedown",(t=>{t.stopPropagation()}))}show(){this.domElement.style.display=this.#t}hide(){this.#t=window.getComputedStyle(this.domElement).display,this.domElement.style.display="none"}},s={displayCompass:!0,display3DToggle:!0,displayZoomIn:!0,displayZoomOut:!0,animationDuration:500,position:"bottom-left",direction:"column"},a={id:"compass",content:"",info:"Rotate the camera to face North",parentId:"widgets"},l={id:"3d-button",content:"3D",info:"Tilt the camera"},r={id:"zoom-in-button",content:'<span class="widget-zoom-button-logo"></span>',info:"Zoom in",parentId:"zoom-button-bar"},d={id:"zoom-out-button",content:'<span id="zoom-out-logo" class="widget-zoom-button-logo"></span>',info:"Zoom out",parentId:"zoom-button-bar"},c=class extends n{#e;#o(t){return t.time=this.animationDuration,this.#e.controls.lookAtCoordinate(t)}#i(t,e){return this.addButton(t.id,t.content,t.info,e,t.parentId)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!t.isGlobeView)throw new Error("'Navigation' plugin only supports 'GlobeView'. Therefore, the 'view' parameter must be a 'GlobeView'.");["top","bottom","left","right"].includes(e.position)&&(console.warn(`'position' optional parameter for 'Navigation' is not a valid option. It will be set to '${s.position}'.`),e.position=s.position),super(t,e,s),this.#e=t,this.direction=e.direction||s.direction,["column","row"].includes(this.direction)||(console.warn(`'direction' optional parameter for 'Navigation' constructor is not a valid option. It will be set to '${s.direction}'.`),this.direction=s.direction),this.animationDuration=void 0===e.animationDuration?s.animationDuration:e.animationDuration,this.domElement.id="widgets-navigation",this.domElement.classList.add(`${this.direction}-widget`),(e.displayCompass??s.displayCompass)&&(this.compass=this.#i(a,(()=>{this.#o({heading:0,tilt:89.5})})),t.addEventListener(i.b.CAMERA_MOVED,(t=>{this.compass.style.transform=`rotate(${-t.heading}deg)`}))),(e.display3DToggle??s.display3DToggle)&&(this.toggle3D=this.#i(l,(()=>{this.#o({tilt:this.#e.controls.getTilt()<89?89.5:40})})),t.addEventListener(i.b.CAMERA_MOVED,(t=>{this.toggle3D.innerHTML=t.tilt<89?"2D":"3D"}))),(e.displayZoomIn??s.displayZoomIn)&&(this.zoomIn=this.#i(r,(()=>{this.#o({zoom:Math.min(20,this.#e.controls.getZoom()+1)})}))),(e.displayZoomOut??s.displayZoomOut)&&(this.zoomOut=this.#i(d,(()=>{this.#o({zoom:Math.max(3,this.#e.controls.getZoom()-1)})})))}addButton(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:()=>{},n=arguments.length>4?arguments[4]:void 0,s=document.getElementById(n);s||(s=this.addButtonBar(n));const a=document.createElement("button");return a.className="widget-button",a.id=t,a.innerHTML=e,a.title=o,a.onclick=i,s.appendChild(a),a.tabIndex=-1,window.addEventListener("pointerup",(()=>{document.activeElement===a&&this.#e.domElement.focus()})),a}addButtonBar(t){const e=document.createElement("div");return e.className="widget-button-bar",t&&(e.id=t),this.domElement.appendChild(e),e}};var m=o(60145),h=o(49469),p=o(48682),u=o(800);const g={minScale:2e-6,maxScale:2e-9,zoomRatio:1/30,width:150,height:150,position:"bottom-left"},f=class extends n{constructor(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t.isGlobeView)throw new Error("'Minimap' plugin only supports 'GlobeView'. Therefore, the 'view' parameter must be a 'GlobeView'.");if(!e.isColorLayer)throw new Error("'layer' parameter form 'Minimap' constructor should be a 'ColorLayer'.");if(super(t,o,g),this.minScale=o.minScale||g.minScale,this.maxScale=o.maxScale||g.maxScale,this.zoomRatio=o.zoomRatio||g.zoomRatio,this.domElement.id="widgets-minimap",o.cursor){const t=document.createElement("div");t.id="cursor-wrapper",this.domElement.appendChild(t),"string"==typeof o.cursor?t.innerHTML=o.cursor:o.cursor instanceof HTMLElement&&t.appendChild(o.cursor)}this.view=new p.Z(this.domElement,e.source.extent,{camera:{type:u.P.ORTHOGRAPHIC},placement:e.source.extent,noControls:!0,maxSubdivisionLevel:t.tileLayer.maxSubdivisionLevel,disableFocusOnStart:!0}),this.view.addLayer(e),this.domElement.addEventListener("pointerdown",(t=>{t.preventDefault()}));const i=this.view.getScale(o.pitch),n=this.view.camera3D.zoom*this.maxScale/i,s=this.view.camera3D.zoom*this.minScale/i,a=new m.Z(t.referenceCrs),l=new m.Z(this.view.referenceCrs),r=t.controls.getCameraTargetPosition();t.addFrameRequester(h.Ao.AFTER_RENDER,(()=>{const e=t.camera3D.position.distanceTo(r),i=t.getScaleFromDistance(o.pitch,e);this.view.camera3D.zoom=this.zoomRatio*s*i/this.minScale,this.view.camera3D.zoom=Math.min(Math.max(this.view.camera3D.zoom,n),s),this.view.camera3D.updateProjectionMatrix(),a.setFromVector3(t.controls.getCameraTargetPosition()),a.as(this.view.referenceCrs,l),this.view.camera3D.position.x=l.x,this.view.camera3D.position.y=l.y,this.view.camera3D.updateMatrixWorld(!0),this.view.notifyChange(this.view.camera3D)}))}};var w=o(11925),v=o(91742),E=o(44450);const b={width:200,height:30,position:"bottom-left"},y=class extends n{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t,e,b),this.domElement.id="widgets-scale",this.view=t,this.domElement.innerHTML="Scale",this.width=e.width||b.width,this.view.isGlobeView?(this.view.addEventListener(v.b.GLOBE_INITIALIZED,(()=>{this.update()})),this.view.controls.addEventListener(w.Q.RANGE_CHANGED,(()=>{this.update()}))):this.view.isPlanarView?(this.view.addEventListener(i.b.INITIALIZED,(()=>{this.update()})),this.view.addEventListener(E.uZ.MOVED,(()=>{this.update()}))):console.warn("The 'view' linked to scale widget is neither a 'GlobeView' nor a 'PlanarView'. The scale wont automatically update. You can implement its update automation using 'Scale.update' method.")}addEventListeners(){}update(){let t=Math.round(this.view.getPixelsToMeters(this.width));const e=10**(t.toString().length-1);t=Math.round(t/e)*e;const o=this.view.getMetersToPixels(t);let i="m";t>=1e3&&(t/=1e3,i="km"),this.domElement.innerHTML=`${t} ${i}`,this.domElement.style.width=`${o}px`}};var C=o(33347);const x={width:300,height:38,position:"top",maxSuggestionNumber:10,fontSize:16,placeholder:"Search location"};function L(t,e){var o;return t?(D(t),e>=t.length?e=0:e<0&&(e=t.length-1),null===(o=t[e])||void 0===o||o.classList.add("active"),e):e}function D(t){for(let e=0;e<t.length;e++)t[e].classList.remove("active")}function S(t){for(;t.children.length>1;)t.removeChild(t.lastChild)}const T=class extends n{#n;constructor(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(super(t,o,x),!e||!e.url||!e.parser||"function"!=typeof e.parser)throw new Error("'geocodingOptions' parameter for 'Searchbar' constructor is not a valid option. Please refer to the documentation.");this.#n=e.onSelected??(()=>{}),this.domElement.id="widgets-searchbar",this.domElement.style.height="auto";const i=document.createElement("form");i.setAttribute("autocomplete","off"),i.id="searchbar-autocompletion-form",this.domElement.appendChild(i);const n=document.createElement("input");let s;n.setAttribute("type","text"),n.setAttribute("name","mySearch"),n.setAttribute("placeholder",o.placeholder||x.placeholder),n.style.height=`${o.height||o.size||x.height}px`,n.style.fontSize=`${o.fontSize||x.fontSize}px`,i.appendChild(n),n.addEventListener("input",(()=>{const t=n.value;if(S(i),s=-1,!t)return!1;e.url.searchParams.set("text",t),C.Z.json(e.url).then((a=>{const l=e.parser(a);let r=0;l.forEach(((e,a)=>{if(r===Math.min(l.size,o.maxSuggestionNumber||x.maxSuggestionNumber))return;const d=r;r++;const c=a.toUpperCase().indexOf(t.toUpperCase());if(c>-1){const l=document.createElement("div");l.style.minHeight=n.style.height,l.style.fontSize=`${o.fontSize||x.fontSize}px`;const r=a.slice(0,c),m=a.slice(c,c+t.length),h=a.slice(c+t.length,a.length);l.innerHTML=`<p>${r}<strong>${m}</strong>${h}</p>`,l.setAttribute("location",a),i.appendChild(l),l.addEventListener("mouseover",(()=>{D(i.children),s=d,l.classList.add("active")})),l.addEventListener("click",(()=>{this.#n(e),n.value=l.getAttribute("location"),S(i)}))}}))}))}));const a=(o.position||x.position).includes("top")?1:-1;n.addEventListener("keydown",(e=>{e.stopPropagation();const o=i.getElementsByTagName("div");switch(e.code){case"Escape":S(i),n.value="",t.domElement.focus();break;case"ArrowDown":e.preventDefault(),s=L(o,s+a);break;case"ArrowUp":e.preventDefault(),s=L(o,s-a);break;case"Enter":e.preventDefault(),o[Math.max(s,0)]&&(o[Math.max(s,0)].click(),t.domElement.focus())}})),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus"),D(i.children)})),i.addEventListener("mouseleave",(()=>{D(i.children),s=-1}))}};var _=o(48891),M=o(24266);const z={width:200,position:"top-right"};class I extends n{constructor(t,e){super(t,e,z),this.domElement.onclick=t=>t.stopImmediatePropagation();const o=document.createElement("select");this.domElement.appendChild(o);const i=new Map,n=()=>{for(const[t,e]of i)e.hidden=t!==o.selectedOptions[0]};o.onchange=n,t.getLayers().filter((t=>!0===t.isC3DTilesLayer)).forEach((e=>{const n=document.createElement("option");n.innerText=e.name,o.add(n);const s=document.createElement("div");this.domElement.appendChild(s),i.set(n,s),e.addEventListener(M.y.ON_TILE_CONTENT_LOADED,(()=>{for(;s.firstChild;)s.firstChild.remove();const o=new Map;for(const[,t]of e.tilesC3DTileFeatures)for(const[,e]of t)for(const t in e.getInfo().batchTable){o.has(t)||o.set(t,[]);const i=e.getInfo().batchTable[t];o.get(t).includes(i)||o.get(t).push(i)}const i=new Map,n=new Map,a=(o,a,l)=>{const r=document.createElement("input");r.setAttribute("type","color"),s.appendChild(r),r.onchange=()=>{const n=o();if(!l.includes(n))return;const s=r.value;i.set(n,(t=>t.getInfo().batchTable[a]==n?s:null)),e.updateStyle(),t.notifyChange()};const d=document.createElement("input");return d.setAttribute("type","range"),d.min=0,d.max=1,d.step=.1,d.value=1,s.appendChild(d),d.onchange=()=>{const i=o();if(!l.includes(i))return;const s=d.value;n.set(i,(t=>t.getInfo().batchTable[a]==i?s:null)),e.updateStyle(),t.notifyChange()},{inputColor:r,opacityElement:d}},l=(t,e)=>{const o=document.createElement("label");o.innerText=t,s.appendChild(o);const i=document.createElement("select");s.appendChild(i),e.forEach((t=>{const e=document.createElement("option");e.value=t,e.text=t,i.add(e)})),a((()=>i.selectedOptions[0].value),t,e)},r=(o,l)=>{const r=document.createElement("label");r.innerText=o,s.appendChild(r);const d=document.createElement("input");d.setAttribute("type","text"),s.appendChild(d);const{inputColor:c,opacityElement:m}=a((()=>d.value),o,l);d.onchange=()=>{if(!l.includes(d.value))return;const s=c.value,a=d.value;i.set(a,(t=>t.getInfo().batchTable[o]==a?s:null));const r=m.value;n.set(a,(t=>t.getInfo().batchTable[o]==a?r:null)),e.updateStyle(),t.notifyChange()}};for(const[t,e]of o)e.length<I.MAX_SELECT_VALUE?l(t,e):r(t,e);e.style=new _.ZP({fill:{color:t=>{let e=null;for(const[,o]of i)e=o(t)||e;return e},opacity:t=>{let e=1;for(const[,o]of n)e=o(t)||e;return e}}})}))})),n()}static get MAX_SELECT_VALUE(){return 10}}const A=I}},t=>(81499,t(t.s=81499))])));
|
|
1
|
+
"use strict";!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("itowns_widgets",[],e):"object"==typeof exports?exports.itowns_widgets=e():t.itowns_widgets=e()}(self,(()=>(self.webpackChunkitowns=self.webpackChunkitowns||[]).push([[318],{81499:(t,e,o)=>{o.r(e),o.d(e,{C3DTilesStyle:()=>A,Minimap:()=>f,Navigation:()=>c,Scale:()=>y,Searchbar:()=>T,Widget:()=>n});var i=o(42293);const n=class{#t;constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;this.parentElement=e.parentElement||t.domElement,this.position=e.position||o.position,["top-left","top-right","bottom-left","bottom-right","top","bottom","left","right"].includes(this.position)||(console.warn(`'position' optional parameter for 'Widget' constructor is not a valid option. It will be set to '${o.position}'.`),this.position=o.position),this.domElement=document.createElement("div"),this.parentElement.appendChild(this.domElement),this.domElement.style.width=`${e.width||e.size||o.width}px`,this.domElement.style.height=`${e.height||e.size||o.height}px`;const i=this.position.split("-");if(this.domElement.classList.add(`${i[0]}-widget`),i[1])this.domElement.classList.add(`${i[1]}-widget`);else switch(i[0]){case"top":case"bottom":this.domElement.style.left=`calc(50% - ${this.domElement.offsetWidth/2}px)`;break;case"left":case"right":this.domElement.style.top=`calc(50% - ${this.domElement.offsetHeight/2}px)`}e.translate&&(this.domElement.style.transform=`translate(${e.translate.x||0}px, ${e.translate.y||0}px)`),this.domElement.addEventListener("pointerdown",(t=>{t.stopPropagation()})),this.domElement.addEventListener("mousedown",(t=>{t.stopPropagation()}))}show(){this.domElement.style.display=this.#t}hide(){this.#t=window.getComputedStyle(this.domElement).display,this.domElement.style.display="none"}},s={displayCompass:!0,display3DToggle:!0,displayZoomIn:!0,displayZoomOut:!0,animationDuration:500,position:"bottom-left",direction:"column"},a={id:"compass",content:"",info:"Rotate the camera to face North",parentId:"widgets"},l={id:"3d-button",content:"3D",info:"Tilt the camera"},r={id:"zoom-in-button",content:'<span class="widget-zoom-button-logo"></span>',info:"Zoom in",parentId:"zoom-button-bar"},d={id:"zoom-out-button",content:'<span id="zoom-out-logo" class="widget-zoom-button-logo"></span>',info:"Zoom out",parentId:"zoom-button-bar"},c=class extends n{#e;#o(t){return t.time=this.animationDuration,this.#e.controls.lookAtCoordinate(t)}#i(t,e){return this.addButton(t.id,t.content,t.info,e,t.parentId)}constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!t.isGlobeView)throw new Error("'Navigation' plugin only supports 'GlobeView'. Therefore, the 'view' parameter must be a 'GlobeView'.");["top","bottom","left","right"].includes(e.position)&&(console.warn(`'position' optional parameter for 'Navigation' is not a valid option. It will be set to '${s.position}'.`),e.position=s.position),super(t,e,s),this.#e=t,this.direction=e.direction||s.direction,["column","row"].includes(this.direction)||(console.warn(`'direction' optional parameter for 'Navigation' constructor is not a valid option. It will be set to '${s.direction}'.`),this.direction=s.direction),this.animationDuration=void 0===e.animationDuration?s.animationDuration:e.animationDuration,this.domElement.id="widgets-navigation",this.domElement.classList.add(`${this.direction}-widget`),(e.displayCompass??s.displayCompass)&&(this.compass=this.#i(a,(()=>{this.#o({heading:0,tilt:89.5})})),t.addEventListener(i.b.CAMERA_MOVED,(t=>{this.compass.style.transform=`rotate(${-t.heading}deg)`}))),(e.display3DToggle??s.display3DToggle)&&(this.toggle3D=this.#i(l,(()=>{this.#o({tilt:this.#e.controls.getTilt()<89?89.5:40})})),t.addEventListener(i.b.CAMERA_MOVED,(t=>{this.toggle3D.innerHTML=t.tilt<89?"2D":"3D"}))),(e.displayZoomIn??s.displayZoomIn)&&(this.zoomIn=this.#i(r,(()=>{this.#o({zoom:Math.min(20,this.#e.controls.getZoom()+1)})}))),(e.displayZoomOut??s.displayZoomOut)&&(this.zoomOut=this.#i(d,(()=>{this.#o({zoom:Math.max(3,this.#e.controls.getZoom()-1)})})))}addButton(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:()=>{},n=arguments.length>4?arguments[4]:void 0,s=document.getElementById(n);s||(s=this.addButtonBar(n));const a=document.createElement("button");return a.className="widget-button",a.id=t,a.innerHTML=e,a.title=o,a.onclick=i,s.appendChild(a),a.tabIndex=-1,window.addEventListener("pointerup",(()=>{document.activeElement===a&&this.#e.domElement.focus()})),a}addButtonBar(t){const e=document.createElement("div");return e.className="widget-button-bar",t&&(e.id=t),this.domElement.appendChild(e),e}};var m=o(60145),h=o(49469),p=o(48682),u=o(800);const g={minScale:2e-6,maxScale:2e-9,zoomRatio:1/30,width:150,height:150,position:"bottom-left"},f=class extends n{constructor(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!t.isGlobeView)throw new Error("'Minimap' plugin only supports 'GlobeView'. Therefore, the 'view' parameter must be a 'GlobeView'.");if(!e.isColorLayer)throw new Error("'layer' parameter form 'Minimap' constructor should be a 'ColorLayer'.");if(super(t,o,g),this.minScale=o.minScale||g.minScale,this.maxScale=o.maxScale||g.maxScale,this.zoomRatio=o.zoomRatio||g.zoomRatio,this.domElement.id="widgets-minimap",o.cursor){const t=document.createElement("div");t.id="cursor-wrapper",this.domElement.appendChild(t),"string"==typeof o.cursor?t.innerHTML=o.cursor:o.cursor instanceof HTMLElement&&t.appendChild(o.cursor)}this.view=new p.Z(this.domElement,e.source.extent,{camera:{type:u.P.ORTHOGRAPHIC},placement:e.source.extent,noControls:!0,maxSubdivisionLevel:t.tileLayer.maxSubdivisionLevel,disableFocusOnStart:!0}),this.view.addLayer(e),this.domElement.addEventListener("pointerdown",(t=>{t.preventDefault()}));const i=this.view.getScale(o.pitch),n=this.view.camera3D.zoom*this.maxScale/i,s=this.view.camera3D.zoom*this.minScale/i,a=new m.Z(t.referenceCrs),l=new m.Z(this.view.referenceCrs),r=t.controls.getCameraTargetPosition();t.addFrameRequester(h.Ao.AFTER_RENDER,(()=>{const e=t.camera3D.position.distanceTo(r),i=t.getScaleFromDistance(o.pitch,e);this.view.camera3D.zoom=this.zoomRatio*s*i/this.minScale,this.view.camera3D.zoom=Math.min(Math.max(this.view.camera3D.zoom,n),s),this.view.camera3D.updateProjectionMatrix(),a.setFromVector3(t.controls.getCameraTargetPosition()),a.as(this.view.referenceCrs,l),this.view.camera3D.position.x=l.x,this.view.camera3D.position.y=l.y,this.view.camera3D.updateMatrixWorld(!0),this.view.notifyChange(this.view.camera3D)}))}};var w=o(11925),v=o(91742),E=o(44450);const b={width:200,height:30,position:"bottom-left"},y=class extends n{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t,e,b),this.domElement.id="widgets-scale",this.view=t,this.domElement.innerHTML="Scale",this.width=e.width||b.width,this.view.isGlobeView?(this.view.addEventListener(v.b.GLOBE_INITIALIZED,(()=>{this.update()})),this.view.controls.addEventListener(w.Q.RANGE_CHANGED,(()=>{this.update()}))):this.view.isPlanarView?(this.view.addEventListener(i.b.INITIALIZED,(()=>{this.update()})),this.view.addEventListener(E.uZ.MOVED,(()=>{this.update()}))):console.warn("The 'view' linked to scale widget is neither a 'GlobeView' nor a 'PlanarView'. The scale wont automatically update. You can implement its update automation using 'Scale.update' method.")}addEventListeners(){}update(){let t=Math.round(this.view.getPixelsToMeters(this.width));const e=10**(t.toString().length-1);t=Math.round(t/e)*e;const o=this.view.getMetersToPixels(t);let i="m";t>=1e3&&(t/=1e3,i="km"),this.domElement.innerHTML=`${t} ${i}`,this.domElement.style.width=`${o}px`}};var C=o(33347);const x={width:300,height:38,position:"top",maxSuggestionNumber:10,fontSize:16,placeholder:"Search location"};function L(t,e){var o;return t?(D(t),e>=t.length?e=0:e<0&&(e=t.length-1),null===(o=t[e])||void 0===o||o.classList.add("active"),e):e}function D(t){for(let e=0;e<t.length;e++)t[e].classList.remove("active")}function S(t){for(;t.children.length>1;)t.removeChild(t.lastChild)}const T=class extends n{#n;constructor(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(super(t,o,x),!e||!e.url||!e.parser||"function"!=typeof e.parser)throw new Error("'geocodingOptions' parameter for 'Searchbar' constructor is not a valid option. Please refer to the documentation.");this.#n=e.onSelected??(()=>{}),this.domElement.id="widgets-searchbar",this.domElement.style.height="auto";const i=document.createElement("form");i.setAttribute("autocomplete","off"),i.id="searchbar-autocompletion-form",this.domElement.appendChild(i);const n=document.createElement("input");let s;n.setAttribute("type","text"),n.setAttribute("name","mySearch"),n.setAttribute("placeholder",o.placeholder||x.placeholder),n.style.height=`${o.height||o.size||x.height}px`,n.style.fontSize=`${o.fontSize||x.fontSize}px`,i.appendChild(n),n.addEventListener("input",(()=>{const t=n.value;if(S(i),s=-1,!t)return!1;e.url.searchParams.set("text",t),C.Z.json(e.url).then((a=>{const l=e.parser(a);let r=0;l.forEach(((e,a)=>{if(r===Math.min(l.size,o.maxSuggestionNumber||x.maxSuggestionNumber))return;const d=r;r++;const c=a.toUpperCase().indexOf(t.toUpperCase());if(c>-1){const l=document.createElement("div");l.style.minHeight=n.style.height,l.style.fontSize=`${o.fontSize||x.fontSize}px`;const r=a.slice(0,c),m=a.slice(c,c+t.length),h=a.slice(c+t.length,a.length);l.innerHTML=`<p>${r}<strong>${m}</strong>${h}</p>`,l.setAttribute("location",a),i.appendChild(l),l.addEventListener("mouseover",(()=>{D(i.children),s=d,l.classList.add("active")})),l.addEventListener("click",(()=>{this.#n(e),n.value=l.getAttribute("location"),S(i)}))}}))}))}));const a=(o.position||x.position).includes("top")?1:-1;n.addEventListener("keydown",(e=>{e.stopPropagation();const o=i.getElementsByTagName("div");switch(e.code){case"Escape":S(i),n.value="",t.domElement.focus();break;case"ArrowDown":e.preventDefault(),s=L(o,s+a);break;case"ArrowUp":e.preventDefault(),s=L(o,s-a);break;case"Enter":e.preventDefault(),o[Math.max(s,0)]&&(o[Math.max(s,0)].click(),t.domElement.focus())}})),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus"),D(i.children)})),i.addEventListener("mouseleave",(()=>{D(i.children),s=-1}))}};var _=o(48891),M=o(24266);const z={width:200,position:"top-right"};class I extends n{constructor(t,e){super(t,e,z),this.domElement.onclick=t=>t.stopImmediatePropagation();const o=document.createElement("select");this.domElement.appendChild(o);const i=new Map,n=()=>{for(const[t,e]of i)e.hidden=t!==o.selectedOptions[0]};o.onchange=n,t.getLayers().filter((t=>!0===t.isC3DTilesLayer)).forEach((e=>{const n=document.createElement("option");n.innerText=e.name,o.add(n);const s=document.createElement("div");this.domElement.appendChild(s),i.set(n,s),e.addEventListener(M.y.ON_TILE_CONTENT_LOADED,(()=>{for(;s.firstChild;)s.firstChild.remove();const o=new Map;for(const[,t]of e.tilesC3DTileFeatures)for(const[,e]of t)for(const t in e.getInfo().batchTable){o.has(t)||o.set(t,[]);const i=e.getInfo().batchTable[t];o.get(t).includes(i)||o.get(t).push(i)}const i=new Map,n=new Map,a=(o,a,l)=>{const r=document.createElement("input");r.setAttribute("type","color"),s.appendChild(r),r.onchange=()=>{const n=o();if(!l.includes(n))return;const s=r.value;i.set(n,(t=>t.getInfo().batchTable[a]==n?s:null)),e.updateStyle(),t.notifyChange()};const d=document.createElement("input");return d.setAttribute("type","range"),d.min=0,d.max=1,d.step=.1,d.value=1,s.appendChild(d),d.onchange=()=>{const i=o();if(!l.includes(i))return;const s=d.value;n.set(i,(t=>t.getInfo().batchTable[a]==i?s:null)),e.updateStyle(),t.notifyChange()},{inputColor:r,opacityElement:d}},l=(t,e)=>{const o=document.createElement("label");o.innerText=t,s.appendChild(o);const i=document.createElement("select");s.appendChild(i),e.forEach((t=>{const e=document.createElement("option");e.value=t,e.text=t,i.add(e)})),a((()=>i.selectedOptions[0].value),t,e)},r=(o,l)=>{const r=document.createElement("label");r.innerText=o,s.appendChild(r);const d=document.createElement("input");d.setAttribute("type","text"),s.appendChild(d);const{inputColor:c,opacityElement:m}=a((()=>d.value),o,l);d.onchange=()=>{if(!l.includes(d.value))return;const s=c.value,a=d.value;i.set(a,(t=>t.getInfo().batchTable[o]==a?s:null));const r=m.value;n.set(a,(t=>t.getInfo().batchTable[o]==a?r:null)),e.updateStyle(),t.notifyChange()}};for(const[t,e]of o)e.length<I.MAX_SELECT_VALUE?l(t,e):r(t,e);e.style=new _.ZP({fill:{color:t=>{let e=null;for(const[,o]of i)e=o(t)||e;return e},opacity:t=>{let e=1;for(const[,o]of n)e=o(t)||e;return e}}})}))})),n()}static get MAX_SELECT_VALUE(){return 10}}const A=I}},t=>(81499,t(t.s=81499))])));
|
|
2
2
|
//# sourceMappingURL=itowns_widgets.js.map
|
package/lib/Core/Style.js
CHANGED
|
@@ -19,10 +19,9 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
19
19
|
const itowns_stroke_single_before = ".itowns-stroke-single:before {\n display: var(--text_stroke_display);\n content: attr(data-before);\n opacity: 1;\n position: absolute;\n -webkit-text-stroke-width: var(--text_stroke_width);\n -webkit-text-stroke-color: var(--text_stroke_color);\n left: 0;\n right: 0;\n bottom: 0;\n top: 0;\n z-index: -1;\n white-space: inherit;\n overflow-wrap: inherit;\n letter-spacing: inherit;\n text-align: inherit;\n padding: inherit;\n font-family: inherit;\n text-transform: inherit;\n max-width: inherit;\n font-size: inherit;\n}\n";
|
|
20
20
|
const cacheStyle = new _Cache.default();
|
|
21
21
|
exports.cacheStyle = cacheStyle;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
22
|
+
const matrix = document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix();
|
|
23
|
+
const canvas = document.createElement('canvas');
|
|
24
24
|
const inv255 = 1 / 255;
|
|
25
|
-
const canvas = typeof document !== 'undefined' ? document.createElement('canvas') : {};
|
|
26
25
|
function baseAltitudeDefault(properties, ctx) {
|
|
27
26
|
var _ctx$coordinates;
|
|
28
27
|
return (ctx === null || ctx === void 0 ? void 0 : (_ctx$coordinates = ctx.coordinates) === null || _ctx$coordinates === void 0 ? void 0 : _ctx$coordinates.z) || 0;
|
|
@@ -1131,7 +1130,7 @@ class Style {
|
|
|
1131
1130
|
const CustomStyle = {
|
|
1132
1131
|
itowns_stroke_single_before
|
|
1133
1132
|
};
|
|
1134
|
-
const customStyleSheet =
|
|
1133
|
+
const customStyleSheet = document.createElement('style');
|
|
1135
1134
|
customStyleSheet.type = 'text/css';
|
|
1136
1135
|
Object.keys(CustomStyle).forEach(key => {
|
|
1137
1136
|
customStyleSheet.innerHTML += `${CustomStyle[key]}\n\n`;
|
|
@@ -39,8 +39,8 @@ const update = (0, _dTilesProcessing.process3dTilesNode)();
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Find tileId of object
|
|
42
|
-
*
|
|
43
42
|
* @param {THREE.Object3D} object - object
|
|
43
|
+
*
|
|
44
44
|
* @returns {number} tileId
|
|
45
45
|
*/
|
|
46
46
|
function findTileID(object) {
|
|
@@ -55,8 +55,8 @@ function findTileID(object) {
|
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Check if object3d has feature
|
|
58
|
-
*
|
|
59
58
|
* @param {THREE.Object3D} object3d - object3d to check
|
|
59
|
+
*
|
|
60
60
|
* @returns {boolean} - true if object3d has feature
|
|
61
61
|
*/
|
|
62
62
|
function object3DHasFeature(object3d) {
|
|
@@ -229,6 +229,7 @@ class C3DTilesLayer extends _GeometryLayer.default {
|
|
|
229
229
|
* targets picked under specified coordinates. Intersects can be
|
|
230
230
|
* computed with view.pickObjectsAt(..). See fillHTMLWithPickingInfo()
|
|
231
231
|
* in 3dTilesHelper.js for an example.
|
|
232
|
+
*
|
|
232
233
|
* @returns {C3DTileFeature} - the closest C3DTileFeature of the intersects array
|
|
233
234
|
*/
|
|
234
235
|
getC3DTileFeatureFromIntersectsArray(intersects) {
|
|
@@ -274,7 +275,6 @@ class C3DTilesLayer extends _GeometryLayer.default {
|
|
|
274
275
|
|
|
275
276
|
/**
|
|
276
277
|
* Initialize C3DTileFeatures from tileContent
|
|
277
|
-
*
|
|
278
278
|
* @param {THREE.Object3D} tileContent - tile as THREE.Object3D
|
|
279
279
|
*/
|
|
280
280
|
initC3DTileFeatures(tileContent) {
|
|
@@ -339,8 +339,8 @@ class C3DTilesLayer extends _GeometryLayer.default {
|
|
|
339
339
|
/**
|
|
340
340
|
* Update style of the C3DTFeatures, an allowList of tile id can be passed to only update certain tile.
|
|
341
341
|
* Note that this function only update THREE.Object3D materials, in order to see style changes you should call view.notifyChange()
|
|
342
|
-
*
|
|
343
342
|
* @param {Array<number>|null} [allowTileIdList] - tile ids to allow in updateStyle computation if null all tiles are updated
|
|
343
|
+
*
|
|
344
344
|
* @returns {boolean} true if style updated false otherwise
|
|
345
345
|
*/
|
|
346
346
|
updateStyle() {
|
package/lib/Main.js
CHANGED
|
@@ -58,6 +58,12 @@ Object.defineProperty(exports, "C3DTilesBoundingVolumeTypes", {
|
|
|
58
58
|
return _C3DTilesEnums.C3DTilesBoundingVolumeTypes;
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
+
Object.defineProperty(exports, "C3DTilesGoogleSource", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _C3DTilesGoogleSource.default;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
61
67
|
Object.defineProperty(exports, "C3DTilesIonSource", {
|
|
62
68
|
enumerable: true,
|
|
63
69
|
get: function () {
|
|
@@ -268,6 +274,12 @@ Object.defineProperty(exports, "GLOBE_VIEW_EVENTS", {
|
|
|
268
274
|
return _GlobeView.GLOBE_VIEW_EVENTS;
|
|
269
275
|
}
|
|
270
276
|
});
|
|
277
|
+
Object.defineProperty(exports, "GLTFParser", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function () {
|
|
280
|
+
return _GLTFParser.default;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
271
283
|
Object.defineProperty(exports, "GTXParser", {
|
|
272
284
|
enumerable: true,
|
|
273
285
|
get: function () {
|
|
@@ -578,13 +590,13 @@ Object.defineProperty(exports, "ellipsoidSizes", {
|
|
|
578
590
|
Object.defineProperty(exports, "enableDracoLoader", {
|
|
579
591
|
enumerable: true,
|
|
580
592
|
get: function () {
|
|
581
|
-
return
|
|
593
|
+
return _GLTFParser.enableDracoLoader;
|
|
582
594
|
}
|
|
583
595
|
});
|
|
584
596
|
Object.defineProperty(exports, "enableKtx2Loader", {
|
|
585
597
|
enumerable: true,
|
|
586
598
|
get: function () {
|
|
587
|
-
return
|
|
599
|
+
return _GLTFParser.enableKtx2Loader;
|
|
588
600
|
}
|
|
589
601
|
});
|
|
590
602
|
Object.defineProperty(exports, "getMaxColorSamplerUnitsCount", {
|
|
@@ -596,13 +608,13 @@ Object.defineProperty(exports, "getMaxColorSamplerUnitsCount", {
|
|
|
596
608
|
Object.defineProperty(exports, "glTFLoader", {
|
|
597
609
|
enumerable: true,
|
|
598
610
|
get: function () {
|
|
599
|
-
return
|
|
611
|
+
return _GLTFParser.glTFLoader;
|
|
600
612
|
}
|
|
601
613
|
});
|
|
602
614
|
Object.defineProperty(exports, "legacyGLTFLoader", {
|
|
603
615
|
enumerable: true,
|
|
604
616
|
get: function () {
|
|
605
|
-
return
|
|
617
|
+
return _GLTFParser.legacyGLTFLoader;
|
|
606
618
|
}
|
|
607
619
|
});
|
|
608
620
|
Object.defineProperty(exports, "process3dTilesNode", {
|
|
@@ -682,6 +694,7 @@ var _OrientedImageSource = _interopRequireDefault(require("./Source/OrientedImag
|
|
|
682
694
|
var _PotreeSource = _interopRequireDefault(require("./Source/PotreeSource"));
|
|
683
695
|
var _C3DTilesSource = _interopRequireDefault(require("./Source/C3DTilesSource"));
|
|
684
696
|
var _C3DTilesIonSource = _interopRequireDefault(require("./Source/C3DTilesIonSource"));
|
|
697
|
+
var _C3DTilesGoogleSource = _interopRequireDefault(require("./Source/C3DTilesGoogleSource"));
|
|
685
698
|
var _EntwinePointTileSource = _interopRequireDefault(require("./Source/EntwinePointTileSource"));
|
|
686
699
|
var _GpxParser = _interopRequireDefault(require("./Parser/GpxParser"));
|
|
687
700
|
var _GeoJsonParser = _interopRequireDefault(require("./Parser/GeoJsonParser"));
|
|
@@ -692,7 +705,7 @@ var _LASParser = _interopRequireDefault(require("./Parser/LASParser"));
|
|
|
692
705
|
var _ISGParser = _interopRequireDefault(require("./Parser/ISGParser"));
|
|
693
706
|
var _GDFParser = _interopRequireDefault(require("./Parser/GDFParser"));
|
|
694
707
|
var _GTXParser = _interopRequireDefault(require("./Parser/GTXParser"));
|
|
695
|
-
var
|
|
708
|
+
var _GLTFParser = _interopRequireWildcard(require("./Parser/GLTFParser"));
|
|
696
709
|
var _C3DTFeature = _interopRequireDefault(require("./Core/3DTiles/C3DTFeature"));
|
|
697
710
|
var _C3DTileset = _interopRequireDefault(require("./Core/3DTiles/C3DTileset"));
|
|
698
711
|
var _C3DTBoundingVolume = _interopRequireDefault(require("./Core/3DTiles/C3DTBoundingVolume"));
|
package/lib/Parser/B3dmParser.js
CHANGED
|
@@ -5,29 +5,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
exports.enableDracoLoader = enableDracoLoader;
|
|
9
|
-
exports.enableKtx2Loader = enableKtx2Loader;
|
|
10
|
-
exports.legacyGLTFLoader = exports.glTFLoader = void 0;
|
|
11
8
|
var THREE = _interopRequireWildcard(require("three"));
|
|
9
|
+
var _C3DTBatchTable = _interopRequireDefault(require("../Core/3DTiles/C3DTBatchTable"));
|
|
12
10
|
var _Capabilities = _interopRequireDefault(require("../Core/System/Capabilities"));
|
|
13
|
-
var
|
|
14
|
-
var _DRACOLoader = require("../ThreeExtended/loaders/DRACOLoader");
|
|
15
|
-
var _KTX2Loader = require("../ThreeExtended/loaders/KTX2Loader");
|
|
16
|
-
var _LegacyGLTFLoader = _interopRequireDefault(require("./deprecated/LegacyGLTFLoader"));
|
|
11
|
+
var _ThreeUtils = _interopRequireDefault(require("../Utils/ThreeUtils"));
|
|
17
12
|
var _ShaderUtils = _interopRequireDefault(require("../Renderer/Shader/ShaderUtils"));
|
|
18
|
-
var _C3DTBatchTable = _interopRequireDefault(require("../Core/3DTiles/C3DTBatchTable"));
|
|
19
13
|
var _ReferencingLayerProperties = _interopRequireDefault(require("../Layer/ReferencingLayerProperties"));
|
|
20
|
-
var
|
|
14
|
+
var _GLTFParser = _interopRequireDefault(require("./GLTFParser"));
|
|
21
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const matrixChangeUpVectorZtoX = new THREE.Matrix4().makeRotationZ(-Math.PI / 2);
|
|
17
|
+
const matrixChangeUpVectorYtoZInv = new THREE.Matrix4().makeRotationX(-Math.PI / 2);
|
|
18
|
+
const matrixChangeUpVectorXtoZ = new THREE.Matrix4().makeRotationZ(-Math.PI / 2);
|
|
26
19
|
const utf8Decoder = new TextDecoder();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 3D Tiles pre-1.0 contain not standardized and specific uniforms that we filter out to avoid shader compilation errors
|
|
23
|
+
* This method is passed to scene.traverse and applied to all 3D objects of the loaded gltf.
|
|
24
|
+
* @param {THREE.Object3D} obj - 3D object of the gltf hierarchy
|
|
25
|
+
*/
|
|
31
26
|
function filterUnsupportedSemantics(obj) {
|
|
32
27
|
// see GLTFLoader GLTFShader.prototype.update function
|
|
33
28
|
const supported = ['MODELVIEW', 'MODELVIEWINVERSETRANSPOSE', 'PROJECTION', 'JOINTMATRIX'];
|
|
@@ -47,67 +42,35 @@ function filterUnsupportedSemantics(obj) {
|
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* The Draco library files are in folder itowns/examples/libs/draco/.
|
|
56
|
-
* You must indicate this path when you want to enable Draco Decoding.
|
|
57
|
-
* For more information on Draco, read /itowns/examples/libs/draco/README.md.
|
|
58
|
-
*
|
|
59
|
-
* @example <caption>Enable draco decoder</caption>
|
|
60
|
-
* // if you copied /itowns/examples/libs/draco/ to the root folder of your project,you can set the path to './'.
|
|
61
|
-
* itowns.enableDracoLoader('./');
|
|
62
|
-
*
|
|
63
|
-
* @param {string} path path to draco library folder.
|
|
64
|
-
* This library is mandatory to load b3dm and gltf with Draco compression.
|
|
65
|
-
* @param {object} config optional configuration for Draco compression.
|
|
45
|
+
* 3D Tiles pre-1.0 had a gltfUpAxis parameter that defined the up vector of the gltf file that might be different from
|
|
46
|
+
* the standard y-up for gltf. Manage the case when this gltfUpAxis is defined (i.e. apply the correct rotation to the
|
|
47
|
+
* gltf file to have it z-up in the end).
|
|
48
|
+
* @param {THREE.Object3D} gltfScene - the parsed glTF scene
|
|
49
|
+
* @param {String} gltfUpAxis - the gltfUpAxis parameter
|
|
66
50
|
*/
|
|
67
|
-
function
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
dracoLoader.setDecoderConfig(config);
|
|
51
|
+
function applyDeprecatedGltfUpAxis(gltfScene, gltfUpAxis) {
|
|
52
|
+
if (gltfUpAxis === 'Z') {
|
|
53
|
+
// If gltf up was already z-up, apply the inverse transform matrix that was applied in the glTFParser
|
|
54
|
+
gltfScene.applyMatrix4(matrixChangeUpVectorYtoZInv);
|
|
55
|
+
} else if (gltfUpAxis === 'X') {
|
|
56
|
+
gltfScene.applyMatrix4(matrixChangeUpVectorYtoZInv);
|
|
57
|
+
gltfScene.applyMatrix4(matrixChangeUpVectorXtoZ);
|
|
75
58
|
}
|
|
76
|
-
glTFLoader.setDRACOLoader(dracoLoader);
|
|
77
59
|
}
|
|
78
60
|
|
|
79
61
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* The KTX2 library files are in folder itowns/examples/libs/basis/.
|
|
83
|
-
* You must indicate this path when you want to enable KTX2 decoding.
|
|
84
|
-
* For more information about KTX2, read /itowns/examples/libs/basis/README.md.
|
|
85
|
-
*
|
|
86
|
-
* @example <caption>Enable ktx2 decoder</caption>
|
|
87
|
-
* // if you copied /itowns/examples/libs/draco/ to the root folder of your project,you can set the path to './'.
|
|
88
|
-
* itowns.enableKtx2Loader('./', view.mainLoop.gfxEngine.renderer);
|
|
89
|
-
*
|
|
90
|
-
* @param {string} path path to KTX2 library folder.
|
|
91
|
-
* @param {THREE.WebGLRenderer} renderer the threejs renderer
|
|
62
|
+
* @module B3dmParser
|
|
92
63
|
*/
|
|
93
|
-
function enableKtx2Loader(path, renderer) {
|
|
94
|
-
if (!path || !renderer) {
|
|
95
|
-
throw new Error('Path to ktx2 folder and renderer are mandatory');
|
|
96
|
-
}
|
|
97
|
-
const ktx2Loader = new _KTX2Loader.KTX2Loader();
|
|
98
|
-
ktx2Loader.setTranscoderPath(path);
|
|
99
|
-
ktx2Loader.detectSupport(renderer);
|
|
100
|
-
glTFLoader.setKTX2Loader(ktx2Loader);
|
|
101
|
-
}
|
|
102
64
|
var _default = {
|
|
103
65
|
/** Parse b3dm buffer and extract THREE.Scene and batch table
|
|
104
66
|
* @param {ArrayBuffer} buffer - the b3dm buffer.
|
|
105
67
|
* @param {Object} options - additional properties.
|
|
106
68
|
* @param {string=} [options.gltfUpAxis='Y'] - embedded glTF model up axis.
|
|
107
69
|
* @param {string} options.urlBase - the base url of the b3dm file (used to fetch textures for the embedded glTF model).
|
|
108
|
-
* @param {boolean=} [options.doNotPatchMaterial=
|
|
70
|
+
* @param {boolean=} [options.doNotPatchMaterial=false] - disable patching material with logarithmic depth buffer support.
|
|
109
71
|
* @param {float} [options.opacity=1.0] - the b3dm opacity.
|
|
110
|
-
* @param {boolean
|
|
72
|
+
* @param {boolean=} [options.frustumCulled=false] - enable frustum culling.
|
|
73
|
+
* @param {boolean|Material=} [options.overrideMaterials=false] - override b3dm's embedded glTF materials. If
|
|
111
74
|
* true, a threejs [MeshBasicMaterial](https://threejs.org/docs/index.html?q=meshbasic#api/en/materials/MeshBasicMaterial)
|
|
112
75
|
* is set up. config.overrideMaterials can also be a threejs [Material](https://threejs.org/docs/index.html?q=material#api/en/materials/Material)
|
|
113
76
|
* in which case it will be the material used to override.
|
|
@@ -115,8 +78,7 @@ var _default = {
|
|
|
115
78
|
*
|
|
116
79
|
*/
|
|
117
80
|
parse(buffer, options) {
|
|
118
|
-
const
|
|
119
|
-
const urlBase = options.urlBase;
|
|
81
|
+
const frustumCulled = options.frustumCulled === true;
|
|
120
82
|
if (!buffer) {
|
|
121
83
|
throw new Error('No array buffer provided.');
|
|
122
84
|
}
|
|
@@ -173,61 +135,56 @@ var _default = {
|
|
|
173
135
|
const posGltf = headerByteLength + b3dmHeader.FTJSONLength + b3dmHeader.FTBinaryLength + b3dmHeader.BTJSONLength + b3dmHeader.BTBinaryLength;
|
|
174
136
|
const gltfBuffer = buffer.slice(posGltf);
|
|
175
137
|
const headerView = new DataView(gltfBuffer, 0, 20);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
138
|
+
const init_mesh = function (mesh) {
|
|
139
|
+
mesh.frustumCulled = frustumCulled;
|
|
140
|
+
if (mesh.material) {
|
|
141
|
+
if (options.overrideMaterials) {
|
|
142
|
+
const oldMat = mesh.material;
|
|
143
|
+
// Set up new material
|
|
144
|
+
if (typeof options.overrideMaterials === 'object' && options.overrideMaterials.isMaterial) {
|
|
145
|
+
mesh.material = options.overrideMaterials;
|
|
146
|
+
} else {
|
|
147
|
+
mesh.material = new THREE.MeshBasicMaterial();
|
|
148
|
+
}
|
|
149
|
+
(0, _ThreeUtils.default)(oldMat);
|
|
150
|
+
} else if (_Capabilities.default.isLogDepthBufferSupported() && mesh.material.isRawShaderMaterial && !options.doNotPatchMaterial) {
|
|
151
|
+
_ShaderUtils.default.patchMaterialForLogDepthSupport(mesh.material);
|
|
152
|
+
console.warn('glTF shader has been patched to add log depth buffer support');
|
|
186
153
|
}
|
|
154
|
+
(0, _ReferencingLayerProperties.default)(mesh.material, options.layer);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
promises.push(_GLTFParser.default.parse(gltfBuffer, options).then(gltf => {
|
|
158
|
+
for (const scene of gltf.scenes) {
|
|
159
|
+
scene.traverse(filterUnsupportedSemantics);
|
|
160
|
+
}
|
|
161
|
+
applyDeprecatedGltfUpAxis(gltf.scene, options.gltfUpAxis);
|
|
162
|
+
const shouldBePatchedForLogDepthSupport = _Capabilities.default.isLogDepthBufferSupported() && !options.doNotPatchMaterial;
|
|
163
|
+
if (options.frustumCulling === false || options.overrideMaterials || shouldBePatchedForLogDepthSupport || options.layer) {
|
|
164
|
+
gltf.scene.traverse(init_mesh);
|
|
165
|
+
}
|
|
187
166
|
|
|
188
|
-
|
|
189
|
-
|
|
167
|
+
// Apply relative center from Feature table.
|
|
168
|
+
gltf.scene.position.copy(FT_RTC);
|
|
190
169
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
gltf.scene.traverse(function (mesh) {
|
|
200
|
-
mesh.frustumCulled = false;
|
|
201
|
-
if (mesh.material) {
|
|
202
|
-
if (options.overrideMaterials) {
|
|
203
|
-
const oldMat = mesh.material;
|
|
204
|
-
// Set up new material
|
|
205
|
-
if (typeof options.overrideMaterials === 'object' && options.overrideMaterials.isMaterial) {
|
|
206
|
-
mesh.material = options.overrideMaterials;
|
|
207
|
-
} else {
|
|
208
|
-
mesh.material = new THREE.MeshBasicMaterial();
|
|
209
|
-
}
|
|
210
|
-
(0, _ThreeUtils.default)(oldMat);
|
|
211
|
-
} else if (_Capabilities.default.isLogDepthBufferSupported() && mesh.material.isRawShaderMaterial && !options.doNotPatchMaterial) {
|
|
212
|
-
_ShaderUtils.default.patchMaterialForLogDepthSupport(mesh.material);
|
|
213
|
-
console.warn('b3dm shader has been patched to add log depth buffer support');
|
|
214
|
-
}
|
|
215
|
-
(0, _ReferencingLayerProperties.default)(mesh.material, options.layer);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
resolve(gltf);
|
|
219
|
-
};
|
|
220
|
-
const version = headerView.getUint32(4, true);
|
|
221
|
-
if (version === 1) {
|
|
222
|
-
legacyGLTFLoader.parse(gltfBuffer, urlBase, onload);
|
|
223
|
-
} else {
|
|
224
|
-
glTFLoader.parse(gltfBuffer, urlBase, onload);
|
|
170
|
+
// Apply relative center from gltf json.
|
|
171
|
+
const contentArray = new Uint8Array(gltfBuffer, 20, headerView.getUint32(12, true));
|
|
172
|
+
const content = utf8Decoder.decode(new Uint8Array(contentArray));
|
|
173
|
+
const json = JSON.parse(content);
|
|
174
|
+
if (json.extensions && json.extensions.CESIUM_RTC) {
|
|
175
|
+
gltf.scene.position.fromArray(json.extensions.CESIUM_RTC.center);
|
|
176
|
+
gltf.scene.updateMatrixWorld(true);
|
|
225
177
|
}
|
|
178
|
+
return gltf;
|
|
179
|
+
}).catch(e => {
|
|
180
|
+
throw new Error(e);
|
|
226
181
|
}));
|
|
227
182
|
return Promise.all(promises).then(values => ({
|
|
228
183
|
gltf: values[1],
|
|
229
184
|
batchTable: values[0]
|
|
230
|
-
}))
|
|
185
|
+
})).catch(e => {
|
|
186
|
+
throw new Error(e);
|
|
187
|
+
});
|
|
231
188
|
} else {
|
|
232
189
|
throw new Error('Invalid b3dm file.');
|
|
233
190
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
exports.enableDracoLoader = enableDracoLoader;
|
|
9
|
+
exports.enableKtx2Loader = enableKtx2Loader;
|
|
10
|
+
exports.legacyGLTFLoader = exports.glTFLoader = void 0;
|
|
11
|
+
var THREE = _interopRequireWildcard(require("three"));
|
|
12
|
+
var _GLTFLoader = require("../ThreeExtended/loaders/GLTFLoader");
|
|
13
|
+
var _DRACOLoader = require("../ThreeExtended/loaders/DRACOLoader");
|
|
14
|
+
var _KTX2Loader = require("../ThreeExtended/loaders/KTX2Loader");
|
|
15
|
+
var _LegacyGLTFLoader = _interopRequireDefault(require("./deprecated/LegacyGLTFLoader"));
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
const matrixChangeUpVectorYtoZ = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
|
19
|
+
const glTFLoader = new _GLTFLoader.GLTFLoader();
|
|
20
|
+
exports.glTFLoader = glTFLoader;
|
|
21
|
+
const legacyGLTFLoader = new _LegacyGLTFLoader.default();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @module GLTFParser
|
|
25
|
+
* @description Parses [glTF](https://www.khronos.org/gltf/) 1.0 and 2.0 files.
|
|
26
|
+
*
|
|
27
|
+
* Under the hood, glTF 2.0 files are parsed with THREE.GltfLoader() and GLTF 1.0 are parsed with the previous THREE
|
|
28
|
+
* GltfLoader (for 1.0 glTF) that has been kept and maintained in iTowns.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Enable loading gltf files with [Draco](https://google.github.io/draco/) geometry extension.
|
|
33
|
+
*
|
|
34
|
+
* @param {String} path path to draco library folder containing the JS and WASM decoder libraries. They can be found in
|
|
35
|
+
* [itowns examples](https://github.com/iTowns/itowns/tree/master/examples/libs/draco).
|
|
36
|
+
* @param {Object} [config] optional configuration for Draco decoder (see threejs'
|
|
37
|
+
* [setDecoderConfig](https://threejs.org/docs/index.html?q=draco#examples/en/loaders/DRACOLoader.setDecoderConfig) that
|
|
38
|
+
* is called under the hood with this configuration for details.
|
|
39
|
+
*/
|
|
40
|
+
exports.legacyGLTFLoader = legacyGLTFLoader;
|
|
41
|
+
function enableDracoLoader(path, config) {
|
|
42
|
+
if (!path) {
|
|
43
|
+
throw new Error('Path to draco folder is mandatory');
|
|
44
|
+
}
|
|
45
|
+
const dracoLoader = new _DRACOLoader.DRACOLoader();
|
|
46
|
+
dracoLoader.setDecoderPath(path);
|
|
47
|
+
if (config) {
|
|
48
|
+
dracoLoader.setDecoderConfig(config);
|
|
49
|
+
}
|
|
50
|
+
glTFLoader.setDRACOLoader(dracoLoader);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Enable loading gltf files with [KTX2](https://www.khronos.org/ktx/) texture extension.
|
|
55
|
+
*
|
|
56
|
+
* @param {String} path path to ktx2 library folder containing the JS and WASM decoder libraries. They can be found in
|
|
57
|
+
* [itowns examples](https://github.com/iTowns/itowns/tree/master/examples/libs/basis).
|
|
58
|
+
* @param {THREE.WebGLRenderer} renderer the threejs renderer
|
|
59
|
+
*/
|
|
60
|
+
function enableKtx2Loader(path, renderer) {
|
|
61
|
+
if (!path || !renderer) {
|
|
62
|
+
throw new Error('Path to ktx2 folder and renderer are mandatory');
|
|
63
|
+
}
|
|
64
|
+
const ktx2Loader = new _KTX2Loader.KTX2Loader();
|
|
65
|
+
ktx2Loader.setTranscoderPath(path);
|
|
66
|
+
ktx2Loader.detectSupport(renderer);
|
|
67
|
+
glTFLoader.setKTX2Loader(ktx2Loader);
|
|
68
|
+
}
|
|
69
|
+
var _default = {
|
|
70
|
+
/** Parses a gltf buffer to an object with threejs structures and applies a y-up to z-up conversion to align with
|
|
71
|
+
* itowns convention. Essentially calls THREE.GltfLoader.parse() for glTF 2.0 files and the legacy threejs parser
|
|
72
|
+
* for gtTF 1.0 files.
|
|
73
|
+
* @param {ArrayBuffer} buffer - the glTF asset to parse, as an ArrayBuffer, JSON string or object.
|
|
74
|
+
* @param {String} path - the base path from which to find subsequent glTF resources such as textures and .bin data files.
|
|
75
|
+
* @return {Promise} - a promise that resolves with an object containing an Object that contains loaded parts:
|
|
76
|
+
* .scene, .scenes, .cameras, .animations, and .asset.
|
|
77
|
+
*/
|
|
78
|
+
parse(buffer, path) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
if (!buffer || !path) {
|
|
81
|
+
reject(new Error('[GLTFParser]: Buffer and path are mandatory to parse a glTF.'));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Apply y-up (gltf convention) to z-up (itowns convention) conversion
|
|
86
|
+
const onload = gltf => {
|
|
87
|
+
gltf.scene.applyMatrix4(matrixChangeUpVectorYtoZ);
|
|
88
|
+
resolve(gltf);
|
|
89
|
+
};
|
|
90
|
+
const onError = e => {
|
|
91
|
+
reject(new Error(`[GLTFParser]: Failed to parse gltf with error: ${e}`));
|
|
92
|
+
};
|
|
93
|
+
const headerView = new DataView(buffer, 0, 20);
|
|
94
|
+
const version = headerView.getUint32(4, true);
|
|
95
|
+
if (version === 1) {
|
|
96
|
+
legacyGLTFLoader.parse(buffer, path, onload, onError);
|
|
97
|
+
} else {
|
|
98
|
+
glTFLoader.parse(buffer, path, onload, onError);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.default = _default;
|
|
@@ -9,6 +9,7 @@ exports.default = void 0;
|
|
|
9
9
|
var THREE = _interopRequireWildcard(require("three"));
|
|
10
10
|
var _B3dmParser = _interopRequireDefault(require("../Parser/B3dmParser"));
|
|
11
11
|
var _PntsParser = _interopRequireDefault(require("../Parser/PntsParser"));
|
|
12
|
+
var _GLTFParser = _interopRequireDefault(require("../Parser/GLTFParser"));
|
|
12
13
|
var _Fetcher = _interopRequireDefault(require("./Fetcher"));
|
|
13
14
|
var _ReferencingLayerProperties = _interopRequireDefault(require("../Layer/ReferencingLayerProperties"));
|
|
14
15
|
var _PointsMaterial = _interopRequireDefault(require("../Renderer/PointsMaterial"));
|
|
@@ -22,7 +23,6 @@ function b3dmToMesh(data, layer, url) {
|
|
|
22
23
|
urlBase,
|
|
23
24
|
overrideMaterials: layer.overrideMaterials,
|
|
24
25
|
doNotPatchMaterial: layer.doNotPatchMaterial,
|
|
25
|
-
opacity: layer.opacity,
|
|
26
26
|
registeredExtensions: layer.registeredExtensions,
|
|
27
27
|
layer
|
|
28
28
|
};
|
|
@@ -36,6 +36,12 @@ function b3dmToMesh(data, layer, url) {
|
|
|
36
36
|
};
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
function gltfToMesh(data, layer, url) {
|
|
40
|
+
const urlBase = THREE.LoaderUtils.extractUrlBase(url);
|
|
41
|
+
return _GLTFParser.default.parse(data, urlBase).then(result => ({
|
|
42
|
+
object3d: result.scene
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
39
45
|
function pntsParse(data, layer) {
|
|
40
46
|
return _PntsParser.default.parse(data, layer.registeredExtensions).then(result => {
|
|
41
47
|
const material = layer.material ? layer.material.clone() : new _PointsMaterial.default({
|
|
@@ -96,10 +102,14 @@ function executeCommand(command) {
|
|
|
96
102
|
};
|
|
97
103
|
if (path) {
|
|
98
104
|
// Check if we have relative or absolute url (with tileset's lopocs for example)
|
|
99
|
-
|
|
105
|
+
let url = path.startsWith('http') ? path : metadata.baseURL + path;
|
|
106
|
+
if (layer.source.isC3DTilesGoogleSource) {
|
|
107
|
+
url = layer.source.getTileUrl(url);
|
|
108
|
+
}
|
|
100
109
|
const supportedFormats = {
|
|
101
110
|
b3dm: b3dmToMesh,
|
|
102
|
-
pnts: pntsParse
|
|
111
|
+
pnts: pntsParse,
|
|
112
|
+
gltf: gltfToMesh
|
|
103
113
|
};
|
|
104
114
|
return _Fetcher.default.arrayBuffer(url, layer.source.networkOptions).then(result => {
|
|
105
115
|
if (result !== undefined) {
|
|
@@ -107,12 +117,16 @@ function executeCommand(command) {
|
|
|
107
117
|
const magic = utf8Decoder.decode(new Uint8Array(result, 0, 4));
|
|
108
118
|
if (magic[0] === '{') {
|
|
109
119
|
result = JSON.parse(utf8Decoder.decode(new Uint8Array(result)));
|
|
110
|
-
|
|
120
|
+
// Another specifics of 3D tiles from Google: tilesets in tilesets are required from the root base
|
|
121
|
+
// url and not from their parent base url
|
|
122
|
+
const newPrefix = layer.source.isC3DTilesGoogleSource ? layer.source.baseUrl : url.slice(0, url.lastIndexOf('/') + 1);
|
|
111
123
|
layer.tileset.extendTileset(result, metadata.tileId, newPrefix, layer.registeredExtensions);
|
|
112
124
|
} else if (magic == 'b3dm') {
|
|
113
125
|
func = supportedFormats.b3dm;
|
|
114
126
|
} else if (magic == 'pnts') {
|
|
115
127
|
func = supportedFormats.pnts;
|
|
128
|
+
} else if (magic == 'glTF') {
|
|
129
|
+
func = supportedFormats.gltf;
|
|
116
130
|
} else {
|
|
117
131
|
return Promise.reject(`Unsupported magic code ${magic}`);
|
|
118
132
|
}
|