Skip to content
Open
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
7 changes: 7 additions & 0 deletions views/shared/css/geolocation-marker.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
button#geolocation_find_location_by_address {
float: none;
}
#geolocation_metadata_select {
width: 80%;
}
#geolocation_metadata_select_label {
font-weight: bold;
margin-right: 5px;
}

div#geolocation {
clear: both;
Expand Down
46 changes: 46 additions & 0 deletions views/shared/map/input-partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
<input type="hidden" name="geolocation[zoom_level]" value="<?php echo $zoom; ?>">
<input type="hidden" name="geolocation[map_type]" value="Leaflet">

<?php
$metadata = [];

if (($item = get_current_record('Item')) instanceof Item) {
$texts = $item->getAllElementTexts();

foreach ($texts as $textRecord) {
$element = $item->getElementById($textRecord->element_id);
// Build a label like "Title: My Item Title" and store it in the metadata array:
$metadata[] = sprintf('%s: %s', $element->name, substr($tmp = $textRecord->text, 0, 40) . (strlen($tmp) > 40 ? '...' : ''));
}

$metadata = array_unique($metadata);
}
?>

<div class="field">
<div id="location_form" class="two columns alpha">
<label for="geolocation_address"><?php echo html_escape($label); ?></label>
Expand All @@ -16,7 +32,22 @@
<input type="text" name="geolocation[address]" id="geolocation_address" value="<?php echo $address; ?>">
<button type="button" name="geolocation_find_location_by_address" id="geolocation_find_location_by_address" data-success-message="<?php echo __('Location found.'); ?>"><?php echo __('Find'); ?></button>
</div>

<div class="two columns alpha">
<label id="geolocation_metadata_select_label" for="geolocation_metadata_select"><?php echo __('Get location from metadata:');?></label>
</div>
<div class="inputs five columns omega">
<select id="geolocation_metadata_select">
<?php foreach ($metadata as $md): ?>
<option value="<?php echo html_escape($md); ?>">
<?php echo html_escape($md); ?>
</option>
<?php endforeach; ?>
</select>
<button type="button" id="geolocation_metadata_load_btn"><?php echo __('Load');?></button>
</div>
</div>

<div id="geolocation-sr-alerts" class="sr-only" aria-live="polite" aria-atomic="true"></div>
<div id="omeka-map-form" class="geolocation-map"></div>

Expand Down Expand Up @@ -57,5 +88,20 @@
jQuery('#geolocation_find_location_by_address').click();
}
});

// Make the metadata load button set the hidden form fields the plugin uses.
jQuery('#geolocation_metadata_load_btn').on('click', function (event) {
event.preventDefault();

// Get the raw selected option text, e.g. "Title: My Awesome Place"
var selected = jQuery('#geolocation_metadata_select').val();
if (!selected) return;

// Split off the part after the first ": "
var parts = selected.split(': ');
var address = parts.slice(1).join(': ');

jQuery('#geolocation_address').val(address).trigger('change');
});
});
</script>