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

PolygonLayer- add elevationScale, fix updateTriggers.getElevation doesn't trigger updateGeometry #1046

Merged
merged 3 commits into from
Nov 2, 2017

Conversation

heshan0131
Copy link
Collaborator

  • bug fix: Recalculate geometry when updateTriggers.getElevation has changed
  • add elevationScale

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

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

There are 2-3 PRs here:

  1. A very straightforward addition of an elevationScale prop to the polygon layer.
    2a) A tricky workaround for the getElevation accessor not being triggered correctly.
    2b) A "hack" to the layer-browser to be able to trigger updateTriggers.

The first one I think could just be merged. The second one should ideally go through some discussion.

If these are being proposed for patch releases, having small PRs would also be a big benefit.

// tessellator needs to be invoked
if (changeFlags.dataChanged || geometryConfigChanged) {
// check if updateTriggers.getElevation has been triggered
const getElevationTriggered = changeFlags.updateTriggersChanged &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I think I understand why you needed to do this (you have an accessor that affects positions), you'll probably agree with me when I say that I don't like the amount of code needed to handle this case here.

We should take a second look at the PolygonTesselator it can handle this - to make sure we don't need it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is what I had to do here to have polygon tessellation triggered by updateTriggers.getElevation. This bug affects both the Polygon layer and the GeojsonLayer. The frustration here is changeFlags.updateTriggersChanged only returns true or false, so there is no way to tell which accessor has changed. If there is way to tell whether updateTriggers.getElevation has changed in one line, it would be mostly ideal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is the right approach.
With the current polygon layer setup, calculatePositions is already being called when getElevation update trigger changes, where we call this.state.polygonTesselator.positions(). What needs to happen is that we move the position calculation from the tesselator's constructor into this method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The tesselator is also a bit tricky as all other attributes depend on the positions. They need to be precalculated for the other attribute calculators to work. The model doesn't integrate smoothly with our normal attribute manager model.

I've made a couple of attempts to create a generic Tesselator/GeometryManager for layers with "custom geometries" to handle this (and a couple of other related issues) in a unified way but haven't had time to get it ready, unfortunately.

I guess we'll need to make a temporary fix here for now, proceed as makes sense. I'll approve the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We never use the positions array in other attribute calculation. Each attribute is calculated independently from the source data and accessors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To clarify - in a custom geometry the number of vertices per object is not constant. This is a calculation that depends on the "position" accessor (perhaps getPolygon or getPath) that affects all other attributes.

I tend to think of the number of verts that gets discovered during "position" calculation, an example is the PolygonLayer where we use something like the earcut library, although I think we are make some short cuts there.

In general one will need to either be able to calculate the number of verts in every attribute updater, or build an intermediary data structure to hold verts and indices and make it available to attribute updates. This is one of the problems I was tackling.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The accessor that will change all attributes is getPolygon, whose update trigger we are not tracking, and that should be a bug.
The specific issue that this PR is trying to fix is regarding getElevation, which only affects positions, and should not need to reconstruct the tesselator.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course. The main thing that concerns me is the amount of logic this is adding to the layers. I was trying to explain a solution I have been trying to build on the side. Have already approved this PR.

lightSettings: LIGHT_SETTINGS,
elevationScale: 0.6
},
getUpdateTriggers: settings => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intended to create a manual test case for the getElevation updateTrigger?

Maybe we should add a separate button to trigger updateTriggers rather than hooking it to some arbitrary setting?

The prop handling in the layer browser is already very hacky. I would like us to at least think twice before adding more hacks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree this is hacky at a glance. At the moment, our layer browser doesn't provide any mechanism to allow tests on updateTriggers. It really increases the risks that updateTriggers are not handled correctly in layers. Though I agree with you this probably should not be included in this PR, will remove it and leave it for further discussion

@heshan0131 heshan0131 changed the title PolygonLayer- add elevationScale, bug fixes PolygonLayer- add elevationScale, fix updateTriggers.getElevation doesn't trigger updateGeometry Oct 18, 2017
@heshan0131 heshan0131 changed the base branch from master to 4.1-release October 27, 2017 17:56
@heshan0131 heshan0131 changed the base branch from 4.1-release to master October 27, 2017 18:24
@heshan0131 heshan0131 merged commit 400cfa0 into master Nov 2, 2017
@heshan0131 heshan0131 added this to the v4.1.Next milestone Nov 14, 2017
heshan0131 added a commit that referenced this pull request Nov 21, 2017
…sn't trigger updateGeometry (#1046)

* [PolygonLayer] add elevationScale
* [GeoJsonLayer] add elevationScale
* bug fix: [solidPolygonLayer] generate geometry when updateTriggers.getElevation has changed
@heshan0131 heshan0131 mentioned this pull request Nov 21, 2017
heshan0131 added a commit that referenced this pull request Nov 22, 2017
…sn't trigger updateGeometry (#1046)

* [PolygonLayer] add elevationScale
* [GeoJsonLayer] add elevationScale
* bug fix: [solidPolygonLayer] generate geometry when updateTriggers.getElevation has changed
@ibgreen ibgreen deleted the polygon-layer-elevation branch November 29, 2017 21:21
@jianhuang01 jianhuang01 modified the milestones: v4.1.Next, v4.1.6 PATCH Dec 1, 2017
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.

4 participants