Skip to content

Commit

Permalink
feat(share): add link when sharing points
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Jul 24, 2024
1 parent ee2ca2e commit d39e3e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/js/my-account/my-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ ${landmark.properties.locationName}
Latitude : ${Math.round(landmark.geometry.coordinates[1] * 1e6) / 1e6}
Longitude : ${Math.round(landmark.geometry.coordinates[0] * 1e6) / 1e6}
${landmark.properties.description}
`,
https://cartes-ign.ign.fr?lng=${landmark.geometry.coordinates[0]}&lng=${landmark.geometry.coordinates[1]}&z=15`,
dialogTitle: "Partager mon point de repère",
});
}
Expand Down
22 changes: 19 additions & 3 deletions src/js/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Position {
// ajout des listeners principaux :
shadowContainer.getElementById("positionShare").addEventListener("click", () => {
Share.share({
title: `Partager ${this.header}`,
title: `Partager ${this.#getTrueHeader()}}`,
text: this.shareContent,
dialogTitle: "Partager la position",
});
Expand Down Expand Up @@ -450,7 +450,7 @@ class Position {
}

#setShareContent(latitude, longitude, altitude = "") {
let trueHeader = this.header;
const trueHeader = this.#getTrueHeader();
if (this.header.includes("landmarkSummaryIcon")) {
trueHeader = DomUtils.stringToHTML(this.header.trim()).innerText.trim();
} else if (this.header.includes("divLegendDescription")) {
Expand All @@ -465,10 +465,26 @@ class Position {
Altitude : ${altitude} m`;
}

const zoom = Math.round(this.map.getZoom() * 100) / 100;
this.shareContent = `${trueHeader ? trueHeader : this.header}
${this.name}
Latitude : ${latitude}
Longitude : ${longitude}${altitudeText}`;
Longitude : ${longitude}${altitudeText}
https://cartes-ign.ign.fr?lng=${longitude}&lng=${latitude}&z=${zoom}`;
}

/* Transforme le HTML du header de la position en texte pour le partage */
#getTrueHeader() {
let trueHeader = this.header;
if (this.header.includes("landmarkSummaryIcon")) {
trueHeader = DomUtils.stringToHTML(this.header.trim()).innerText.trim();
} else if (this.header.includes("divLegendDescription")) {
trueHeader = DomUtils.stringToHTML(this.header.trim()).querySelector(".divLegendDescription").innerHTML.trim().replace("<br>", "\n");
}
if (trueHeader.includes("positionSubTitle")) {
trueHeader = trueHeader.trim().replace("<p class=\"positionSubTitle\">", "\n").replace("</p>", "\n");
}
return trueHeader;
}

/**
Expand Down

0 comments on commit d39e3e0

Please sign in to comment.