ol-cesium
Version:
OpenLayers Cesium integration library
2 lines • 5.2 kB
JavaScript
(()=>{"use strict";var e,t={1511:(e,t,r)=>{function n(e,t,r){const n=t/r;let i;return n>1?(i=[e.width,e.width/n],i[1]>e.height&&(i=[e.height*n,e.height])):(i=[e.height*n,e.height],i[0]>e.width&&(i=[e.width,e.width/n])),{scaling:[i[0]/e.width,i[1]/e.height],width:i[0],height:i[1],offsetX:(e.width-i[0])/2,offsetY:(e.height-i[1])/2}}r.d(t,{pv:()=>a,ZV:()=>n,ss:()=>s});let i=null;class o{constructor(e){this.gl=e;const t=this.initShaderProgram();this.programInfo={program:t,attribLocations:{vertexPosition:e.getAttribLocation(t,"aVertexPosition")},uniformLocations:{uScaling:e.getUniformLocation(t,"uScaling")}},this.positionBuffer=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,this.positionBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),e.STATIC_DRAW)}getVertexShaderSource(){return"\n attribute vec4 aVertexPosition;\n uniform vec2 uScaling;\n void main() {\n gl_Position = vec4(aVertexPosition[0] * uScaling[0], aVertexPosition[1] * uScaling[1], -1.0, 1.0);\n }\n "}getFragmentShaderSource(){return"\n precision highp float;\n void main() {\n gl_FragColor = vec4(.5, .5, .5, .6);\n }\n "}initShaderProgram(){const e=this.gl,t=this.getVertexShaderSource(),r=this.getFragmentShaderSource(),n=o.loadShader(e,e.VERTEX_SHADER,t),i=o.loadShader(e,e.FRAGMENT_SHADER,r),a=e.createProgram();if(e.attachShader(a,n),e.attachShader(a,i),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error(`Unable to initialize the shader program: ${e.getProgramInfoLog(a)}`);return a}drawMask(e){const t=this.gl,r=this.programInfo;t.enable(t.BLEND),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.vertexAttribPointer(r.attribLocations.vertexPosition,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(r.attribLocations.vertexPosition),t.useProgram(r.program),t.enable(t.STENCIL_TEST),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.REPLACE),t.uniform2fv(r.uniformLocations.uScaling,e),t.blendFunc(t.ZERO,t.ONE),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.stencilFunc(t.EQUAL,0,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.uniform2fv(r.uniformLocations.uScaling,[1,1]),t.blendFunc(t.ZERO,t.SRC_ALPHA),t.drawArrays(t.TRIANGLE_STRIP,0,4)}static loadShader(e,t,r){const n=e.createShader(t);if(e.shaderSource(n,r),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(`An error occurred compiling the shaders: ${e.getShaderInfoLog(n)}`);return n}}function a(e,t){const r=e.canvas,n=r.getContext("webgl2")||r.getContext("webgl");if(t){if(!i){const r=new o(n);i=e.postRender.addEventListener((()=>{r.drawMask(t())}))}}else i&&(i(),i=null);e.requestRender()}function s(e,t){return new Promise(((r,n)=>{const i=e.postRender.addEventListener((()=>{i();try{let n;if(t){const r=document.createElement("canvas");r.width=t.width,r.height=t.height,r.getContext("2d").drawImage(e.canvas,t.offsetX,t.offsetY,t.width,t.height,0,0,t.width,t.height),n=r.toDataURL()}else n=e.canvas.toDataURL();r(n)}catch(e){n(e)}}));e.requestRender()}))}},3558:(e,t,r)=>{var n=r(6459),i=r(7811),o=r(9800),a=r(7761),s=r(9529),c=r(6424),h=r(5761),l=r(196);Cesium.Ion.defaultAccessToken=l.x;const d=new h.Z({layers:[new c.Z({source:new s.Z})],controls:(0,a.c)({attributionOptions:{collapsible:!1}}),target:"map",view:new o.ZP({center:(0,i.vs)([25,20],"EPSG:4326","EPSG:3857"),zoom:3})}),u=new n.ZP({map:d}),g=u.getCesiumScene();function f(){const e=document.querySelector("#printValue").value,t=g.canvas,r=Math.min(t.width,t.height);return"portrait"===e?(0,n.ZV)(t,r/4,r/2):(0,n.ZV)(t,r/2,r/4)}Cesium.createWorldTerrainAsync().then((e=>g.terrainProvider=e)),u.setEnabled(!0),document.getElementById("enable").addEventListener("click",(()=>u.setEnabled(!u.getEnabled()))),document.getElementById("resolutionScale").addEventListener("change",(e=>u.setResolutionScale(Number.parseFloat(e.target.value)))),(0,n.pv)(g,(()=>f().scaling)),window.takeScreenshot=async function(){const e=f(),t=await(0,n.ss)(g,e),r=new Image,i=g.canvas;r.src=t,r.width=e.width/(i.width/i.clientWidth),r.height=e.height/(i.height/i.clientHeight),document.body.append(r)}}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var o=r[e]={exports:{}};return t[e].call(o.exports,o,o.exports,n),o.exports}n.m=t,e=[],n.O=(t,r,i,o)=>{if(!r){var a=1/0;for(l=0;l<e.length;l++){for(var[r,i,o]=e[l],s=!0,c=0;c<r.length;c++)(!1&o||a>=o)&&Object.keys(n.O).every((e=>n.O[e](r[c])))?r.splice(c--,1):(s=!1,o<a&&(a=o));if(s){e.splice(l--,1);var h=i();void 0!==h&&(t=h)}}return t}o=o||0;for(var l=e.length;l>0&&e[l-1][2]>o;l--)e[l]=e[l-1];e[l]=[r,i,o]},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.j=740,(()=>{var e={740:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var i,o,[a,s,c]=r,h=0;if(a.some((t=>0!==e[t]))){for(i in s)n.o(s,i)&&(n.m[i]=s[i]);if(c)var l=c(n)}for(t&&t(r);h<a.length;h++)o=a[h],n.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return n.O(l)},r=self.webpackChunkol_cesium=self.webpackChunkol_cesium||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var i=n.O(void 0,[351],(()=>n(3558)));i=n.O(i)})();
//# sourceMappingURL=print.289e72ec54b9adb1646e.js.map