First off, let me explain how I have everything configured:

I have 3 different content types, that each share the same geolocation field, for use in views.

I have a views page that is configured as follows (I only include any changes from the views page default):

  • Format:
    • Format: Geolocation Google Maps API - CommonMap
    • Settings:
      • Geolocation Source Field: Content: Location
      • Title Source Field: Content: Title
  • Fields:
    • Content: Title (Just the node title)
    • Content: Location (The geolocation field)
  • Filter Criteria:
    • Content: Publishing status (= Yes)
    • Content: Content type (exposed)
      • Content types: Here I selected only the 3 types I know have the geolocation field.
      • Allow multiple selections: TRUE
      • Limit list to selected items: TRUE
  • Path: /map
  • User pager: Display all items | All items

This works fine, when I submit the exposed filters on the views page (/map) it correctly displays the right markers for the selected options.

The problem:

However, if I change the view to use AJAX, it keeps the original markers, and just puts the markers it gets from the AJAX call, on top of the existing markers, duplicating many of them as the default view shows all markers.

How can I make it clear the existing markers when it places new via AJAX?

CommentFileSizeAuthor
#12 clear-cluster-markers-2878799-12.patch613 bytesericgsmith

Comments

Dionsj created an issue. See original summary.

christianadamski’s picture

Status: Active » Postponed (maintainer needs more info)

Hey @Dionsj,

is this a duplicate of #2872266: mapMarkers not sufficiently removed ? If yes, simply using latest -dev should fix it.

dionsj’s picture

Hello @ChristianAdamski,

I am using 8.x-1.x-dev (installed via composer), which I needed due to some patch fixes for custom markers that the stable version didn't have (having trouble finding the issue that had the patches, but I simply updated to -dev instead of applying the patches).

Also, my issue doesn't just double them, it keeps adding them every time an AJAX call is made that returns a result.
Neither does it update the marker clusters, instead it duplicates it (so if you initially had a cluster of 3, after one AJAX submission you have 2 clusters of 3 each, at the exact same location), I only noticed this as the semi-transparent parts of the marker icon got much less transparent.

I have also tried this on a clean Drupal instance with only the modules enabled that were needed for the map to work, and the same problem presented itself there.

dionsj’s picture

Some additional information:
Setting the option to show raw locations under the map format settings, it correctly updates the locations, but it seems the map doesn't properly clear the old markers (making it related to #2872266: mapMarkers not sufficiently removed, as you mentioned).

christianadamski’s picture

Status: Postponed (maintainer needs more info) » Active
christianadamski’s picture

Status: Active » Postponed (maintainer needs more info)

Hey @Dionsj,

still relevant with current release? If yes, could you export a view which triggers this?

dionsj’s picture

@ChristianAdamski I'm working on a new site that will need similar functionality, if I encounter the same problem I will throw you an exported view.

dionsj’s picture

I can confirm that I still get duplicated markers.
Exported view config: https://pastebin.com/jb9y1277
(It has some additional fields in it apart form the location and title, you can remove those)

Steps to reproduce:

  1. Create several nodes of the content type for the map
  2. Use the maps proximity search to limit your search to only a few markers
  3. Zoom out until clustering is triggered (this sometimes never happens, though might not be relevant to this issue)
  4. Reset your search by clearing the proximity search
  5. Zoom out until clustering is triggered again
  6. The clustering marker is now darker, due to it being dublicated, same happens with regular markers but is most obvious for cluster markers, submit the proximity search several times to make it even more obvious

I hope this helps.

Running Geolocation 8.x-1.x-dev and Geocoder 8.x-2.x-dev downloaded and installed a few minutes prior to making this comment.

christianadamski’s picture

Status: Postponed (maintainer needs more info) » Active
dionsj’s picture

Has there been any update to this? I'm still experiencing the issue, I wouldn't mind trying to solve it myself but have no idea where to start looking.

ericgsmith’s picture

@Dionsj - I think what is possibly happening is that the markers are cleared, but you still have cluster settings on the map object. This means the clusters are still visible, and when you zoom the markers get re drawn as they are still present in the maps config.

To fix, we can add the following to Drupal.geolocation.removeMapMarker function

    if (typeof map.markerClusterer !== "undefined" && typeof map.markerClusterer.clearMarkers === "function") {
      map.markerClusterer.clearMarkers();
    }

I can quickly whip up a patch - another option would be to add another method so that this can be called independently - but I can't think of any context where we would want to clear the markers and keep the cluster markers,

ericgsmith’s picture

StatusFileSize
new613 bytes

Patch attached

ericgsmith’s picture

Status: Active » Needs review
dionsj’s picture

The patch completely fixed the issue I was having, on both sites where I encountered it.

dww’s picture

Title: Submitting exposed views filter via ajax dublicates markers. » Submitting exposed views filter via AJAX duplicates markers
Status: Needs review » Reviewed & tested by the community

I'm also hitting the same bug, and patch #12 fixes it splendidly. The code looks clean and reasonable. RTBC.

Thanks!
-Derek

christianadamski’s picture

I need to add a "clearCallback" to 8.x-2.x to make it work there. Will add to 8.x-1.x after that.

@ericgsmith: Thanks for debugging this so far.

christianadamski’s picture

Title: Submitting exposed views filter via AJAX duplicates markers » MarkerClusterer: Submitting exposed views filter via AJAX duplicates markers

  • ChristianAdamski committed 3de007d on 8.x-2.x
    Issue #2878799 by ericgsmith, ChristianAdamski: MarkerClusterer:...

christianadamski’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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