How to make content fit the full screen (Mapbox) - css

I'm using a map api (Mapbox). I'm trying to make the map fit the full screen, but nothing I try seems to work.
I have a wrapper and container for the map. I've tried to different solutions, but I'm still having problems.
Option 1: problem: the map doesn't fit the viewport, instead a scroll bar is added forcing the user to scroll down to view the entire map
jsfiddle #1
Option 2: problem: the map fills the entire viewport, but the bottom portion of the map is cut off (notice the mapbox logo is missing at the bottom)
jsfiddle #2
How can I get the map to fit the view port without being cutoff or adding a scroll bar?
Full code for reference:
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
class Application extends React.Component {
componentDidMount() {
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/light-v9', // stylesheet location
center: [13.392, 52.523], // starting position [lng, lat]
zoom: 9 // starting zoom
});
map.addControl(new mapboxgl.NavigationControl());
}
render() {
return (
<div>
<h2>Hello</h2>
<p>Hi</p>
<div className="map-wrapper">
<div ref={this.mapContainer} id="map"/>
</div>
</div>
)
}
}
ReactDOM.render(<Application/>, document.getElementById('app'));
body, html {
height: 100%;
}
.map-wrapper {
position: fixed;
width: 100%;
height: 100%;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100% !important.
}
<div id="app"></div>

No need for the wrapper. Simply set your height and width to 100vh and 100vw respectively.
#map {
width: 100vw;
height: 100vh;
}

Related

page background color or image is positioning under header

I have a React project and this is how its index-page:
inside div, I have side bar and its main css:
.side-nav {
position: sticky;
top: 0;
left: 0;
height: 100vh;
z-index: 100;
width: calc(3.5vw + 3.5vh);
this is how sidebar,navbar and main page stacked.
const BaseLayout: React.FC<BaseLayoutProps> = (props) => {
const { className, user, navClass = "with-bg", loading, children } = props;
return (
// display:flex will keep sideBar and main, side by side
<div style={{ display: "flex" }}>
<SideBar />
<Header className={navClass} user={user} loading={loading} />
{children}
</div>
);
};
this is main div for Header
.port-navbar.port-default {
width: 100vw;
z-index: 15;
height: calc(3.5vw + 3.5vh);
}
and this is the main div for index-page:
background-color: green;
there is another component under header. I want that component should be under header. In the current structure, I do not understand why index-page does not start right after the header.
Also, I do not understand why I have extra space on the right side of header.
first of all side-nav is not the class name of the header so the styles will not perform on it.
second, you need to use this for the Header component:
position: absolute;
if that didn't work please show some more details and a snippet.

Issue with 100% high Mapbox map when rendering with React

I am rendering a map using Mapboxgl, Bootstrap 4 and React.
I need the map to take 100% of the height of the page and to display in the first column of a two column grid.
However, when using React, the width of the map extends over to 100% of the width of the row - overlapping underneath the 2nd column.
The best thing would be to check my examples on jsfidle to understand what I mean.
Map correctly showing (when using pure HTML and no React)
https://jsfiddle.net/apphancer/jhxy5c63/
Map showing width issue (when using React)
https://jsfiddle.net/apphancer/9g71ovn6/
In order to have the 100% height working I am using this CSS:
.map-wrapper {
position: fixed;
width: 100%;
height: 100%;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
}
I suspect this might have something to do with how the map gets rendered with React as the problem does not happen when using the pure HTML solution.
Is anyone able to point in the right direction?
HTML
<div id="app"></div>
CSS
body, html {
height: 100%;
}
#app, .row, .col-9 {
height: 100%;
}
.col-3 {
background-color: rgba(0, 0, 0, 0.5);
border: 1px solid red;
}
.map-wrapper {
position: fixed;
width: 100%;
height: 100%;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
}
JS
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA';
class Application extends React.Component {
componentDidMount() {
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/light-v9', // stylesheet location
center: [13.392, 52.523], // starting position [lng, lat]
zoom: 9 // starting zoom
});
map.addControl(new mapboxgl.NavigationControl());
map.resize(); // tried with this to see if it would help
}
render() {
return (
<div className="row no-gutters">
<div className="col-9">
<div className="map-wrapper">
<div ref={el => this.mapContainer = el} id="map"/>
</div>
</div>
<div className="col-3">
2 of 2
</div>
</div>
)
}
}
ReactDOM.render(<Application/>, document.getElementById('app'));
If you use position fixed with 100% width in wrapper, it will cover all width. But if you set position to relative, it will cover just remaining width.
.map-wrapper {
position: relative;
width: 100%;
height: 100%;
}
This worked in your react-jsfiddle. Please try.
If you are using position fixed in your project you can cover whole area so for that you have 2 solution
1st solution
give 75% width to the #map so it will behave like col-9 and no need to give position: absolute;
#map {
width: 75%;
height: 100%;
}
2nd Solution
give it relative position to the parent of your element so it cant leave it area, for that you can change position: fixed to position: relative
.map-wrapper {
position: relative;
width: 100%;
height: 100%;
}
both solution is good solution but i prefer 2nd solution, from my side.
const [viewport, setViewport] = useState({
width: '100%',
height: 'calc(100vh - 162px)', // 162px is size height of all elements on top of map
latitude: 0,
longitude: 0,
zoom: 12,
bearing: 0,
pitch: 0,
transitionDuration: 2000,
transitionInterpolator: new FlyToInterpolator(),
});
I migrated to React 18, and updated a bunch of dependencies, included the map library.
The only thing that resolved my problem was this. It has a tic, when the map resizes, but it's a start.
useEffect(() => {
map.on("load", () => map.resize());
}, [])

