问题
I have a google map where I load geometry data* to the data layer using addGeoJson. Everything works fine until i tried to bind an event on polygons in order to change opactiy settings.
*I retreive city borders from OSM to draw polygons, I think my json object is well formatted, I took Google as reference : https://storage.googleapis.com/mapsdevsite/json/google.json
As soon as I click on a polygon (any of them), it seems to duplicates my polygons anywhere around however the opacity change correctly.
I used this as exemple for my code : https://developers.google.com/maps/documentation/javascript/examples/layer-data-dynamic
Here is my JSFiddle : https://jsfiddle.net/fmarrot/k7b57egw/ (the data can be seen in console.log(Config.polygon) (line 10)
Indeed if i comment line 29 to 31, no problem at all, but I can't change polygon opacity anymore.
map.data.addListener('click', function(event) {
event.feature.setProperty('opacity', (event.feature.getProperty('opacity')===0.5?0.9:0.5));
});
Any idea of what I am doing wrong ?
Thanks for your help !
回答1:
Ok I think I figured out, it seems to be a Chrome bug (my version 58.0.3029.110 (64-bit)), I've just tested it with Firefox, Edge and IE with no problems > no polygons duplications on polygon click and works like a charm !
I am gonna wait for a chrome fix or if someone have a solution I would appreciate any suggestions !
UPDATE
As stated in Google issue tracker, the issue was fixed in Chrome 60. The corresponding bug was marked as Fixed on August 9, 2017.
https://buganizer.corp.google.com/issues/38211242
来源:https://stackoverflow.com/questions/44570595/google-map-data-layer-click-on-polygon-and-change-opacity-chrome-bug