-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinput-partial.php
More file actions
69 lines (62 loc) · 2.89 KB
/
Copy pathinput-partial.php
File metadata and controls
69 lines (62 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
$center = js_escape($center);
$options = $this->geolocationMapOptions($options);
?>
<input type="hidden" name="geolocation[latitude]" value="<?php echo $lat; ?>">
<input type="hidden" name="geolocation[longitude]" value="<?php echo $lng; ?>">
<input type="hidden" name="geolocation[zoom_level]" value="<?php echo $zoom; ?>">
<input type="hidden" name="geolocation[map_type]" value="Leaflet">
<div class="field">
<div id="location_form" class="two columns alpha">
<label for="geolocation_address"><?php echo html_escape($label); ?></label>
</div>
<div class="inputs five columns omega">
<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>
<div id="geolocation-sr-alerts" class="sr-only" aria-live="polite" aria-atomic="true"></div>
<div id="omeka-map-form" class="geolocation-map"></div>
<?php
echo js_tag('geocoder');
$geocoder = json_encode(get_option('geolocation_geocoder'));
?>
<script type="text/javascript">
var omekaGeolocationForm = new OmekaMapForm('omeka-map-form', <?php echo $center; ?>, <?php echo $options; ?>);
var geocoder = new OmekaGeocoder(<?php echo $geocoder; ?>);
jQuery(document).on('omeka:tabselected', function () {
omekaGeolocationForm.resize();
});
jQuery(document).ready(function () {
// Make the Find By Address button lookup the geocode of an address and add a marker.
jQuery('#geolocation_find_location_by_address').on('click', function (event) {
event.preventDefault();
var address = jQuery('#geolocation_address').val();
var successMessage = jQuery(this).data('successMessage');
// If no address is entered, alert the user instead of throwing an error later.
if (!address) {
alert('Please enter an address.');
jQuery('#geolocation_address').focus();
return;
}
geocoder.geocode(address).then(function (coords) {
var marker = omekaGeolocationForm.setMarker(L.latLng(coords));
if (marker === false) {
jQuery('#geolocation_address').val('');
jQuery('#geolocation_address').focus();
} else {
jQuery('#geolocation-sr-alerts').text(successMessage + ' ' + address);
}
}, function () {
alert('Error: "' + address + '" was not found!');
});
});
// Make the return key in the geolocation address input box click the button to find the address.
jQuery('#geolocation_address').on('keydown', function (event) {
if (event.which == 13) {
event.preventDefault();
jQuery('#geolocation_find_location_by_address').click();
}
});
});
</script>