UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 1.57 kB
import{POI_PIN_DEFAULT_COLOR as _}from"../../../../constants.js";import{createImageCanvas as y}from"./canvases.js";import{getPoiPinLayout as I,getPoiPinShadeColor as O,POI_MARKER_PIN_SHAPE as R,POI_SELECTED_PIN_SHAPE as E}from"./poi-pin-shape.js";const x=.6,p="#ffffff",A="rgba(0, 0, 0, 0.35)";function w(t,i){const n=document.createElement("canvas");n.width=i.canvasWidth,n.height=i.canvasHeight;const o=n.getContext("2d");return o.scale(i.scale,i.scale),{canvas:n,ctx:o,path:new Path2D(t.outline)}}function m(t,i,n){t.shadowColor=A,t.shadowOffsetY=i.shadow.offsetY*n,t.shadowBlur=i.shadow.blur*n}function C(t){t.shadowColor="transparent",t.shadowOffsetY=0,t.shadowBlur=0}function S(t){return t.getContext("2d").getImageData(0,0,t.width,t.height)}export function createPoiPinImage(t,i,n,o){const s=R,l=I(s,i,n),{canvas:e,ctx:a,path:c}=w(s,l),{x:d,y:f}=s.head;if(m(a,s,l.scale),a.fillStyle=p,a.fill(c),C(a),a.beginPath(),a.arc(d,f,s.head.innerRadius,0,2*Math.PI),a.fillStyle=_,a.fillStyle=o,a.fill(),t){const P=2*s.head.innerRadius*x*l.scale,h=y(t,P,P,1),r=h.getContext("2d");r.globalCompositeOperation="source-in",r.fillStyle=p,r.fillRect(0,0,h.width,h.height);const g=h.width/l.scale,u=h.height/l.scale;a.drawImage(h,d-g/2,f-u/2,g,u)}return S(e)}export function createPoiPinheadImage(t,i,n){const o=E,s=I(o,t,i),{canvas:l,ctx:e,path:a}=w(o,s),c=O(n);return m(e,o,s.scale),e.fillStyle=n,e.fill(a),C(e),e.strokeStyle=c,e.lineWidth=o.strokeWidth,e.lineJoin="round",e.stroke(a),e.beginPath(),e.arc(o.head.x,o.head.y,o.head.innerRadius,0,2*Math.PI),e.fillStyle=c,e.fill(),S(l)}