Repairing the Left-sided Popup Leaflet

Can someone help me with fixing the positioning of the Popup to the left of the map? Currently, it does not stay aligned to the left edge when moving the map.

I tried using position: fixed in my styling, and while everything looks good when zooming, it breaks when the map is moved. Here is the code for my Map component:

<MapContainer zoom={this.state.zoom} center={center} zoomControl={false}>
                    <TileLayer
                        attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                        url={"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}
                    />


                    {this.state.geoJsonIsVisibleAll[0].geoJsonIsVisible &&
                        <ChuyGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[1].geoJsonIsVisible &&
                        <TalasGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[2].geoJsonIsVisible &&
                        <OshGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[3].geoJsonIsVisible &&
                        <BatkenGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[4].geoJsonIsVisible &&
                        <JalalAbadGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[5].geoJsonIsVisible &&
                        <NarynGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                    {this.state.geoJsonIsVisibleAll[6].geoJsonIsVisible &&
                        <IssykKolGeoJsonLayer url="kyrgyzstanPlaces.json" cluster={false}/>
                    }
                </MapContainer>

And here is the code for the popup:

<Marker
    key={f.properties.id}
    position={f.geometry.coordinate.reverse()}
>
<Popup
    maxWidth={250}
    maxHeight={650}
    closeButton={true}
    className={'popup-fixed'}
    autoPan={false}>
    <div className="popup-info">
    <p><span>Name: </span>{f.properties.name}</p>
    <p><span>Location: </span>{f.properties.location}</p>
    <p><span>Description: </span>{f.properties.description}</p>
    </div>
    </Popup>
    </Marker>

Here are the styles I am using:

.leaflet-container {
  height: 70vh;
  width: 60vw;
  position: absolute;
  right: 20%;
  top: 15%;
}

.popup-fixed {
  position: fixed;
  top: 0;
  left: 1% !important;
  transform: none !important;
  margin: 0;
  border-radius: 0;
}

Image showing the problem:

Answer №1

Consider using a modal div instead of a popup for a more user-friendly experience. You have the option to customize the inner HTML content within the modal div. Alternatively, if you prefer using popups, you can create an additional map pane and attach the popup to that specific pane.

var newPane = map.createPane('custom', document.getElementById('mapid'));

var customPopup = L.popup({
    pane: 'custom', 
    className: 'popup-custom',
    autoPan: false,
})

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

Aligning text in a vertical progress bar using absolute positioning

Currently, I am trying to create a health bar-like element but I am facing difficulties in centering the text within it. Despite exhausting all my options, the text is either off-center when its length changes or extends beyond the borders of the bar. Her ...

Show JSON array items

My php file (history.php) generates a JSON object $i=1; $q=mysql_query("select * from participants where phone='".mysql_real_escape_string($_GET['phone'])."' limit 10"); while($rs=mysql_fetch_array($q)){ $response[$i] = $rs[&ap ...

The collapsible section expands upon loading the page

Trying to implement Disqus as a plugin on my test webpage, I created a collapsible section with a "Show comments" button. The idea was to hide the plugin by default and reveal it only when users click on "Show comments". Despite using the w3schools example ...

Utilizing jQuery to display labels only for selected checkboxes while concealing the ones that are not checked

I currently have the following setup: <style>.selectit{display:none;}</style> <div id="foo"> <label class="selectit"> <input type="checkbox" name="one" id="one" checked> One </label> <label class="selectit"> <i ...

Adjust the stroke and fill color of an SVG upon hovering over it

I have a unique SVG image with an intricate stroke around it that matches the color of a filled icon. Positioned on a black background within the image, you can view my example here: https://jsfiddle.net/o48629qs/ The challenge I am facing involves changi ...

Styling <Link> component with styled-components: A step-by-step guide

Utilizing the Link component from @material-ui/core/Link in my TypeScript code was initially successful: <Link href="#" variant="body2"> Forgot? </Link> However, I am exploring the transition to styled-components located in a separate file. ...

Transforming jQuery Object into a String after making an AJAX request

If I were to submit a form with some text in the value of user_input, let's say "I am free," through AJAX, and it comes back to me as a string. Once it becomes an Object, how could I convert it back into a string format? Thanks, <!DOCTYPE HTML> ...

Ways to substitute the $(document).ready function?

I'm facing a problem and struggling to find a solution. Here is the JavaScript script that's causing me trouble: $(function () { $.ajaxSetup({ cache: false }); var timer = window.setTimeout(function () { $(".alert").fadeTo(10 ...

Is it possible to extract the body from the post request using req.body.item?

After working with Express, I learned how to extract body data from a post request. Most examples showed that using req.body.item should retrieve the desired value for tasks like inserting into a table. However, in my case, I found that I couldn't ac ...

Ways to identify when a React child element is overflowing

tl;dr How can I create a component that hides overflow and toggles views with a button? For example, the user can initially see tabs 1, 2, and 3 while tabs 4, 5, and 6 are hidden. Clicking a button will hide tabs 1, 2, and 3, and show tabs 4, 5, and 6 with ...

How can you transform a variable into an HTML element using Angular?

Currently, I am working on parsing a JSON file that contains information about various articles. The structure of the JSON file is as follows: { "articles": [ { "id": 1, "title": "<h1>How to install Atom</h1>" }, { ...

Hide/Show overflow causing a disruption in my perspective

I am puzzled as to why my paragraph is not starting on a new line despite the overflow property set on the previous element. Take a look at my plunker, adjust the overflow property in line 11 to hidden and it will display correctly. When set to visible, i ...

When was Chrome first updated to include timezone offset support for Intl.DateTimeFormat()?

My experience with Chromium 121 has been positive using the Intl.DateTimeFormat as shown below: new Intl.DateTimeFormat('en', { dateStyle: 'long', timeStyle: 'long', timeZone: '+0500', }).format ...

Guide on incorporating Bootstrap JS into HTML5 reusable web elements

RESOLVED: the solution is in a comment TL;DR: Issues triggering Bootstrap's JS, likely due to incorrect import of JS scripts I've been working on integrating Bootstrap with my custom reusable web components across all pages. Specifically, I&apo ...

When node.js v6.11.2 is installed on Windows 7, it does not include the correct npm version

When trying to install node.js v6.11.2 on my Windows 7 computer, I am encountering an issue where it is installing the incorrect version of npm alongside it. Even after downloading the installer directly from node.js' website which claims that 6.11.2 ...

Issue with Angular ng-model not functioning as expected within ng-repeat block

Encountering an issue when trying to bind Json data into ng-model within ng-repeat. html : <div ng-controller="Ctrl"> <div> <table> <th> <td>add</td> <td>ed ...

What is the proper way to write the code for this form?

I am exploring alternatives to using the html TABLE tag and struggling to create the desired layout. I have attached a screenshot showing my table design. How can I achieve the same layout using divs or spans while still maintaining vertical alignment of t ...

JavaScript code to access values from a JSON object

{ "4": { "structure": "Archaeological Museum", "boxes": [{ "id": "5", "name": "Ground Cassa DEMO" }] }, "5": { "structure": ...

Obtain an Instance of a Class Using a Decorator

Delving deep into the world of decorators, I stumbled upon some fascinating ideas for incorporating them into my reflux implementation. My concept involves tagging a store's class method with an action, so that whenever that action is triggered, it au ...

Having trouble establishing a connection with the deployed express API

I am experiencing an issue with my API deployed on Heroku. Whenever I try to access it either from my localhost or my deployed frontend, I am receiving a fail status and the following details in the headers: Request URL: my-url Request Method: POST Status ...