question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map page getting scrolled,Even when map is only 50% height of the page

See original GitHub issue

My component page

import { Component } from 'preact';
import {style} from './style';
import Map, { GoogleApiWrapper, Marker, InfoWindow } from 'google-maps-react';

class MapContainer extends Component {
  constructor(props) {

    super(props);
    this.state = {
      showingInfoWindow: false,
      activeMarker: {},
      selectedPlace: {},
    }


    this.onMarkerClick = this.onMarkerClick.bind(this);
    this.onMapClicked = this.onMapClicked.bind(this);
  }

  onMarkerClick = (props, marker, e) => {
    this.setState({
      selectedPlace: props,
      activeMarker: marker,
      showingInfoWindow: true
    });
  };
  onMouseoverMarker =(props, marker, e)=> {
    this.setState({
      selectedPlace: props,
      activeMarker: marker,
      showingInfoWindow: true
    });
  };

  onMapClicked = (props) => {
    if (this.state.showingInfoWindow) {
      this.setState({
        showingInfoWindow: true,
        activeMarker: null
      })
    }
  };

  render() {
    return (

      <Map
        google={this.props.google}
        onClick={this.onMapClicked}
        style={{width:'50%', height: '50%',position: 'relative'}}
        zoom={11}
        center={{
          lat: 9.924071,
          lng: 76.358376,
        }}>
        <Marker
          onClick={this.onMarkerClick}
          onMouseover={this.onMouseoverMarker}
          name={'ARAM '}
          position={{lat: 89.900005, lng: 96.384455}}
        />
        <Marker
          onClick={this.onMarkerClick}
          onMouseover={this.onMouseoverMarker}
          name={'ARAM'}
          position={{lat: 90.949685, lng: 96.344408}}
        />

        <InfoWindow
          marker={this.state.activeMarker}
          visible={this.state.showingInfoWindow}>
          <h1>
            {this.state.selectedPlace.name}
          </h1>
        </InfoWindow>
      </Map>
    )
  };
}

export default GoogleApiWrapper({
  apiKey: 'AIzaooBZKs1IZMk46f8n8sVv6-ZlWi-KvZ5W6xE',
})(MapContainer)

My app.js

`import { h, Component } from 'preact';
import { Router } from 'preact-router';
import Header from './header';
import Nav from './nav';
import Home from '../routes/home';
import Rewards from '../routes/rewards';
import More from '../routes/more';
import Location from '../routes/location';
import Toast from '../lib/toast';
// import Home from 'async!./home';
// import Profile from 'async!./profile';
export default class App extends Component {
	/** Gets fired when the route changes.
	 *	@param {Object} event		"change" event from [preact-router](http://git.io/preact-router)
	 *	@param {string} event.url	The newly routed URL
	 */
	handleRoute = e => {
		this.currentUrl = e.url;
	};
	componentDidMount() {
		if (typeof window != "undefined" &&
			"serviceWorker" in navigator) {
			navigator.serviceWorker.register('./sw.js').then(() => {
					console.log('sw registered in app');
				});
		}
		if (typeof window != "undefined") {
			window.addEventListener('online', this.onlineMode);
			window.addEventListener('offline', this.offlineMode);
		}
	}
	render() {
		return (
			<div id="app">
				<Header />
				<div id="content">
					<Router onChange={this.handleRoute}>
						<Home path="/" />
						<Rewards path="/rewards" />
						<Location path="/location" id="Location" />
						<More path="/more" />
						</Router>
				</div>
				<div id="toast"></div>
			</div>
		);
	}
}

and i am using the map component in this page

import { h, Component } from 'preact';
import style from './style';

import GoogleApiWrapper from '../../components/maps';

export default class Location extends Component {

render () {

    return (

      <GoogleApiWrapper />
      

		);
  }
}

sir,My Location page is scollable,even when no full content is available,…when map component is removed its working fine…where i might be going wrong

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
lukapehardacommented, Nov 23, 2018

You can override container styles and fix this without commenting out the code.

<Map ... containerStyle={{ width: '100%', height: '300px', position: 'relative' }} ... </Map>

0reactions
rawphpcommented, Dec 22, 2019

Same here. Adding containerStyle the map is not visible

Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm trying to make google map stay on right side of page when ...
When I scroll down I want the map to stay visible. I am using flex to make the columns. I've tried many different...
Read more >
Element size and scrolling - The Modern JavaScript Tutorial
We've just covered geometry properties of DOM elements, that can be used to get widths, heights and calculate distances. But as we know...
Read more >
website page cant scroll when a map is visible(on the ... - GitHub
the whole page can not scroll ,even when I try changing the width style of the map container,or fixed/absolute/static position.
Read more >
Google map scrolls when scrolling down the page on mobile
I'm putting a site together with a full width google map, its fine on a pc as you can use the scrollbar, but...
Read more >
Scroll tracking with Google Analytics 4 and Google Tag Manager
But did you know that the built-in scroll tracking in Google ... only when someone scrolls below the 90% percent mark of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found