Skip to content

Update oms.coffee to work with AdvancedMarkerElement#181

Open
ericberman wants to merge 1 commit into
jawj:masterfrom
ericberman:issue-180-work-with-advancedmarkerelement
Open

Update oms.coffee to work with AdvancedMarkerElement#181
ericberman wants to merge 1 commit into
jawj:masterfrom
ericberman:issue-180-work-with-advancedmarkerelement

Conversation

@ericberman
Copy link
Copy Markdown

Changes:

  • Google didn't provide an equivalent for getVisible in AdvancedMarkerElement; I'm not quite sure how this was intended to be used - whether it was asking "is this marker's location within the bounds of the map" or "is this marker status visible vs. invisible". So I created a new method IsVisibleMarker that returns true if the marker has a non-null map (map == null is how you remove a marker from the map) AND is within the bounds of that maps latitude/longitude boundaries. This works for my purposes, I hope it is the correct definition
  • changed getPosition/setPosition to .position property
  • changed getZIndex/setZIndex to .zIndex property
  • commented out the line "(return i if o is obj) for o, i in arr" in p.arrIndexOf. If I'm understanding Coffee correctly (I'm not!!) this never gets called if arr.indexOf is defined, so this seems to work...

Probably worth noting a few other things I had to do to migrate to AdvancedMarkerElement:

  • No longer use defered script include, so I no longer get a callback when it is loaded, so the old code of waiting for both oms and maps to load no longer works. E.g., now I load googlemaps with (g => { var h, a, k, p = "The Google Maps JavaScript API", c = "google", l = "importLibrary", q = "ib", m = document, b = window; b = b[c] || (b[c] = {}); var d = b.maps || (b.maps = {}), r = new Set, e = new URLSearchParams, u = () => h || (h = new Promise(async (f, n) => { await (a = m.createElement("script")); e.set("libraries", [...r] + ""); for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]); e.set("callback", c + ".maps." + q); a.src = https://maps.${c}apis.com/maps/api/js? + e; d[q] = f; a.onerror = () => h = n(Error(p + " could not load.")); a.nonce = m.querySelector("script[nonce]")?.nonce || ""; m.head.append(a) })); d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n)) })({
    key: "...",
    v: "weekly",
    // Use the 'v' parameter to indicate the version to use (weekly, beta, alpha, etc.).
    // Add other bootstrap parameters as needed, using camel case.
    });

So now I need to create the overlappingmarkerspiderfier in oogle.maps.event.addListenerOnce(this.gmap, 'idle', function () { ...}

Changes:
 * Google didn't provide an equivalent for getVisible in AdvancedMarkerElement; I'm not quite sure how this was intended to be used - whether it was asking "is this marker's location within the bounds of the map" or "is this marker status visible vs. invisible".  So I created a new method IsVisibleMarker that returns true if the marker has a non-null map (map == null is how you remove a marker from the map) AND is within the bounds of that maps latitude/longitude boundaries.  This works for my purposes, I hope it is the correct definition
 * changed getPosition/setPosition to .position property
 * changed getZIndex/setZIndex to .zIndex property
 * commented out the line "(return i if o is obj) for o, i in arr" in p.arrIndexOf.  If I'm understanding Coffee correctly (I'm not!!) this never gets called if arr.indexOf is defined, so this seems to work...

Probably worth noting a few other things I had to do to migrate to AdvancedMarkerElement:
 * No longer use defered script include, so I no longer get a callback when it is loaded, so the old code of waiting for both oms and maps to load no longer works.    E.g., now I load googlemaps with        (g => { var h, a, k, p = "The Google Maps JavaScript API", c = "google", l = "importLibrary", q = "__ib__", m = document, b = window; b = b[c] || (b[c] = {}); var d = b.maps || (b.maps = {}), r = new Set, e = new URLSearchParams, u = () => h || (h = new Promise(async (f, n) => { await (a = m.createElement("script")); e.set("libraries", [...r] + ""); for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]); e.set("callback", c + ".maps." + q); a.src = `https://maps.${c}apis.com/maps/api/js?` + e; d[q] = f; a.onerror = () => h = n(Error(p + " could not load.")); a.nonce = m.querySelector("script[nonce]")?.nonce || ""; m.head.append(a) })); d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n)) })({
           key: "...",
           v: "weekly",
           // Use the 'v' parameter to indicate the version to use (weekly, beta, alpha, etc.).
           // Add other bootstrap parameters as needed, using camel case.
       });

So now I need to create the  overlappingmarkerspiderfier in oogle.maps.event.addListenerOnce(this.gmap, 'idle', function () { ...}
Copy link
Copy Markdown

@seche seche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works with the AdvancedMarker Element

@waledagne
Copy link
Copy Markdown

@seche Will this be merged anytime soon :)

Comment thread lib/oms.coffee
Comment on lines -249 to +257
continue unless m1.getMap()? and m1.getVisible() # marker not visible: ignore
continue unless m1.getMap()? and @isVisibleMarker(m1) # marker not visible: ignore
m1Data = mData[i1]
continue if m1Data.willSpiderfy # true in the case that we've assessed an earlier marker that was near this one
for m2, i2 in @markers
continue if i2 is i1 # markers cannot be near themselves: ignore
continue unless m2.getMap()? and m2.getVisible() # marker not visible: ignore
continue unless m2.getMap()? and @isVisibleMarker(m2) # marker not visible: ignore
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up, AdvancedMarkerElement does not have getMap() anymore and this will result in a TypeError: m1.getMap() is not a function

AME does have map instead, I've replaced in my copy m1.getMap() with m1.map and it seems it works fine. (Same for m2.getMap() -> m2.map)

https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElement

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super - is there action required on my part for this to be merged, inclusive of the getMap() => map change?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a maintainer of OverlappingMarkerSpiderfier, just a dev that needed this plugin too and used it a bit more extensive and uncovered the issues mentioned in my review.

We've been using your changes combined with mine since I've posted this code proposal in our production, we didn't encounter any other issues since so I believe you can add my changes to your Pull Request.

Sorry for the late reply.

@JD1609
Copy link
Copy Markdown

JD1609 commented Feb 19, 2025

Hey @ericberman, while reviewing your PR, I'd suggest the following code changes:

👉 Code Suggestion for #181

after this changes works fine

You can also review and apply these suggestions locally on your machine.

Learn more about GitKraken Code Suggest

Code Suggest liberates your code reviews from GitHub's restrictive, comment-only feedback style. As simple as suggesting changes in a Google-doc, provide real code suggestions from where you code, e.g. your IDE, and on anything in your project — not just on the lines of code changed in the PR.

Join your team on GitKraken to speed up PR review.

@ericberman
Copy link
Copy Markdown
Author

Hey @ericberman, while reviewing your PR, I'd suggest the following code changes:

👉 Code Suggestion for #181

I don't have access to that gitkraken suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants