Skip to content

Commit

Permalink
update geocoder to reset to NULL when X clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed Aug 21, 2024
1 parent c6fbdb2 commit 3fabaf3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
Binary file removed .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mapboxapi
Type: Package
Title: R Interface to 'Mapbox' Web Services
Date: 2024-05-14
Version: 0.6.1
Date: 2024-08-21
Version: 0.6.2
Authors@R:
c(person(given = "Kyle", family = "Walker", email = "[email protected]",
role = c("aut", "cre")),
Expand Down
11 changes: 5 additions & 6 deletions inst/www/mapboxGeocoderBinding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var mapboxGeocoderBinding = new Shiny.InputBinding();

$.extend(mapboxGeocoderBinding, {
find: function(scope) {
return $(scope).find(".mapbox-geocoder");
Expand All @@ -8,21 +7,22 @@ $.extend(mapboxGeocoderBinding, {
var accessToken = $(el).data("access-token");
var options = $(el).data("options");
mapboxgl.accessToken = accessToken;

var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl,
...options
});

geocoder.addTo(el);

// Capture the result event and send data to Shiny
geocoder.on('result', function(e) {
$(el).data("geocoder-result", e.result); // Store the result in jQuery data
$(el).trigger('change');
});

// Add event listener for the 'clear' event
geocoder.on('clear', function() {
$(el).data("geocoder-result", null); // Reset the result to null
$(el).trigger('change');
});
$(el).data("geocoder", geocoder);
},
getValue: function(el) {
Expand All @@ -37,5 +37,4 @@ $.extend(mapboxGeocoderBinding, {
$(el).off(".mapboxGeocoderBinding");
}
});

Shiny.inputBindings.register(mapboxGeocoderBinding);
Binary file removed tools/.DS_Store
Binary file not shown.
Binary file removed tools/readme/.DS_Store
Binary file not shown.

0 comments on commit 3fabaf3

Please sign in to comment.