Giter Site home page Giter Site logo

Comments (4)

jgimbel avatar jgimbel commented on June 20, 2024 2

I found how popup's catch the scroll event.

I think this is how you will want to handle scroll events.

import { DomEvent } from 'leaflet'
import  React, { Component } from 'react'
import Control from 'react-leaflet-control'

class CustomZoom extends Component {

  componentDidMount() {
    DomEvent
      .disableClickPropagation(this.container)
      .disableScrollPropagation(this.container)
  }

  refContainer(el) {
    this.container = el;
  }

  render() {
    <Control position={topright} >
      <div ref={::this.refContainer}> I am scrollable, and will not click on the map! </div>
    </Control>
  }
}

from react-leaflet-control.

jgimbel avatar jgimbel commented on June 20, 2024

If I understand correctly. The control pane is not seeing the scroll event, but the map catches it, and scrolls. I will need to create an example folder to test this. Unfortunately I am traveling today and cannot work on this.

from react-leaflet-control.

alexanderfrey avatar alexanderfrey commented on June 20, 2024

Yes, thats exactly what is happening. I have seen suggestions on github leaflet to register an event listener when mouse is entering custom control and to to call map.disablePan() within that event listener. That sounds very hacky to me and did not work reliably for me. What wonders me though is that only few people seem to complain about that issue. I looked into the zoom control code of react-leaflet which seems to block the events somehow but I could not find the reason for that. Thanks for your help in advance !!

from react-leaflet-control.

NekoApocalypse avatar NekoApocalypse commented on June 20, 2024

I tried the code above, but got an Error.

The problem is: React does not guarantee ref callbacks to be called after componentDidMount(), So there is a chance that this.container() is still null when componentDidMount() is called.

Here is my code that eliminated the error for me (plus, no need to bind refContainer):

class StaticControl extends Component {
    constructor(props) {
      super(props);
      this.container = null;
  }

  refContainer = (element) => {
    this.container = element;
    if (element) {
      DomEvent
        .disableClickPropagation(element)
        .disableScrollPropagation(element);
    }
  }

  render() {
    return (
      <Control position="topleft">
        <div ref={this.refContainer}>
          I am scrollable and will not click on the map!
        </div>
      </Control>
    );
  }
}

from react-leaflet-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.