-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KML/GeoJSON polygon onFeatureClick() not called #558
Comments
I looked at this with the current master branch at 80d9497 (0.6.2), and here's my understanding of what's happening (partially thanks to Google Translate). @tenSunFree Please let me know if I got any of this wrong :). SummaryIn Steps to repro
What I expect to seeThe click listener should fire and I should see a Toast that says What I actually seeTapping on the blue polygon has no effect - the listener doesn't fire (see below screenshot). I also noticed that the remote URL used for |
I ended up digging further into this while reviewing PR #380 (PR #380 does not appear to fix this issue). The root problem here seems to be that the Maps API ...as does PolylineOptions.clickable: In However, there isn't an equivalent in This affects GeoJSON polygons too, but the difference being that in app code you can set clickable to true for GeoJSON polygons by setting a GeoJSON polygon style:
...which then gets propagated to Unless I'm missing something, there doesn't seem to be an equivalent way to set clickable to true from app code via Possible solution seems to be adding a boolean clickable attribute to |
I'm also wondering if the hard-coding of
|
I was curious to see if there were any interactions with the KML spec itself here - the closest attribute I can find is BalloonStyle
Regardless of how this should translate to this library, the documentation for this library clearly says that |
I wanted to see where exactly this issue regressed. Looking back at old library versions:
Using Git blame, it looks like the KML click listening in KmlDemoActivity was added as part of the GeoJSON/KML integration in #351. #351 (comment) says:
I tested with the specific PR merge commit (a7a8fcc), but same result as v0.5.0 - tapping on the KML polygon has no effect. So, it appears that KML polygon click listening never actually worked as intended, so we're free to come up with our own solution here. |
Actually, looking more carefully at the original KML/GeoJSON integration PR, it did include the line to hard-code clickable to true for polygons.
...but then this PR allowed setting the clickable attribute via the style, changing the above code to:
...which broke it, because the PolygonOptions defaults clickable to false. So the issue was re-introduced prior to the 0.6.0 release. So, in summary, we effectively have the same issue for both KML/GeoJSON polylines and polygons right now:
...but we're handling each case differently:
|
As discussed in #558, the original intent when combining the KML and GeoJSON renderers was to have GeoJSON and KML lines and polygons clickable by default. However, there was a regression in #454 that unintentionally disabled clicks for KML and GeoJSON polygons when attempting to allow developers to use GeoJSON custom styles to set clickable. I investigated both KML and GeoJSON lines and polygons, and here is the current state of the library: * For KML/GeoJSON polygons - we're currently supporting developer-defined clickable styles for GeoJSON (the change in #454), but that results in a default of not clickable for GeoJSON and KML. And there isn't a way to override the default in KmlLayer. * For KML/GeoJSON lines - we're currently ignoring developer-defined clickable styles and hard-coding the default clickable style to true. This PR solves both problems (default of "not clickable" and supporting developer-defined styles) as follows: * Makes all styles for GeoJSON and KML lines and polygons clickable by default by setting clickable=true in style constructors rather than the renderer. This also allows the developer to set a custom style with clickable=false on GeoJSON lines and polygons (custom programmatic KML styles currently aren't supported by the library). * Make clickable default to true in the Style superclass - this should hopefully avoid a similar issue in any new implementations that extend Style * Normalize the GeoJsonLineStringStyle and GeoJsonPolygonStyle clickable implementations - GeoJsonPolygonStyle was missing code related to the clickable attribute * Add missing <name> attribute to the KML polygon demo file used in the MultiLayerDemoActivity * Add unit tests: * For GeoJSON - test both default and programmatic custom clickable styles for both the style and renderer classes * For KML - test the default style for both the style and renderer classes * Refactor KML and GeoJSON test utility methods used in more than one test class to new Kml/GeoJsonTestUtil classes * Fix GeoJSON polygonStyle.toPolygonOptions().isVisible() test (this previously didn't check PolygonOptions) I've also added TODO statements in the unit tests where we could expand coverage further (i.e., after adding the layers to the map), but that requires additional test instrumentation to have a live GoogleMap object. Fixes #558 Refs: 558
關鍵在於 Renderer 的 addedPolygon.setClickable(polygonOptions.isClickable());
polygonOptions.isClickable() 總是得到false
所以如果想讓 KmlDemoActivity的onFeatureClick 可以被調用
必須修正成 addedPolygon.setClickable(true);
The text was updated successfully, but these errors were encountered: