在 OpenLayers 中配置 maxExtent 和 limitExtent 坐标
我对 OpenLayers 和 GeoData 非常陌生;因此,我想我有一个关于使用 OpenLayers 配置地图边界的相当菜鸟的问题。首先,这是我编写的地图代码...
function createMap(containerId){
return new OpenLayers.Map(containerId, {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution:156543.0339,
numZoomLevels:4,
controls: [],
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
restrictExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)
});
}
我有我的地图,并且在其顶部加载了矢量国家/地区形状的 GeoJSON 层。到目前为止,一切都很好。但是,如果我在地图上调用 zoomToMaxExtent
,地图会缩小为视口中心的一个缩略图大小的小图形,而不是填充框架。然后,如果我放大地图,我可以(似乎)在任何方向上无限地平移地图,而不是被限制在地图形状的边缘。
因此,我认为我的 maxExtent
和 restrictExtent
设置出了问题,尽管我不知道它是什么。老实说,我不确定那些巨大的边界数字是什么(在示例代码中找到它们)。本质上,通过经度/纬度坐标,我想我只是想将边界限制为-180、-90、180、90——这应该为地图地理提供一个紧密的框架,对吧?不幸的是,将这些经度/纬度设置为边界参数似乎没有任何作用。任何见解将不胜感激!
I'm very new to OpenLayers and working with GeoData; as such, I think I have a pretty noob question about configuring map bounds with OpenLayers. First, here's the map code I've made up...
function createMap(containerId){
return new OpenLayers.Map(containerId, {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution:156543.0339,
numZoomLevels:4,
controls: [],
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
restrictExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)
});
}
I have my map and I've loaded a GeoJSON layer of vector country shapes on top of it. So far so good. However, if I call zoomToMaxExtent
on the map, the map zooms out to be a little tiny thumbnail-sized graphic in the center of my viewport rather than filling the frame. Then if I zoom in on the map, I can (seemingly) pan the map indefinitely in any direction rather than being constrained at the edges of the map shapes.
So I assume I'm doing something wrong with my maxExtent
and restrictExtent
settings, although I have no idea what it is. To be honest, I'm not sure what those huge bounding numbers are (found them in sample code). Essentially, by Lon/Lat coordinates, I think I'm just trying to restrict bounding to -180, -90, 180, 90 – which should provide a tight frame around the map geography, right? Unfortunately setting those Lon/Lat's to the bounding params don't seem to do anything. Any insight would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论