2
votes

I am adding new features to a map solution which is using OpenLayers 2.13. This solution displays features over Norway, so we're using UTM33N (EPSG:32633) Projection.

Currently I am trying to add selectable/tooltip functionality to a new layer which should display GPS-tracks (Linestrings) The solution already has similar "selectable" functionality on several of its layers. These layers are added as an array to an OpenLayers.Control.SelectFeature.

Before I added the GPS layer to the SelectFeature, I could see it being displayed correctly in the map and in the right position. (Image 1)

During setting up the map, I add the GPS layer to the layers in the SelectFeature control which is inside a custom made TooltipControl:

tooltipControl.getSelectFeatureControl().selectFeatureControl.layers.push(gpsLayer);

When I add it to the SelectFeature control however, it is displayed with a considerable offset from where it should have been. (Image 2) The offset is actually dependent on zoom level, because when I zoom in the features approach their correct position, but still aren't correct.

From inspecting the DOM I can see that before adding the GPS layer to the SelectFeature control the layer was being rendered inside a div called "OpenLayers_Layer_Vector_55". When panning the map, the div's style is being changed, more specifically the "left" and "top" properties of the div are being changed to ensure the linestring is rendered at the correct position.

After adding it to SelectFeature, it is being rendered inside a div called "OpenLayers_Layer_Vector_RootContainer_283" along with all the other selectable layers. Now the GPS layer is not rendered in the correct position on the map anymore. OpenLayers is still updating the "left" and "top" properties of the Vector_55 div when I pan, but the GPS layer is unaffected by this since it is now contained in the RootContainer_283 div.

How can I render the GPS layer in the correct position and still have it in the SelectFeature control?

Image 1 - Correct rendering:

Image 2 - Incorrect rendering:

Thanks in advance!

1
How large is the offset? Meters, kilometers? Which projections are you using?MortenSickel
The offset is actually dependent on zoom level. When I zoom in, the features approach their correct position, but still aren't correct. Projection used is EPSG:32633 (UTM33N).Anders Gjerde
OpenLayers is surely able to handle multiple vector layers with a selectFeature control, so the problem is somewhere else.. Maybe in the custom selectFeature control?fradal83

1 Answers

1
votes

After hours of searching I finally found that the GPS layer was getting its "ratio" set to 1.2 at initialization.

This layer used to be a WMS layer (inheriting from Grid), so setting its ratio would mean:

ratio {Float} Used only when in single-tile mode, this specifies the ratio of the size of the single tile to the size of the map.

But ratio means something else for a Vector layer:

ratio {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map.

With the default ratio at 1, it's rendered in the right position! Thanks to the commenters for your input.