UNPKG

trifid-plugin-yasgui

Version:
2 lines (1 loc) 3.47 kB
YasguiMapPluginDefaultOptions||(YasguiMapPluginDefaultOptions={});YasguiMapPluginDefaultOptions.mapKind||(YasguiMapPluginDefaultOptions.mapKind="default");var h=class{priority=10;hideFromSelection=!1;wktLabels=new Map;constructor(s){this.yasr=s}getResults(){if(this.wktLabels.clear(),!this.yasr||!this.yasr.results||!this.yasr.results.json||!this.yasr.results.json.results||!this.yasr.results.json.results.bindings)return[];let s=this.yasr.results.json.results.bindings;if(s.length<1)return[];let c=[];return s.forEach((r,p)=>{if(!r)return null;let n=Object.entries(r).filter(e=>{let t=e[1];return!(!t||!t.type||t.type!=="literal"||!t.datatype||t.datatype!=="http://www.opengis.net/ont/geosparql#wktLiteral"||!t.value)});if(n.length===0)return null;n.forEach(e=>{let t=e[0],f=`results-map-wkt-${t}-${p}`,d=e[1];if(c.push({id:f,wkt:d.value}),!r||!r[`${t}Label`])return;let i=r[`${t}Label`];if(!i||i.type!=="literal")return;let o=i.value;this.wktLabels.set(f,o)})}),c}async draw(){await import("./deps-TAHCJHMH.js");let{Style:s,Stroke:c,Fill:r}=await import("./style-L367F676.js"),p=this.getResults(),n=document.createElement("ol-map");n.style.height="500px",n.style.width="100%";let e=document.createElement("div");e.style.position="absolute",e.style.bottom="0px",e.style.left="0px",e.style.background="rgb(255, 255, 255)",e.style.padding="8px",e.style.display="none",e.style.zIndex="10",e.style.borderTopRightRadius="5px",e.style.borderTop="1px solid #000",e.style.borderRight="1px solid #000",n.appendChild(e);let t;YasguiMapPluginDefaultOptions?.mapKind==="swisstopo"?(t=document.createElement("swisstopo-wmts"),t.setAttribute("layer-name","ch.swisstopo.pixelkarte-farbe"),t.setAttribute("z-index","-1")):t=document.createElement("ol-layer-openstreetmap");let f=new s({fill:new r({color:"rgba(255, 68, 28, 0.6)"}),stroke:new c({color:"#ff441c",width:5})}),d=new s({fill:new r({color:"rgba(255, 68, 28, 0.2)"}),stroke:new c({color:"#ff441c",width:5})}),i=document.createElement("ol-layer-vector"),o=document.createElement("ol-layer-wkt"),y=document.createElement("ol-select");y.style=d,t.appendChild(i),t.appendChild(o),t.appendChild(y),n.appendChild(t),this.yasr.resultsEl.textContent="",this.yasr.resultsEl.appendChild(n),y.addEventListener("feature-selected",l=>{if(!l?.detail?.feature)return;let a=l.detail.feature;a.setStyle(f);let u=a.getId();if(!this.wktLabels.has(u))return;let w=this.wktLabels.get(u);w?(e.innerText=w,e.style.display="block"):e.style.display="none"}),y.addEventListener("feature-unselected",l=>{if(!l?.detail?.feature)return;l.detail.feature.setStyle(d),e.style.display="none"}),p.filter(l=>l.wkt.includes("POINT")).forEach(l=>{let a=document.createElement("ol-marker-icon"),u=l.wkt.match(/POINT *\(([^)]+)\)/)[1].split(" ");u.length===2&&(a.setAttribute("lat",u[1]),a.setAttribute("lon",u[0]),a.setAttribute("src","/yasgui-public/marker-icon.svg"),i.appendChild(a))}),o.featureData=p,o.featureStyle=d,setTimeout(()=>{o.fit()},200)}canHandleResults(){return this.getResults().length>0}getIcon(){let s=document.createElement("div");return s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-map-pin"><path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/><circle cx="12" cy="10" r="3"/></svg>',s}};Yasr.registerPlugin("Map",h);