New home › Forums › Pro Add-on › Disable polygon hover
Tagged: polygon
- This topic has 11 replies, 4 voices, and was last updated 7 months ago by Matthew.
-
AuthorPosts
-
March 31, 2020 at 2:54 pm #58507ronsuParticipant
Hi,
I was wondering if there was a way to disable polygon hover? I can change polygon fill opacity and stroke opacity in general but on hover I can change only fill opacity. Now if I hover on the polygon, the stroke (which opacity is set to 0) pops on full opacity. Can I change the stroke’s hover opacity or better, disable hover completely?
April 1, 2020 at 3:16 pm #58522DylanModeratorHi there,
Thank you so much for getting in touch, we do appreciate your time.
Unfortunately, this is not supported by default. However, I do believe we should be able to provide you with a bit of custom JavaScript to achieve the required result.
Would you be open to sharing a link to your website (map page) so that I can ensure the script I create works well with your set up?
I look forward to hearing back from you.
April 1, 2020 at 3:37 pm #58523ronsuParticipantThis reply has been marked as private.April 2, 2020 at 9:06 am #58526DylanModeratorHi there,
Thank you for confirming your website link.
Please add the following custom JavaScript to your site:
jQuery(function($){ $(window).load(function(){ if(typeof WPGM_Path_Polygon !== 'undefined'){ for(var i in WPGM_Path_Polygon){ google.maps.event.clearListeners(WPGM_Path_Polygon[i]); } } }); });
I believe this will remove the hover functionality from the polygons.
This can be added under Maps > Settings -> Advanced -> Within the Custom JavaScript block.
I hope this helps?
April 2, 2020 at 9:35 am #58527ronsuParticipantThis works perfectly! Thank you!
One less crucial thing: is it possible to change hover cursor? Now it’s pointer and because it’s not clickable, it would be nice to change it to default.April 2, 2020 at 10:04 am #58529DylanModeratorHi there,
Fantastic news, so glad to hear that helped!
Yes, this can be achieved by changing the following section of the snippet I shared previously:
for(var i in WPGM_Path_Polygon){ google.maps.event.clearListeners(WPGM_Path_Polygon[i]); }
To this instead:
for(var i in WPGM_Path_Polygon){ google.maps.event.clearListeners(WPGM_Path_Polygon[i]); WPGM_Path_Polygon[i].setOptions({clickable: false}); }
This will force the map engine to ignore the original click handlers which are assigned to the polygons, which disables the cursor change.
I hope this helps?
April 2, 2020 at 10:07 am #58530ronsuParticipantPerfect! Thank you again for the fast answer!
April 2, 2020 at 10:08 am #58531DylanModeratorOnly a pleasure, glad to hear that helped! 🙂
Have a great day further.
February 22, 2023 at 1:09 am #76467FoomagooParticipantI’m looking to achieve the same thing but this piece of Javascript has no affect on my polygons. jQuery(window).load is not a valid event on jQuery > version 3. I replaced that call with
jQuery(window).on("load", function {
But that throws an error that WPGM_Path_Polygon is undefined if I call
console.log(WPGM_Path_Polygon);
And without it nothing happens because WPGM_Path_Polygon is undefined.
February 22, 2023 at 5:01 pm #76475FoomagooParticipantSo I decided to try a setTimeout call to see if the function was just being called to early. After 3 seconds the WPGM_Path_Polygon array is set but it has a length of 0. So I’m not sure where to go from here to remove the polygon hover events.
February 23, 2023 at 12:43 am #76476FoomagooParticipantAfter doing more searching I was able to find the solution I was after in this topic https://www.wpgmaps.com/forums/topic/polygon-mouse-hover-2/.
February 24, 2023 at 10:43 am #76484MatthewModeratorHi @Foomagoo,
Thank you for getting in touch with us, we do appreciate your time.
We are happy that you managed to find the solution in one of our other threads.
Should you ever require any further assistance, I am more than happy to help.
Have a fantastic day further!
Kindest Regards,
Matthew -
AuthorPosts
- You must be logged in to reply to this topic.