Skip to content

Commit

Permalink
Merge pull request #583 from geonetwork/fix-weird-box-zoom
Browse files Browse the repository at this point in the history
Change dragPanCondition to fix box zoom on map
  • Loading branch information
Angi-Kinas authored Aug 22, 2023
2 parents ed55122 + f774324 commit 90cfc36
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
42 changes: 42 additions & 0 deletions libs/feature/map/src/lib/utils/map-utils.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
PinchRotate,
} from 'ol/interaction'
import { MetadataLinkType } from '@geonetwork-ui/util/shared'
import MapBrowserEvent from 'ol/MapBrowserEvent'

const wmsUtilsMock = {
getLayerLonLatBBox: jest.fn(() => of([1.33, 48.81, 4.3, 51.1])),
Expand Down Expand Up @@ -265,6 +266,47 @@ describe('MapUtilsService', () => {
})
})

describe('#dragPanCondition', () => {
let interaction: DragPan
beforeEach(() => {
interaction = new DragPan()
const map = new Map({})
map.addInteraction(interaction)
})

it('returns true for a left click without modifier key', () => {
const nativeEvent = {
type: 'pointer',
pointerType: 'mouse',
isPrimary: true,
button: 0,
}
const event = new MapBrowserEvent(
'pointer',
interaction.getMap(),
nativeEvent as PointerEvent
)

expect(dragPanCondition.bind(interaction)(event)).toBe(true)
})
it('returns false for a left click with modifier key', () => {
const nativeEvent = {
type: 'pointer',
pointerType: 'mouse',
isPrimary: true,
button: 0,
shiftKey: true,
}
const event = new MapBrowserEvent(
'pointer',
interaction.getMap(),
nativeEvent as PointerEvent
)

expect(dragPanCondition.bind(interaction)(event)).toBe(false)
})
})

const SAMPLE_WMTS_LINK = {
name: 'GEOGRAPHICALGRIDSYSTEMS.ETATMAJOR10',
url: 'http://my.server.org/wmts',
Expand Down
10 changes: 8 additions & 2 deletions libs/feature/map/src/lib/utils/map-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import TileWMS from 'ol/source/TileWMS'
import VectorSource from 'ol/source/Vector'
import { Options, optionsFromCapabilities } from 'ol/source/WMTS'
import { DragPan, MouseWheelZoom, defaults, Interaction } from 'ol/interaction'
import { mouseOnly, platformModifierKeyOnly } from 'ol/events/condition'
import {
mouseOnly,
noModifierKeys,
platformModifierKeyOnly,
primaryAction,
} from 'ol/events/condition'
import WMTSCapabilities from 'ol/format/WMTSCapabilities'
import { from, Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
Expand Down Expand Up @@ -220,7 +225,8 @@ export function dragPanCondition(
if (!dragPanCondition) {
this.getMap().dispatchEvent('mapmuted')
}
return dragPanCondition
// combine the condition with the default DragPan conditions
return dragPanCondition && noModifierKeys(event) && primaryAction(event)
}

export function mouseWheelZoomCondition(
Expand Down

0 comments on commit 90cfc36

Please sign in to comment.