Openlayers - 禁用图层上的平移
我正在使用 OpenLayers,并尝试创建一个信息覆盖层。 我使用自己的 WMS 服务器,因此对于这一层,服务器始终发送包含信息的图像。 我的问题是,当我平移地图时,我的“信息”图层也会平移,一旦完成平移,该图层就会刷新并且文本会显示在正确的位置。 我想禁用此特定图层(WMS)上的平移,有什么方法可以实现此目的吗?
我尝试使用外部 div 但没有成功,平移仍然存在。
谢谢 !
编辑: 这就是我带来的。它运行完美,谢谢你的想法
<script type="text/javascript">
/////////////////////////////////////////
// USE AN EMPTY LAYER WITH ATTRIBUTION //
/////////////////////////////////////////
var informationLayerRefreshStrategy = new OpenLayers.Strategy.Refresh({
interval: 10000,
force:true,
refresh: function() {
if (this.layer) {
this.layer.attribution = "Data loading ...";
// Load new attributions
var layer = this.layer;
$.ajax({
url: "myURL",
success: function(data){
layer.attribution = data;
map.getControlsByClass("OpenLayers.Control.Attribution")[0].updateAttribution();
},
global: false
});
}
}
});
var informationLayer = new OpenLayers.Layer(
"Sans fond de plan",
{attribution:"Data loading ..."});
informationLayerRefreshStrategy.setLayer(informationLayer);
informationLayerRefreshStrategy.activate();
</script>
I'm using OpenLayers and I'm trying to create an information overlay layer.
I'm using my own WMS server, so for this layer, the server always send an image with informations in it.
My problem is that when I pan the Map, my "information" layer also pan, once finished panning, the layer is refreshed and the text is displayed in the right position.
I would like to disable panning on this particular layer (WMS), is there any way to achieve this ?
I tried with an external div but didn't succeed, the panning was still there.
Thanks !
Edit:
So here is what I've come with. It works perfectly, thanks for the idea
<script type="text/javascript">
/////////////////////////////////////////
// USE AN EMPTY LAYER WITH ATTRIBUTION //
/////////////////////////////////////////
var informationLayerRefreshStrategy = new OpenLayers.Strategy.Refresh({
interval: 10000,
force:true,
refresh: function() {
if (this.layer) {
this.layer.attribution = "Data loading ...";
// Load new attributions
var layer = this.layer;
$.ajax({
url: "myURL",
success: function(data){
layer.attribution = data;
map.getControlsByClass("OpenLayers.Control.Attribution")[0].updateAttribution();
},
global: false
});
}
}
});
var informationLayer = new OpenLayers.Layer(
"Sans fond de plan",
{attribution:"Data loading ..."});
informationLayerRefreshStrategy.setLayer(informationLayer);
informationLayerRefreshStrategy.activate();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的结论:使用仅包含归因值的单独图层。对可以配置为使用 JSON 的单独资源进行查询。在refreshStrategy中,仅使用结果数据更新图层的属性,并设置生成的属性div的样式以显示在地图的正确位置。
My conclusion: Use a separate layer that only contains the attribution values. Do your querying to a separate resource that you could configure to use JSON. In the refreshStrategy, only update the Attribution for the layer with the resulting data, and style the generated attribution div to display on the correct place with regards to your map.