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

fix: multiple small bug fixes #1221

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

iBobik
Copy link
Contributor

@iBobik iBobik commented Sep 17, 2022

I hope all fixes are ok :-)

Sorry for adding more commits in one PR. In my project I had to to many changes to make it work and I hope it is not big deal in project of this state.

I am open to specific feedback and will improve it ASAP, so they can be merged soon. You can also cherry pick some commits if it makes sense.

To be in sync with package.json. Previously:
npm ci can only install packages when your package.json and package-lock.json or
npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.

Signed-off-by: Honza Pobořil <[email protected]>
Signed-off-by: Honza Pobořil <[email protected]>
Map load could take time and all child components will need to have map object loaded.

Signed-off-by: Honza Pobořil <[email protected]>
Component could be mounted sooner than style finished loading, so check it first.

Signed-off-by: Honza Pobořil <[email protected]>
@iBobik iBobik changed the title Multiple small bug fixes fix: multiple small bug fixes Sep 18, 2022
- Added umnount hooks
- Added visibility prop for geojson
- Moved style load waiting from components to VMap

Signed-off-by: Honza Pobořil <[email protected]>
So I can npm install branch directly.

Signed-off-by: Honza Pobořil <[email protected]>
Comment on lines -58 to -69
map.value.on('style.load', () => {
// https://github.com/mapbox/mapbox-gl-js/issues/2268#issuecomment-401979967
const styleTimeout = () => {
if (!map.value.isStyleLoaded()) {
loaded.value = false;
setTimeout(styleTimeout, 200);
} else {
loaded.value = true;
}
};
styleTimeout();
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you've added the loaded check in map, maybe we can refactor this code from all the other files ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the issue that is linked it seems that the style can be changed and then the map.value.isStyleLoaded() can return false even when the map was loaded once before. I think leaving this as is in VMarker and other components is safer then dooing it only in VMap component when load event is fired from mapbox.

The use case for this code is when you change the style of the map and then add new marker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Buk1m Do you think it would be ok to reload all child components (markers, …) centrally from map when style has changed?

Because this would allow simplify components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinayakkulkarni Could you please tell if I can solve style change by children reload? It will be small performance degradation on style change, but huge simplification of child components.

Thank you for decision. I am going to work on another issues and I will need to merge this, because otherwise I will be forced to commit everything just to my fork and not care about PRs. It is hard to advocate open source contributions to my clients when it will delay fixes and make it more expensive.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @iBobik, sorry for the late message I must have missed the previous notification.

I only worked with mapbox custom styles in a way that styles were loaded at the beginning and never changed, in which case your solution would work. (Un)fortunately you can change them after the map was loaded simply by calling map.setStyle and then map.value.isStyleLoaded() will return false again.

Loading new styles can take a while as it is usually a http request. So if the styles were changed and you will try to add new marker before loading is finished, then you will encounter "Style not done loading" error (At least according to the issue from comment).

There is no way to listen if styles were changed so you can either wrap setStyles method to know when the styles were changed and delay map manipulations until map.value.isStyleLoaded() return true or stick with the current solution.

So the case is:

  1. Map has fully loaded once
  2. Styles are changed
  3. New marker is added before new styles are fully loaded.
  4. Possible "Style not done loading" error

Keep in mind that the issue is old and I didn't test this exact case myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have some idea how to solve it without having this timeout logic in every component?

Is it enough to have own method for style switching what will unload all children for the time of loading?

I am looking for solution what will simplify v-mapbox' codebase, because we are not able to do everything perfectly. In this project's status we have difficulties to push it to the stable state just for basic use-cases, so I think we should not paralyse development by requiring to cover too much use-cases.

@iBobik
Copy link
Contributor Author

iBobik commented Sep 30, 2022 via email

Copy link

@Buk1m Buk1m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional popup could be already merged but this PR contains too many changes to other files. The default popup is annoying as I cannot add a marker without popup or errors.

Most of the changes are nice in my opinion but the change to loaded event is unnecessary and can cause issues when map style is changed after initial load.

src/controls/VControlGeolocate.vue Outdated Show resolved Hide resolved
src/layers/mapbox/VLayerMapboxGeojson.vue Outdated Show resolved Hide resolved
Comment on lines -58 to -69
map.value.on('style.load', () => {
// https://github.com/mapbox/mapbox-gl-js/issues/2268#issuecomment-401979967
const styleTimeout = () => {
if (!map.value.isStyleLoaded()) {
loaded.value = false;
setTimeout(styleTimeout, 200);
} else {
loaded.value = true;
}
};
styleTimeout();
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the issue that is linked it seems that the style can be changed and then the map.value.isStyleLoaded() can return false even when the map was loaded once before. I think leaving this as is in VMarker and other components is safer then dooing it only in VMap component when load event is fired from mapbox.

The use case for this code is when you change the style of the map and then add new marker.

@Buk1m
Copy link

Buk1m commented Oct 12, 2022

I would like to use this library but it still needs more work and more reactivity. If I pass new coordinates to Marker then it should move on the map accordingly. I could make a PR with some improvements but first I would like to see this PR merged.

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.

3 participants