openlayers / ol2

OpenLayers v2 - deprecated!
Other
1.48k stars 771 forks source link

Using ratio attribute of vector layer with selectFeature control results in layer offset #1363

Open sassanp opened 10 years ago

sassanp commented 10 years ago

Hi Folks,

When I use the ratio property of a vector layer (to pre-render off-screen features) and enable selectFeature control for the same layer, the result is that the layer is shifted (the amount of shift depends on the ratio set).

This would appear to be a bug. It goes away if I either disable/deactivate the control or set the ratio to 1.

Bug does not occur when using the Canvas renderer (but unfortunately this renderer lacks many essential features for my project).

I think it's something to do with RootContainer.

Thanks Sassan

clifforj commented 10 years ago

I hit this same problem today, it happens only when you add multiple layers to a selectFeature control. The workaround which I'm using for the time being is to set a matching ratio onto the RootContainer layer that the selectFeature control creates. e.g.

layer1.addOptions({ratio: 2.5});
layer2.addOptions({ratio: 2.5});

selectControl = new OpenLayers.Control.SelectFeature([layer1, layer2]);
selectControl.layer.addOptions({ratio: 2.5});

This seems to work because ratios added to the RootContainer shift the layer in the opposite direction to ratios added to the other layers... Still looking for an actual fix though!

clifforj commented 10 years ago

Digging into it a bit more and it's starting to make much more sense why this 'shift' occurs.

Consider the following, a RootContainer with ratio of 1, and a child layer with a ratio of 2. As ratio relates to the drawable area of the layers, you'd end up with the following situation.

| = RootContainer
- = Child Layer
+ = RootContainer & Child Layer

+++++++++++++++---------------
+             |              -
+             |              -
+             |              -
+             |              -
+||||||||||||||              -
-                            -
-                            -
-                            -
-                            -
------------------------------

We can see that the centre point of the RootContainer is no where near the centre point of the child. This is what causes the 'shift' effect as something rendered at the centre of the Child layer would actually be much further down/right of the center of the viewport.

sassanp commented 10 years ago

Workaround works. Thanks!

Would be nice if it could be done automatically. A fairly simple patch (see if all child layers have common ratio and inherit if possible), but I don't have a dev environment set up. Much more complex would be handling the (thankfully unlikely) case where there are multiple layers with varying ratios.

Thanks again for the workaround. Sassan

On 5 August 2014 17:32, John Clifford notifications@github.com wrote:

Digging into it a bit more and it's starting to make much more sense why this 'shift' occurs.

Consider the following, a RootContainer with ratio of 1, and a child layer with a ratio of 2. As ratio relates to the drawable area of the layers, you'd end up with the following situation.

| = RootContainer

  • = Child Layer
  • = RootContainer & Child Layer

+++++++++++++++---------------

  • | -
  • | -
  • | -
  • | - +|||||||||||||| -
  • -
  • -
  • -

- -

We can see that the centre point of the RootContainer is no where near the centre point of the child. This is what causes the 'shift' effect as something rendered at the centre of the Child layer would actually be much further down/right of the center of the viewport.

Reply to this email directly or view it on GitHub https://github.com/openlayers/openlayers/issues/1363#issuecomment-51223500 .