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?
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | clear-cluster-markers-2878799-12.patch | 613 bytes | ericgsmith |
Comments
Comment #2
christianadamski commentedHey @Dionsj,
is this a duplicate of #2872266: mapMarkers not sufficiently removed ? If yes, simply using latest -dev should fix it.
Comment #3
dionsjHello @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.
Comment #4
dionsjSome 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).
Comment #5
christianadamski commentedComment #6
christianadamski commentedHey @Dionsj,
still relevant with current release? If yes, could you export a view which triggers this?
Comment #7
dionsj@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.
Comment #8
dionsjI 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:
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.
Comment #9
christianadamski commentedComment #10
dionsjHas 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.
Comment #11
ericgsmith commented@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
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,
Comment #12
ericgsmith commentedPatch attached
Comment #13
ericgsmith commentedComment #14
dionsjThe patch completely fixed the issue I was having, on both sites where I encountered it.
Comment #15
dwwI'm also hitting the same bug, and patch #12 fixes it splendidly. The code looks clean and reasonable. RTBC.
Thanks!
-Derek
Comment #16
christianadamski commentedI 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.
Comment #17
christianadamski commentedComment #20
christianadamski commentedThanks!