New home › Forums › Pro Add-on › General queries › change zoom level of marker
- This topic has 57 replies, 4 voices, and was last updated 2 years, 3 months ago by Dylan.
-
AuthorPosts
-
February 1, 2017 at 1:30 pm #23799amandsimMember
Hi,
I would like to be able to change the zoom level when I click one of the markers. Currently it’s to close and I need it to show more area.
Is it possible to do that? I don’t mind modifying the code if necessary.
Thanks!
February 2, 2017 at 7:54 am #23814DylanModeratorHi there,
Thank you so much for getting in touch with us.
Are you referring to the zoom level set when you click on a marker listing below the map?
If so, yes it is possible to change the zoom level within the code.
If you are however talking about the zoom level when a marker is clicked within the map, we do not set the zoom level by default. Meaning there may be something else going on with the map causing it to zoom. If this is the case, please send me a link to your map so that I can run a few tests from my side?
February 2, 2017 at 7:59 am #23815amandsimMemberHi dylan,
Yes, what i’m trying to do is to change the zoom level when a marker is clicked from the marker listing.
Could you please let me know which code should i modify and how to change the zoom level?
Thanks!
February 3, 2017 at 7:35 am #23831DylanModeratorHi there,
Not a problem at all. Please follow the steps below to make this change:
1. Open the core.js file (wp-google-maps-pro/js/core.js) and look for the following segment of code:
if (click_from_list) { MYMAP[map_id].map.panTo(marker.position); MYMAP[map_id].map.setZoom(13); } click_from_list = false;
2. There will be more than on instance of the code above (the second instance will be relatively close to the first and should be easy to fine) – I would suggest looking at lines 2756 to 2779 Approx.
3. Within all instances of this code, you will need to alter the following line of code:MYMAP[map_id].map.setZoom(13);
Where
13
is the zoom level
4. Once this is done, remember to save the file.I hope this helps?
September 21, 2017 at 12:27 pm #30701fadilla.wahyudiMemberHi Dylan.
I’ve tried changing the zoom level to 20 on both of them but nothing changed.
- This reply was modified 6 years ago by fadilla.wahyudi.
September 21, 2017 at 2:08 pm #30716fadilla.wahyudiMember[quote quote=30701]Hi Dylan.
I’ve tried changing the zoom level to 20 on both of them but nothing changed.
[/quote]
** Sorry, but it somehow worked now. Thank you!
September 25, 2017 at 8:47 am #30752DylanModeratorThis reply has been marked as private.October 17, 2017 at 2:11 pm #31308aforshawMemberHi – I have exactly the same problem, but clicking on a marker (as opposed to one from the list below the map) will not zoom in and pan.
Where do I need to change in order to zoom the map when clicking on a marker? (Please note that I do not mean clicking on the carousel entries below the map). Clicking on a marker usually opens the info-window, so I’m guessing it should be modified somewhere there.. but I don’t know where that is.
Many thanks
- This reply was modified 5 years, 11 months ago by aforshaw.
October 18, 2017 at 3:58 pm #31356DylanModeratorHi there,
Thank you so much for getting in touch.
Unfortunately marker clicks do not trigger a zoom event currently.
However this could be achieved by making some code changes if you are open to this?
October 18, 2017 at 4:05 pm #31359aforshawMemberAbsolutely yes – I don’t mind modifying the code 🙂 Please point me in the right direction and I’ll make the changes.
Many thanks
October 20, 2017 at 3:53 pm #31459DylanModeratorHi there,
Thank you so much for your time on this one.
You will need to edit the core.js file of the plugin (wp-content/plugins/wp-google-maps-pro/js/core.js), and find the “wpgmza_open_marker_func” function within the file.
Once you have found this function, please find all instances of the following segment of code:
if (click_from_list) { MYMAP[map_id].map.panTo(marker.position); MYMAP[map_id].map.setZoom(13); }
There should be 2 instances of this code, which should be replaced with this instead:
if (click_from_list) { MYMAP[map_id].map.panTo(marker.position); } MYMAP[map_id].map.setZoom(13);
These code changes can be made via FTP, or alternatively this could also be made from within the WordPress code editor.
This should zoom in on the marker regardless of whether it is clicked within the map or the marker listing.
I hope this helps? 🙂
October 20, 2017 at 5:09 pm #31462aforshawMemberHi Dylan,
Thanks for that. I’ve made the changes but also needed it to pan to center the marker once clicked before zooming in, so I’ve changed it to:
if (click_from_list) {
MYMAP[map_id].map.panTo(marker.position);
MYMAP[map_id].map.setZoom(18);
} else { // if clicked on a marker
MYMAP[map_id].map.panTo(marker.position);
MYMAP[map_id].map.setZoom(18);
}I’ll be using different zoom levels eventually hence the duplication of zooms but this works.
Thanks again,
Anthony
October 24, 2017 at 8:42 am #31508DylanModeratorHi Anthony,
So glad to hear the code helped in some way, and thank you so much for sharing your solution with us!
Is there anything else I can assist you with? 🙂
January 29, 2020 at 6:56 pm #57615verewhittomeParticipantHey! I’m trying to achieve the same thing as Anthony. That is, I want the map to zoom in when an in-map marker is clicked. I tried following the instructions mentioned above but I couldn’t seem to find the relevant code snippet:
if (click_from_list) { MYMAP[map_id].map.panTo(marker.position); MYMAP[map_id].map.setZoom(13); }
in wp-content/plugins/wp-google-maps-pro/js/core.js
Has the code changed since?
Thanks,
VereJanuary 30, 2020 at 10:44 am #57636DylanModeratorHi Vere,
Thank you for getting in touch, we do appreciate your time.
Depending on which major version of the Pro version you are making use of, the code may need to change slightly from the original solution you have found.
This is due to recent changes we have made to our core code to allow for external custom functionality to be developed. It also allows us to scale the system better in the future.
Would you be open to sharing a link to your map with me so that I can confirm the core codebase and provide you with a new snippet?
-
AuthorPosts
- You must be logged in to reply to this topic.