Skip to content

Commit

Permalink
Display legend from canvas mviewer#836
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Dec 4, 2023
1 parent 78781ca commit 9740cd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 9 additions & 2 deletions demo/addons/print/js/components/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
*/
export const Legend = () => {
const layerDetails = [...document.querySelectorAll(".mv-layer-details")];
const TitleAndLegend = layerDetails.map((detail) => {
const TitleAndLegend = layerDetails.map((detail, i) => {
let legend = detail.querySelector(".mv-legend");
if (legend) {
// legend from WMS
legend = detail.querySelector(".mv-legend").cloneNode();
legend.id = _.uniqueId("print-lgnd-img-");
} else {
// vector legend
let newId = detail.getAttribute("data-layerid");
let canvas = detail.querySelector(".vector-legend");
let canvasToImg = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
legend = `<img class="mv-legend" id="legend-${ newId }" src="${ canvasToImg }" alt="Légende non disponible" onload="mviewer &amp;&amp;" onerror="this.onerror=null;this.src='img/nolegend.png';">`;
}
return `
<div class="print-legend-img">
<p>${detail.getAttribute("data-title")}</p>
${legend.outerHTML}
${legend?.outerHTML || legend}
</div>
`;
});
Expand Down
20 changes: 19 additions & 1 deletion demo/print.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,25 @@
<extension type="component" id="print" path="demo/addons"/>
</extensions>

<themes mini="true" legendmini="false">
<themes mini="true" legendmini="false">
<theme id="lycee" name="Education" collapsed="false" icon="fas fa-book">
<layer id="lycee"
name="Lycées en Bretagne"
type="customlayer"
vectorlegend="true"
url="customlayers/lycee.js"
metadata="https://geobretagne.fr/geonetwork/apps/georchestra/?uuid=99e78163-ce9a-4eee-9ea0-36afc2a53d25"
metadata-csw="https://geobretagne.fr/geonetwork/srv/fre/csw?SERVICE=CSW&amp;VERSION=2.0.2&amp;REQUEST=GetRecordById&amp;elementSetName=full&amp;ID&amp;ID=99e78163-ce9a-4eee-9ea0-36afc2a53d25"
queryable="true"
fields="nom,adresse,photo"
aliases="Nom,Adresse,Photo"
visible="true"
searchable="true"
searchengine="fuse"
fusesearchkeys="nom,adresse"
fusesearchresult="{{nom}} ({{type_etabl}})"
attribution="Région Bretagne" />
</theme>
<theme name="Environnement" collapsed="false" id="environnement" icon="fas fa-leaf">
<layer id="reserve_naturelle_regionale" name="Réserves naturelles régionales" visible="true" tiled="false"
searchable="false" queryable="true" fields="axe" aliases="axe"
Expand Down

0 comments on commit 9740cd9

Please sign in to comment.