The attached patch removes the limitation to use the Client Location Origin Geofield Proximity Source only as option with an exposed proximity filter. With this patch applied the Geofield Proximity filter would work on the User location since the first View load.

Comments

itamair created an issue. See original summary.

itamair’s picture

StatusFileSize
new644 bytes
StuartL’s picture

Hi itamair,

Using this patch in combination with the patch found here (https://www.drupal.org/project/geofield/issues/3014737) is not working for me. There is no option to use the client location as the origin that I can find when adding using the proximity plugin as a field or sort criteria.

Thanks,
Stuart

StuartL’s picture

My apologies - I now understand that the filter must be added, but not exposed.

itamair’s picture

StatusFileSize
new1.15 KB

A better and final patch on this (additionally hides the option to show the Client Origin coordinates in the not Exposed Form settings), going to be committed into dev ...

  • itamair committed b233155 on 8.x-1.x
    Issue #3065776 by itamair: Client Location Origin Geofield Proximity...
itamair’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

StuartL’s picture

Hi Itamair,

A question for you: I have the proximity filter in place using client location origin and am displaying the distance from the user as a field. Caching for the view is disabled.

When I load the page on different devices in different locations, the same content and distances display as if the client's location isn't being queried. Clearing the site's cache does not cause the view to update what's displayed, so it seems the location used the first time the view is loaded is what is used indefinitely.

Using Geofield 8.x-1.6, and Drupal 8.7.2. Any suggestions?

Thanks,
Stuart

itamair’s picture

Status: Closed (fixed) » Needs work

hI #StuartL ... this is a nice point.
Actually I better investigated this and the Client Location Origin Geofield Proximity Source indeed cannot work the way you would like, if not exposed.
Why? ... because at the moment, if not exposed, it will keep using the same Origin coordinates set once the Filter is set in the backend,
so it means would work as the View Filter Administrator Location.
Why? ... because the not exposed filter (that is set server side) cannot have any clue of the Client location at runtime.
The only way (at the moment) for the application to be notified of the Client Location is the HTML Geolocation API, that runs client side.
To accomplish what you ask you should better find a way to add to your Geofield View path an argument that is dinamically populated by the User Location (you should find a way to do this) and that accomplishes the Geofield Proximity Contextual Filter pattern that has been recently added to the Geofield module (@see here: https://www.drupal.org/project/geofield/issues/3031761#comment-13289841).

This said, I think that the use of the Client Location Origin Geofield Proximity Source out of the exposed filter context doesn't have any practical sense ... and the #2 patch should be rolled back (Client Location Origin Geofield Proximity Source only as exposed filter).

I am going to rollback that soon, if any other proper reason and practical use arise for it ...

StuartL’s picture

Thank you for the details. I will investigate that solution shortly.

As a quick fix, I have exposed the filter, hidden it via CSS, and then used JS to submit the form once the page content has finished loading.

itamair’s picture

yeah ... @StuartL, that sounds (and might reveal) a very practical and effective approach.
It would be nice to give a contribute to the community if you could also share you solution, acting also as a "Maker", and not only as a "Taker" ... (cit. Balancing Makers and Takers to scale and sustain Open Source).
It might become an option or an add-on of the Client Location Origin Geofield Proximity Source itself ...

StuartL’s picture

Glad to hear it could prove useful. I don't have any experience contributing to modules, so will have to read up on how that's done. I am still a novice in that regard. I will include my code here hoping that it is useful and may try my hand at contributing a commit at some point.

The below code waits until the page has finished loading, then waits another second (just in case), and then clicks the exposed form submit/apply button (you'll need to insert your own selector). Use CSS to apply 'display: none;' to the exposed for container or proximity exposed filter element.

Only tested in latest versions of Firefox, Edge and Chrome on Windows 10 so far.

$( window ).on('load', function() {
      function sleep (time) {
        return new Promise((resolve) => setTimeout(resolve, time));
      }

      sleep(1000).then(() => {
          $('#your-block-id #exposed-form-submit-button-id').trigger('click');
      });
});

  • itamair committed 6455660 on 8.x-1.x
    Revert "Issue #3065776 by itamair: Client Location Origin Geofield...
itamair’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.