Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #195 from MonsantoCo/offset-support
Browse files Browse the repository at this point in the history
fix popup offset from margins added to map container
  • Loading branch information
stazrad authored Sep 29, 2020
2 parents d99f48e + a1cd7a1 commit 9872147
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bayer/ol-kit",
"version": "0.18.0",
"version": "0.18.1",
"license": "BSD",
"description": "Mapping components & utils built with openlayers + react",
"keywords": [
Expand Down
12 changes: 6 additions & 6 deletions runfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const packageJson = require('./package.json')
const packageName = packageJson.name

function ship () {
const tag = packageJson.version.includes('-') ? 'next' : 'latest'
const latestVersion = child_process.execSync(`npm view ${packageName}@latest version`).toString()
const tag = packageJson.version.includes('-') ? 'next' : 'legacy'
const legacyVersion = child_process.execSync(`npm view ${packageName}@legacy version`).toString()

// publish with a `shipping` tag so we can control the latest/next tags manually since NPM defaults to latest if no tag is provided
// publish with a `shipping` tag so we can control the legacy/next tags manually since NPM defaults to legacy if no tag is provided
run(`export SHIP=true && npm run build && npm publish -f --tag shipping`)
// remove the temporary shipping tag
run(`npm dist-tags remove ${packageName} shipping || true`)

// only if the latest is less than the current version do we tag it (this ignores support branches)
if (semver.gt(packageJson.version, latestVersion)) {
// add the appropriate next or latest tag manually to the version just published
// only if the legacy is less than the current version do we tag it (this ignores support branches)
if (semver.gt(packageJson.version, legacyVersion)) {
// add the appropriate next or legacy tag manually to the version just published
run(`npm dist-tags add ${packageName}@${packageJson.version} ${tag}`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Draw/__snapshots__/DrawContainer.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`<DrawContainer /> should render a basic prebuilt DrawContainer componen
class=\\"sc-AxirZ flfhYH\\"
href=\\"https://ol-kit.com/\\"
target=\\"_blank\\"
title=\\"Powered by ol-kit v0.18.0\\"
title=\\"Powered by ol-kit v0.18.1\\"
>
<svg
viewBox=\\"0 0 204.76 236.44\\"
Expand Down
29 changes: 10 additions & 19 deletions src/Popup/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,6 @@ export const getPopupPositionFromFeatures = (event, features = [], opts = {}) =>
bottom: getPadding(2),
left: getPadding(3)
}
// olMap.getPixelFromCoordinate returns a pixel relative to the map's target element so we need to convert that to a pixel relative to the window.
const mapToScreenPixel = (pixel = [0, 0]) => {
const { x, y } = map.getTargetElement().getBoundingClientRect()
const offset = [x, y]

return pixel.map((val, i) => {
return val + offset[i]
})
}

// find bbox for passed features
const getFitsForFeatures = rawFeatures => {
Expand Down Expand Up @@ -231,21 +222,21 @@ export const getPopupPositionFromFeatures = (event, features = [], opts = {}) =>

// the order of these checks determine which side is tried first (right, left, top, and then bottom)
const getPosition = bbox => {
if (fitsRight(bbox.right)) return { arrow: 'left', pixel: mapToScreenPixel(bbox.right), fits: true }
if (fitsLeft(bbox.left)) return { arrow: 'right', pixel: mapToScreenPixel(bbox.left), fits: true }
if (fitsAbove(bbox.top)) return { arrow: 'bottom', pixel: mapToScreenPixel(bbox.top), fits: true }
if (fitsBelow(bbox.bottom)) return { arrow: 'top', pixel: mapToScreenPixel(bbox.bottom), fits: true }
if (fitsRight(bbox.right)) return { arrow: 'left', pixel: bbox.right, fits: true }
if (fitsLeft(bbox.left)) return { arrow: 'right', pixel: bbox.left, fits: true }
if (fitsAbove(bbox.top)) return { arrow: 'bottom', pixel: bbox.top, fits: true }
if (fitsBelow(bbox.bottom)) return { arrow: 'top', pixel: bbox.bottom, fits: true }

if (opts.lastPosition) {
if (opts.lastPosition.arrow === 'left') return { arrow: 'left', pixel: mapToScreenPixel(bbox.right), fits: false }
if (opts.lastPosition.arrow === 'top') return { arrow: 'top', pixel: mapToScreenPixel(bbox.bottom), fits: false }
if (opts.lastPosition.arrow === 'bottom') return { arrow: 'bottom', pixel: mapToScreenPixel(bbox.top), fits: false }
if (opts.lastPosition.arrow === 'right') return { arrow: 'right', pixel: mapToScreenPixel(bbox.left), fits: false }
if (opts.lastPosition.arrow === 'none') return { arrow: 'none', pixel: mapToScreenPixel(opts.lastPosition.pixel), fits: false }
if (opts.lastPosition.arrow === 'left') return { arrow: 'left', pixel: bbox.right, fits: false }
if (opts.lastPosition.arrow === 'top') return { arrow: 'top', pixel: bbox.bottom, fits: false }
if (opts.lastPosition.arrow === 'bottom') return { arrow: 'bottom', pixel: bbox.top, fits: false }
if (opts.lastPosition.arrow === 'right') return { arrow: 'right', pixel: bbox.left, fits: false }
if (opts.lastPosition.arrow === 'none') return { arrow: 'none', pixel: opts.lastPosition.pixel, fits: false }
}

// if none of the above return, it doesn't fit on any side (it's on top of or within)
return { arrow: 'none', pixel: mapToScreenPixel(pixel), fits: false }
return { arrow: 'none', pixel, fits: false }
}

return getPosition(getFitsForFeatures(features))
Expand Down

0 comments on commit 9872147

Please sign in to comment.