Ticket #2477 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Cloning layers creates clones with the initial state of the original, not the current one

Reported by: ahocevar Owned by: pgiraud
Priority: critical Milestone: 2.9 Release
Component: Layer Version: 2.8
Keywords: Cc:
State: Complete

Description

Because all our layers' clone() methods create a new instance with the original's options, the clones don't have the current state of the original. I think this is not what people expect.

Attachments

openlayers-2477.patch Download (12.1 KB) - added by ahocevar 3 years ago.
openlayers-2477.2.patch Download (11.9 KB) - added by ahocevar 3 years ago.
as suggested by tschaub, don't copy the original's options to the clone
patch-2477-r10117.diff Download (0.8 KB) - added by pgiraud 3 years ago.

Change History

Changed 3 years ago by ahocevar

(In [10040]) Acceptance test checking for proper clone() behavior (see #2477)

Changed 3 years ago by ahocevar

Changed 3 years ago by ahocevar

  • state set to Review

Patch with tests attached. Here is what it does: the new Layer::getOptions function walks through the options object, creating a new options object with the values from the instance. At the end of the clone process, the original's options are copied to the clone's options property.

All layer tests still pass, please review.

Changed 3 years ago by tschaub

  • state changed from Review to Commit

As discussed elsewhere, it feels a bit inconsistent to me to redefine clone as something like "the clone method creates a new layer based on the current state of an existing layer" and then to find that the clone.options object isn't actually what it was constructed with but instead what the other layer was constructed with. But if there is some reason to set the clone's options to those of the original, it's ok by me.

If tests pass, please commit.

Changed 3 years ago by ahocevar

as suggested by tschaub, don't copy the original's options to the clone

Changed 3 years ago by ahocevar

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [10045]) Changing our layers' clone methods so they create a clone of the layer state at the time of clone creation, not at the time the original was created. r=tschaub (closes #2477)

Changed 3 years ago by pgiraud

  • priority changed from minor to critical
  • status changed from closed to reopened
  • state Complete deleted
  • resolution fixed deleted

With this patch, tests fail on Layer.html.

Changed 3 years ago by bartvde

  • owner changed from euzuro to bartvde
  • status changed from reopened to new

I'll look into the test breakage, thanks for the report fredj.

Changed 3 years ago by bartvde

  • status changed from new to closed
  • state set to Complete
  • resolution set to fixed

(In [10120]) fix up tests in Layer.html after clone method was changed, since the clone now represents the original in its current state, and not the state at creation, two tests had to be adapted, non-functional change (closes #2477)

Changed 3 years ago by pgiraud

  • status changed from closed to reopened
  • state changed from Complete to Review
  • resolution fixed deleted

Bart got quicker than me.

OK, as far as I understand, the problem is related to the max and min resolutions. Given a maxResolution option set to "auto", a layer will compute its maxResolution (and then its minResolution) given the size of the map div. Now that the clone method creates a clone with the layer state at the time of the clone creation, the maxResolution of the cloned layer value is the computed one. For now, I don't see any issue with this. If others are also ok with this, I think we can remove the tests on min/maxResolution (See attached patch). The previous test which checks that optionschicken? is correct is sufficient, in my opinion.

Changed 3 years ago by bartvde

I am fine with removing these two test cases.

Changed 3 years ago by pgiraud

Changed 3 years ago by tschaub

  • owner changed from bartvde to pgiraud
  • status changed from reopened to new
  • state changed from Review to Commit

I'm ok with this as well.

Changed 3 years ago by pgiraud

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [10140]) let's remove unrequired tests, r=bartvde, (Closes #2477)

Note: See TracTickets for help on using tickets.