Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixedPopup: Allows fixing the popup on coordinates #1098

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

HelloYuiYui
Copy link
Contributor

Purpose

Allow FixedPopup class to be fixed on map coordinates. Similar to a popup, while retaining the functionality to be moved around on the map. This is an enhancement to the fixed popup.

How

A new parameter "fixedPosition" is passed when creating the popup, if set to true it saves the coordinates of the popup and updates pixel position of the popup accordingly when the map is moved so the popup stays on the saved coordinates.

Also addresses the minor point of options on the example html page not applying to the second popup. (see lines 138 & 141 @ fixedpopup.html)

@Viglino
Copy link
Owner

Viglino commented Aug 21, 2024

The FixedPopup class is a subclass of the Popup class that inherits from Ovelays. It override the updatePixelPosition and updateRenderedPosition from this root class.
I don't think it's a good practice to hack the subclass to restore the root behavior. You should consider using two instances (one Popup and one FixedPopup) and switch when you need.

Viglino added a commit that referenced this pull request Aug 21, 2024
@Viglino
Copy link
Owner

Viglino commented Aug 21, 2024

I've pushed a commit that just call the root class method (super) when the fixed property is set to false: ol/Overlay/FixedPopup~setFixed(bool)

@HelloYuiYui
Copy link
Contributor Author

With the fixed set to false now, the popup goes back to the camera icon's position on the map and cannot be moved elsewhere. My intended behaviour was to keep it fixed on the map position it is moved to, hence addition of this._coord and changes to the root methods so that there are two positions stored, one for the main position (the camera icon on the map) and the position the popup element sits on (this._coord).

Would it be possible to have the popup retain the new position it is on without modifying the root methods? I attempted to use the Popup class as well but FixedPopup was more fitting as I needed the popup to be movable, but static on different coordinates. Thanks!

@Viglino
Copy link
Owner

Viglino commented Aug 21, 2024

OK I see

Viglino added a commit that referenced this pull request Aug 21, 2024
@Viglino
Copy link
Owner

Viglino commented Aug 21, 2024

I finally get your code but rename the method 'hook' to be more readable.
The popup can be hooked on the 'map' popup.setHook('map') or on the 'viewport' popup.setHook('viewport').
popup.get('hook') lets you get it back.
See online: https://viglino.github.io/ol-ext/examples/popup/map.fixedpopup.html

@HelloYuiYui
Copy link
Contributor Author

Nice, thank you!

Added minor fixes to the options so when they change both open popups are updated. Currently if you have two popup's open (with shift+click) and change the options they are only applied to the first popup.

@Viglino Viglino merged commit 79661f2 into Viglino:master Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants