zcreativelabs / react-simple-maps

Beautiful React SVG maps with d3-geo and topojson using a declarative api.
https://www.react-simple-maps.io/
MIT License
3.03k stars 424 forks source link

How to disable double click zoom #341

Open goinnovise opened 9 months ago

goinnovise commented 9 months ago

I am using react-simple-maps 3.0.0-beta.6

I am using the useZoomPan hook to create a control.

I am disabling zoom on scroll with filterZoomEvent, but also noticed that there's zoom-in behavior on double-click. It'd like to disable this.

I've tried handling the click event for geographies and running event.preventDefault() with no luck. I've also noticed that geography.onDoubleClick no longer fires after adding a ZoomableGroup.

My CustomizableZoomGroup:

import { useZoomPan } from 'react-simple-maps'

const handleZoomFilter = ev => {  
  const disableTypes = ['wheel', 'mousedown']  
  return !disableTypes.includes(ev.type)
}

const width = 800
const height = 600
const CustomizableZoomGroup = ({ children }) => {

  const { mapRef, transformString, position } = useZoomPan({
    center: [0, 0],
    filterZoomEvent: handleZoomFilter,
    scaleExtent: [1, 3],
    translateExtent: [
      [0, -height],
      [width, height],
    ],
  })

  return (
    <g ref={mapRef}>
      <g transform={transformString}>{children(position)}</g>
    </g>
  )
}

export default CustomizableZoomGroup
EvgeniyT13 commented 5 months ago

I am using react-simple-maps 3.0.0-beta.6

I am using the useZoomPan hook to create a control.

I am disabling zoom on scroll with filterZoomEvent, but also noticed that there's zoom-in behavior on double-click. It'd like to disable this.

I've tried handling the click event for geographies and running event.preventDefault() with no luck. I've also noticed that geography.onDoubleClick no longer fires after adding a ZoomableGroup.

My CustomizableZoomGroup:

import { useZoomPan } from 'react-simple-maps'

const handleZoomFilter = ev => {  
  const disableTypes = ['wheel', 'mousedown']  
  return !disableTypes.includes(ev.type)
}

const width = 800
const height = 600
const CustomizableZoomGroup = ({ children }) => {

  const { mapRef, transformString, position } = useZoomPan({
    center: [0, 0],
    filterZoomEvent: handleZoomFilter,
    scaleExtent: [1, 3],
    translateExtent: [
      [0, -height],
      [width, height],
    ],
  })

  return (
    <g ref={mapRef}>
      <g transform={transformString}>{children(position)}</g>
    </g>
  )
}

export default CustomizableZoomGroup

I also have this issue. But I used 'dblclick' in array and double click is disabled.