Fix centre and zoom level of map

New home Forums Basic Version Troubleshooting Fix centre and zoom level of map

This topic contains 9 replies, has 2 voices, and was last updated by  RoyH 1 month, 2 weeks ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #52083

    RoyH
    Member

    Hi there,

    I understand from working with the plugin, and reading the support forum, that you set the centre and zoom level of the map every time you save it.

    Is there a way that I can set the centre and zoom level of the map so that it does not change? So that every time I open the map it is centred and zoomed to fit the area I want to cover on the screen?

    I would like to be able to move pins around and scroll around the map, but when I save it, the centre and zoom stays as originally defined

    I have attached a screenshot, the only area I am interested in is inside the blue boundary.

    Many thanks,

    RoyH

    Attachments:
    You must be logged in to view attached files.
    #52087

    Hi there,

    Thanks for getting in touch.

    Yes, this can be achieved by going to Maps > Settings and disabling the zoom and scrolling controls and features for the map. This will mean that in the frontend, the users will not be able to move or zoom the map in or out.

    Please do let me know if this helps.

    Thank you.

    Kind regards,
    Dylan

    #52088

    RoyH
    Member

    Thanks for your prompt response, Dylan. I did have a look at that setting, but it doesn’t really do what I want.

    I do want front-end users to be able to move and zoom around the map, but the initial view we want to present is always going to be the same, but every time I edit a portion of the map, it changes the centre point and zoom settings, and I am finding it difficult trying to line up the back-end map accurately every time before I save it.

    Is there a way I can make the centre point and zoom level effectively ‘read only’ and not change when the rest of the map is edited?

    Thanks again,

    RoyH

    #52099

    Hi there,

    Thanks for the response and sorry for the delay over the weekend and for the misunderstanding on my side.

    This is not possible out of the box, however, this can be achieved with some custom JS. To add Custom JS to the dashboard, you can install the Simple CSS and JS plugin which lets you add custom JavaScript and set whether to load it in the backend or frontend.

    The code to add is:

    jQuery(window).load(function(){
    var map = WPGMZA.maps[0];
    if (typeof map !== 'undefined') {
    var latLng = new google.maps.LatLng(26, 28);
    map.panTo(latLng);
    map.setZoom(4);
    }
    });

    You can set your custom coordinates and zoom as the above zoom and lat and long are just examples.

    Alternatively, you can add this JS to the frontend by going to Maps > Settings > Advanced > Custom JS and then it will pan/zoom to this location when the map loads, so then it will not matter where the map position is saved as it will always start on your location set in the JS code above.

    I hope this helps and please do let me know if you are able to add it correctly.

    Thank you.

    Best regards,
    Dylan

    #52503

    RoyH
    Member

    Hi Dylan,

    Thank you! It all seems to be working perfectly. I could not get the code to work on the back-end, but it worked brilliantly on the front-end through Maps > Settings > Advanced > Custom JS.

    Thanks again,

    RoyH

    #52504

    Hi Roy,

    Thanks for letting me know and I am glad to hear that helped.

    Regarding adding the code to the backend, just to confirm, did you download the Simple CSS and JS plugin and created a JS script set to ‘Admin’? If so, please let me know and I will debug further to determine why this is occurring.

    Thank you for your time.

    Best regards,
    Dylan

    #52538

    RoyH
    Member

    Hi Dylan,

    I just tried the backend fix again, and this time it worked. For the life of me, I can’t tell you what I did differently – the co-ordinates you gave me are in the middle of the Egyptian desert, by the way – but it now resets the map back to our preferred view on saving.

    Many thanks, no doubt I’ll be back with more questions fairly soon.

    RoyH

    #52548

    Hi Roy,

    Thanks for letting me know and I am glad to hear that you were able to get it working correctly.

    Just to confirm, is everything working correctly now?

    Thanks for your time.

    Best regards,
    Dylan

    #52632

    Hi Roy,

    Thanks for the update and that is great to hear.

    Is it working correctly as you wanted it to now and is there anything else at all that I can help with? If there is, please let me know and I would be more than happy to help.

    Best regards,
    Dylan

    #52835

    RoyH
    Member

    Hi Dylan,

    I tried to leave you a response last week but it has not appeared on this page. Anyway – yes that issue is addressed, thank you for your help.

    I have changed one thing, however: I was messing around with the GET variables, and discovered that if I linked to a particular marker, when the map loaded, it zoomed out and centred as per the script, rather than on the marker I wanted to feature via the GET variables.

    So, what I have done is to remove the script from the front end page header, and I have created two map pages: one with the script embedded in the body of the html; and another without the script embedded.

    That way I can launch the map at full-size on the page with the embedded script, but if I want to open the map zoomed in and centred on a marker, I use the page without the script. The two pages are virtually indistinguishable apart from the URL, and that solution seems to work fine.

    Thanks again,

    RoyH

    #52845

    Hi Roy,

    Thanks for letting me know and apologies for not previously taking that into account but am really glad to hear that you were able to find a solution.

    Thanks again for your time and please let me know if there is ever anything else I can assist you with.

    Best regards,
    Dylan

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.