How to center modal with transition on material ui and make it responsive?

I trying to use modal with transition using Material UI and have problem to centering it and also make it responsive or center in small size screen (mobile).
Modal can be centered and looks good on small size if not using transition, but if i add a transition, modal can't be centered or responsive.
This is the code modal without transition link.
Works good with large or small screen size.
This is the code modal with transition link.
I tried to change the value of top & left but still can't get centered at the large and small screen size :
function getModalStyle() {
const top = 25;
const left = 25;
return {
top: `${top}%`,
left: `${left}%`,
transform: `translate(-${top}%, -${left}%)`,
};
}
Can anyone help me?
By default the modal creates a parent container that uses flex, so in order to center you can comment your left: property that it is set to your modal,
return {
top: `${top}%`,
margin:'auto'
// left: `${left}%`,
// transform: `translate(-${top}%, -${left}%)`,
};
and in your modal container you can align items with this
<Modal
...
style={{display:'flex',alignItems:'center',justifyContent:'center'}}
>
https://stackblitz.com/edit/react-1ny5g7?file=demo.js
This works for me:
function getModalStyle() {
return {
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
};
}
This worked for me:
{
width: '100%',
maxWidth: '100vw',
maxHeight: '100%',
position: 'fixed',
top: '50%',
left: '0',
transform: 'translate(0, -50%)',
overflowY: 'auto'
}

Resizing jwplayer7 iframe when orientation changes

I'm having an issue with JWP7, when the player is loading on portrait or landscape mode it stretches out to the full window as expected, but when changing the device orientation while the player is still playing, the player doesn't scaling the the new window dimensions.
Code example:
$('.player').height($window.height());
jwplayer("myElement").setup({
file: "somevideo.mp4",
width: windows.width,
height: windows.height,
});
<div id="player">
<div class="close_btn fadeIn"><img src="/img/close.png" width="50" /> </div>
<div id='player_frame'>
<iframe id=""video_iframe></iframe>
</div>
</div>
#media screen and (orientation:portrait) {
.video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
}
#media screen and (orientation:landscape) {
.video_iframe
{
height: 100vh;
width: 100vw;
}
}
Any suggestions?
Thank you all in advance.
There appear to be a few problems with your code:
1) The iframe ID attribute is not correctly enclosed with quotes:
<iframe id=""video_iframe></iframe>
should be:
<iframe id="video_iframe"></iframe>
2) Your CSS selectors are targeting using the class notation rather than by the element ID:
.video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
should be:
#video_iframe
{
height: 100vh;
overflow: hidden;
width: 100vw;
}
3) The "player" wrapper is likely to be restricting the height of the generated video player as the following is only being run once, and is probably setting an explicit pixel value:
$('#player').height($window.height());
Try removing this line.
I managed to fixed it with jQuery mobile - orientation change event:
$(window).bind( 'orientationchange', function(e){
var windowHeight = $(window).height() + 'px';
var windowWidth = $(window).width() + 'px';
if(window.orientation == 0) // Portrait
{
$("#myElement").height(windowHeight);
$("#myElement").width(windowWidth);
}
else // Landscape
{
$("#myElement").height(windowHeight);
$("#myElement").width(windowWidth);
}
});

zooming content inside div using transform scale property

I am trying to zoom contents of div(same behavior as browser zoom). After searching a lot I found css 3 transform scale property will full fill this requirement.
The content is zooming when I increase the scale size but I am losing the contents of the div. overflow: hidden also didn't help.
var currentZoom = 1.0;
$(document).ready(function () {
$('#btn_ZoomIn').click(
function () {
currentZoom = currentZoom+0.04;
var scaleString = "scale("+currentZoom+")";
$('#divName').css("transform", scaleString);
})
$('#btn_ZoomOut').click(
function () {
//var scaleString = "scale("+currentZoom -= .1+")";
currentZoom = currentZoom-0.04;
var scaleString = "scale("+currentZoom+")";
$('#divName').css("transform", scaleString);
})
});
Js fiddle link: http://jsfiddle.net/chaitut715/k4WsB/
Add a container around #divName:
<div class="wrapper">
<div id="divName">
<img src="https://www.google.co.in/intl/en_ALL/images/srpr/logo11w.png"></img>
</div>
</div>
And set overflow: hidden; on the new container:
.wrapper {
overflow: hidden; /* 'auto' would probably be better */
width: 500px;
}
Working demo

Resources