以偏移量显示的 OpenLayers 矢量图层
OpenLayers vector layer being displayed with offset
我正在向使用 OpenLayers 2.13 的地图解决方案添加新功能。
此解决方案显示挪威的要素,因此我们使用 UTM33N (EPSG:32633) 投影。
目前我正在尝试向新图层添加 selectable/tooltip 功能
应该显示 GPS 轨迹(线串)
该解决方案已经具有类似的 "selectable" 功能
它的几个层。这些图层作为数组添加到 OpenLayers.Control.SelectFeature。
在我将 GPS 层添加到 SelectFeature 之前,我可以看到它正在显示
正确地在地图上和正确的位置。 (图 1)
在设置地图的过程中,我将GPS图层添加到里面的SelectFeature控件中的图层中
自定义的 TooltipControl:
tooltipControl.getSelectFeatureControl().selectFeatureControl.layers.push(gpsLayer);
但是,当我将它添加到 SelectFeature 控件时,它显示的位置与它应该显示的位置有相当大的偏移。 (图 2)
偏移量实际上取决于缩放级别,因为当我放大功能时接近它们的正确位置,但仍然不正确。
通过检查 DOM 我可以看到在将 GPS 层添加到 SelectFeature 控件之前
该层在名为 "OpenLayers_Layer_Vector_55" 的 div 中渲染。平移时
地图,div 的样式正在更改,更具体地说是 "left" 和 "top" 属性
的 div 正在更改以确保线串呈现在正确的位置。
将其添加到 SelectFeature 后,将在名为 "OpenLayers_Layer_Vector_RootContainer_283" 的 div 中呈现
以及所有其他可选层。现在 GPS 图层未正确呈现
在地图上的位置了。 OpenLayers 仍在更新 Vector_55 div 的 "left" 和 "top" 属性
当我平移时,但 GPS 层不受此影响,因为它现在包含在 RootContainer_283 div.
如何在正确的位置渲染 GPS 层并使其仍然在 SelectFeature 控件中?
提前致谢!
经过几个小时的搜索,我终于发现 GPS 层在初始化时将其 "ratio" 设置为 1.2。
这个层曾经是一个WMS层(继承自Grid),所以设置它的比率意味着:
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.
但是比率对于矢量图层来说还有其他含义:
ratio {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map.
在默认比例为 1 的情况下,它呈现在正确的位置!感谢评论者的意见。
我正在向使用 OpenLayers 2.13 的地图解决方案添加新功能。 此解决方案显示挪威的要素,因此我们使用 UTM33N (EPSG:32633) 投影。
目前我正在尝试向新图层添加 selectable/tooltip 功能 应该显示 GPS 轨迹(线串) 该解决方案已经具有类似的 "selectable" 功能 它的几个层。这些图层作为数组添加到 OpenLayers.Control.SelectFeature。
在我将 GPS 层添加到 SelectFeature 之前,我可以看到它正在显示 正确地在地图上和正确的位置。 (图 1)
在设置地图的过程中,我将GPS图层添加到里面的SelectFeature控件中的图层中 自定义的 TooltipControl:
tooltipControl.getSelectFeatureControl().selectFeatureControl.layers.push(gpsLayer);
但是,当我将它添加到 SelectFeature 控件时,它显示的位置与它应该显示的位置有相当大的偏移。 (图 2) 偏移量实际上取决于缩放级别,因为当我放大功能时接近它们的正确位置,但仍然不正确。
通过检查 DOM 我可以看到在将 GPS 层添加到 SelectFeature 控件之前 该层在名为 "OpenLayers_Layer_Vector_55" 的 div 中渲染。平移时 地图,div 的样式正在更改,更具体地说是 "left" 和 "top" 属性 的 div 正在更改以确保线串呈现在正确的位置。
将其添加到 SelectFeature 后,将在名为 "OpenLayers_Layer_Vector_RootContainer_283" 的 div 中呈现 以及所有其他可选层。现在 GPS 图层未正确呈现 在地图上的位置了。 OpenLayers 仍在更新 Vector_55 div 的 "left" 和 "top" 属性 当我平移时,但 GPS 层不受此影响,因为它现在包含在 RootContainer_283 div.
如何在正确的位置渲染 GPS 层并使其仍然在 SelectFeature 控件中?
提前致谢!
经过几个小时的搜索,我终于发现 GPS 层在初始化时将其 "ratio" 设置为 1.2。
这个层曾经是一个WMS层(继承自Grid),所以设置它的比率意味着:
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.
但是比率对于矢量图层来说还有其他含义:
ratio {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map.
在默认比例为 1 的情况下,它呈现在正确的位置!感谢评论者的意见。