Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/3.1/geothesaurus map fixes #1635

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions collections/tools/mapcoordaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
$wktInputId = array_key_exists("wkt_input_id", $_REQUEST)? htmlspecialchars($_REQUEST["wkt_input_id"]):"footprintwkt";
$outputType= array_key_exists("geoJson", $_REQUEST)?"geoJson":"wkt";

$clManager = new ChecklistAdmin();
$clManager->setClid($clid);

if($formSubmit){
if($formSubmit == 'save'){
$clManager = new ChecklistAdmin();
$clManager->setClid($clid);
$clManager->savePolygon($_POST['footprintwkt']);
$formSubmit = "exit";
}
Expand Down Expand Up @@ -66,7 +65,7 @@
<body style="background-color:#ffffff; display:flex; flex-direction:column;">
<h1 class="page-heading" style="margin-left:5px;">Taxon Map</h1>
<div style="float:right;margin-top:5px;margin-bottom:5px;margin-right:15px;margin-left:5px;">
<button name="closebutton" type="button" onclick="self.close()">
<button name="closebutton" type="button" onclick="saveCoordAid()">
<?php echo isset($LANG['SAVE_N_CLOSE'])? $LANG['SAVE_N_CLOSE'] :'Save and Close'?>
</button>
<?php echo isset($LANG['COORD_AID_HELP_TEXT'])? $LANG['COORD_AID_HELP_TEXT'] :'Click the map to start drawing or select from the shape controls to draw bounds of that shape'?>
Expand Down Expand Up @@ -112,6 +111,12 @@
const wktInputId = "<?= $wktInputId?>";
const polyOutputType = "<?= $outputType ?>";

function saveCoordAid() {
const leaflet_save = document.querySelector(".leaflet-draw-actions li a[title='Save changes']");
if(leaflet_save) leaflet_save.click();
self.close();
}

const setField = (id, v) => {
var elem = opener.document.getElementById(id);
if(elem) {
Expand Down Expand Up @@ -223,6 +228,7 @@ function loadShape(mapMode) {
case "polygon":
if(polyOutputType === "geoJson") {
const geoJsonStr = getField(wktInputId);
if(!geoJsonStr) break;
try {
const geoJson = JSON.parse(geoJsonStr);
return {
Expand Down Expand Up @@ -306,6 +312,8 @@ function leafletInit() {
drawColor: {opacity: 0.85, fillOpacity: 0.55, color: '#000' }
}, setShapeToSearchForm);

map.mapLayer.on("draw:edited", saveCoordAid);

if(formShape) {
map.drawShape(formShape);
}
Expand Down
2 changes: 1 addition & 1 deletion content/lang/geothesaurus/index.fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
$LANG['SEARCH_GEOTHESAURUS'] = 'Rechercher un thésaurus géographique';
$LANG['ADD_TERM_LIST'] = 'Ajouter un terme à la liste';

?>
?>
36 changes: 25 additions & 11 deletions geothesaurus/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,26 @@ function listGeoUnits($arr) {
</style>
<script src="<?php echo $CLIENT_ROOT?>/js/autocomplete-input.js" type="module"></script>
<script type="text/javascript">
function toggleEditor(){
toggle(".editTerm");
toggle(".editFormElem");
toggle("#editButton-div", "block");
toggle("#edit-legend");
toggle("#unitDel-div", "block");
let map = document.getElementById("map_canvas");
if(map) map.style.display = map.style.display === 'none'?'block': 'none';
}
function toggleEditor(){
toggle(".editTerm");
toggle(".editFormElem");
toggle("#editButton-div", "block");
toggle("#edit-legend");
toggle("#unitDel-div", "block");

const edit_form = document.querySelector("#unitEditForm");
const add_form = document.querySelector("#unitAddForm");
if(edit_form) {
edit_form.addEventListener('submit', () => window.unsavedChanges = false);
edit_form.addEventListener('change', () => window.unsavedChanges = true);
}
if(add_form) {
add_form.addEventListener('submit', () => window.unsavedChanges = false);
add_form.addEventListener('change', () => window.unsavedChanges = true);
}
let map = document.getElementById("map_canvas");
if(map) map.style.display = map.style.display === 'none'?'block': 'none';
}

function toggle (target, defaultDisplay = "inline"){
const targetList = document.querySelectorAll(target);
Expand Down Expand Up @@ -169,6 +180,9 @@ function openCoordAid(id="footprintwkt") {

function init() {
try {
window.onbeforeunload = function(e) {
if(window.unsavedChanges) return true;
}
leafletInit();
} catch(e) {
console.log("Leaflet Map failed to load")
Expand Down Expand Up @@ -227,7 +241,7 @@ function navigateGeothesaursSearch() {

<!-- Add Form -->
<div id="addGeoUnit-div" style="clear:both;margin-bottom:10px;display:none">
<form name="unitAddForm" action="<?= $geoThesID? '' : 'index.php' ?>" method="post">
<form id="unitAddForm" name="unitAddForm" action="<?= $geoThesID? '' : 'index.php' ?>" method="post">
<fieldset id="new-fieldset">
<legend> <?= $LANG['ADD_GEO_UNIT'] ?> </legend>
<div class="field-div">
Expand Down Expand Up @@ -331,7 +345,7 @@ function navigateGeothesaursSearch() {
if($geoThesID && $geoUnit) {
?>
<div id="updateGeoUnit-div" style="margin-bottom:10px;">
<form name="unitEditForm" action="index.php<?= $geoThesID? '?geoThesID=' . $geoThesID: '' ?>" method="post">
<form id="unitEditForm" name="unitEditForm" action="index.php<?= $geoThesID? '?geoThesID=' . $geoThesID: '' ?>" method="post">
<fieldset id="edit-fieldset">
<legend><span id="edit-legend"><?= $LANG['EDIT'] ?></span> <?= $LANG['GEO_UNIT'] ?> </legend>
<div style="float:right">
Expand Down