Leaflet OpenStreetMap Changes View based on window size

32 Views Asked by At

I am using Leaflet and OpenStreetMap to generate an interactive map. The map generates fine and you are able to interact with the map. The issue I am encountering is if the user has a large screen size and is navigated to the page, the view of the map changes. Refer to the screenshot below:

browser size:1228px enter image description here

browser size: 2510px enter image description here

The following is the code:

    var mymap = L.map('map').setView([34.3155072, -118.2096810], 8.6);
    L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a>       contributors',
       maxZoom: 16
    }).addTo(mymap);

I have attempted to adjust the coordinates to show the same location for both views but that has not worked.

0

There are 0 best solutions below