Trouble arises when the Leaflet js Map is unable to properly adjust to the dimensions of a

Hello, I am currently facing an issue while trying to insert a Leaflet JS map into a placeholder div. The problem I am encountering is that the map seems to be overflowing out of the designated center square area. Can anyone explain why this might be happening?


html, body {
    height: 100%;
}

.outer {
    border: 1px solid black;
    height: 100%;
    width: 50%;
}

.map_panel {
    margin-left: 25%;
    margin-top: 25%;
    border: 1px solid black;
    height: 40%;
    width: 40%;
}


<head>
    <meta charset="UTF-8">
    <title>mapform</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="outer">
        <div class="map_panel">
            <div id="embed_map"></div>
        </div>
    </div>

    
    <script>
        //Creating map options
        var mapOptions = {
            center: [35.7101, 139.8107],
            zoom: 15
        }

        //Creating a map object
        var map = new L.map('embed_map', mapOptions);
        L.marker(mapOptions.center).addTo(map);
        
        //Creating a Layer object
        var layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');

        //Adding layer to the map
        map.addLayer(layer);
    </script>
    
    
</body>
</html>

Answer №1

It appears that there may be an issue with the code you posted not producing the same result as shown in the image. Please ensure that all necessary styles, such as map and outer, are defined properly. It seems like the style being referred to is actually output2.

I have tested the code myself and did not encounter any overlapping issues with the map. However, if overlapping does occur in certain situations, adding overflow: hidden; can help to hide any content outside of the designated area.

You can view the code and test it out yourself here: https://jsfiddle.net/falkedesign/duag5qfc/

Additionally, make sure that the necessary Leaflet css styles have been added to your project.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to align rotated text within the Bootstrap 4 Grid system

I have been working on a grid layout using Bootstrap 4's Grid system, and I am aiming for a design similar to the following: https://i.sstatic.net/sU7kV.png While I have made significant progress and got almost 100% of it complete, I am facing an is ...

How can I get an object returned from a Mongoose find method in NodeJS?

I am currently working on developing a node.js API with Mongoose, However, for a specific task, I need to retrieve the object as a variable from my find operation. This is what I have so far: exports.get_info = function(_id) { Session.findById(_id, f ...

Adjust the IFRAME height to 100% scaling

I am having trouble setting the height of my iframe to 100%. Despite my efforts, I can't seem to make it work properly. What I really want is for the iframe to display without any scroll bars every time and have a height of 100%. See below for the co ...

Avoiding Memory Leaks and Managing JS Heap Size While Polling Large Amounts of Data Every 5 Seconds with Vuex

I'm currently working on a Vue application that utilizes Vuex for state management. Within this application, I have several store modules set up at the root level. Periodically, every 5 seconds, I retrieve a large amount of data and update the store s ...

Create logic statements based on the information obtained from parsing an XML document

Looking for some assistance with writing this code. Any help is appreciated! Let's say I am extracting data from an XML file like the following: function parseXml(xml) { $(xml).find("ITEM").each(function() { var foo = $("bar", this).text ...

PLupload does not support Flash runtime in Internet Explorer 8

I am facing a dilemma with a basic JavaScript function placed within the $(function() { ... }); block. var uploader = new plupload.Uploader({ runtimes: 'html5,flash,silverlight', browse_button: 'pickfiles', c ...

How can Angular incorporate JSON array values into the current scope?

I am currently working on pushing JSON data into the scope to add to a list without reloading the page. I am using the Ionic framework and infinite scroll feature. Can someone please point out what I am doing wrong and help me figure out how to append new ...

Using Angular directives to dynamically add event listeners with the ng-repeat directive

I am currently working with a directive that includes event listeners for an element in the link function. For example: ... link: function(scope, element) { // this gives us the native JS object var el = element[0]; el.draggable = true; ...

Tips for setting background colors as a prop for Material UI cards in React JS

Currently utilizing the Material UI next framework to construct a wrapper for the card component. This customized wrapper allows for personalization of the component. I have successfully extended the component so that the title and image within the card ca ...

Codeigniter session unexpectedly ends after AJAX call completes successfully

Currently, I am utilizing the CodeIgniter framework on a Heroku server with an AWS database. In my AJAX success function, I have a window.location.reload(); call which ends up destroying the session and redirecting to the login page. Is there a way to prev ...

Exploring the applications of the `this` keyword within a jQuery-based JavaScript object

Recently, there has been a challenge in creating a JavaScript object with the specific structure outlined below: function colorDiv(div){ this.div=div; this.div.bind("click",this.changeColor) this.changeColor(){ this.div.css(" ...

Allow access only to authorized staff members in Django

So I'm working on this Django code and I want to display a button only if the user is either a super user or staff. I've tried using is_superuser and is_staff but it's not working for me. {% if request.user == post.user %} <div class=&qu ...

Loading screen while all files and audio are being loaded

My JavaScript code is responsible for displaying and playing audio on my website. Unfortunately, the load time of the page is quite slow. To address this issue, I decided to follow a tutorial on installing a preloader, which can be found at . Although I ...

Error: The function init is missing and cannot be found when the HTML button is clicked

In my attempt to utilize a function within HTML, I am encountering difficulty implementing it in an Angular TS component. An error message indicates that the code must be correct as it is being provided by TensorFlow. The snippet of code in question is as ...

Tips for resolving issues with the navigation menu not appearing on the website

For more information, please visit the webpage at I am facing an issue where the dropdown menu does not show up when hovering on the Services page. The dropdown menu was created in WordPress using wp_nav_menu. There are 5 pages, including a Services page ...

come together for the purpose of creating an insert statement in MySQL syntax

Good day! I have a query about creating a MySQL syntax statement for inserting data into two tables. Here is the structure of the tables: I am able to insert `userid` and `picturepath`, but I'm unsure how to also insert into the `flag` column in the ...

Finding the intersection of arrays in JavaScript

What is an efficient way to find the intersection of multiple arrays in JavaScript? For example: arr1 = [1,2,3,4,5]; arr2 = [1,2,3,4]; arr3 = [4]; arr4 = [4,5]; Intersection: [4] ...

show JSON data following an Ajax request (Asynchronous)

I'm encountering an "undefined" error while attempting to render raw JSON using JSON.parse (result). function decodeVin(result) { var vinArray = JSON.parse(result); var results = "<h4>Vehicle Information Result:</h4>"; results += "Year: ...

Choose every fourth row in the table

Is there a way to alternate the background colors of selected groups of 4 rows in a table? I want to make one group red and the next group blue. Any suggestions or ideas on how to achieve this? <table> <tr style="background-color: red;"> ...

Ordering tables according to the last column using jQuery

Despite trying various solutions provided in other discussions, I have been unable to get the table to display in descending order based on the Weight Score column. Here is a reference of the table: <table align="center" border="1px" cellpadding="5" id ...