我是 JavaScript 的新手,我正在评估在项目中使用 OpenLayer 3。
我正在研究关于这个库的一些教程,我对图层概念有以下疑问。
因此,根据我的理解(如果我做错了断言请纠正我)来渲染一个简单的“Hello World” map 示例,我可以有这样的东西:
var view = new ol.View2d({
center: [0,0],
zoom: 0
});
var map = new ol.Map({
target: map, // map is the id of the element in the DOM where the map will be putted
layers: [layer],
view: view // Use the previous defined view object for the settings of this map
});
我还没有在我的电脑上测试这个例子,我已经从这个视频教程中得到它:https://www.youtube.com/watch?v=SPPhpLTkWX8
所以看起来 map 和** View *是分开的
map :是用户与之交互(点击、拖放、绘制、执行操作)的主要对象。
View :包含与如何呈现 map 相关的设置(在这种情况下它是一个二维 map ,其中指定了 map 的中心位置显示和缩放时)。
据我所知,存在这种关注点分离,因为我可以拥有一个 map ,它可以使用不同的 View 对象以不同的方式显示。
这个推理是正确的还是我遗漏了什么?
并且不是第一个大疑问:在教程中显示,前面的代码将 map 显示到浏览器中。好的,但是从哪里拿这张 map ?它是 GoogleMap map 还是什么?这对我来说很晦涩...
然后本教程继续展示图层概念。
所以它显示了创建 Open Street Map 层 ( https://www.openstreetmap.org ) 的代码:
var osm = new ol.layer.Tile({
source: new ol.source.OSM();
});
然后我认为要使用此图层,我必须将其作为元素添加到之前定义到 map 对象中的 layers: [layer] 数组。是否正确?
现在我还不太清楚的是。
什么是图层?它是在特定 map 上添加的附加信息之类的东西,还是一种特殊类型的 map (例如 Google map 或从其他 map 提供商获得的其他类型的 map )。
我认为这是第一个(一些数据在 map 上显示为图层,事实上在 map 对象上我有一个 layers 数组作为字段,其中我想我可以添加不止一层来在此 map 上显示不同的信息)。
但我有这个疑问,因为我无法理解谁是 OpenLayer 中的 map 提供者(谷歌地图或什么?)以及我是否也可以指定一个特定的 map 提供者。
之所以产生这种疑问,是因为我看到使用 OpenLayer 我可以使用 Bing Map 作为图层,但据我所知,Bing Map 是 Bing Map 的 map 提供程序替代品 < strong>Google map 。
var bing= new ol.layer.Tile({
source: new ol.source.BingMaps({
key: API KEY,
style: setted style
})
});
那么具体是如何工作的呢?
最佳答案
一下子有很多问题,让我尝试回答一些:
So from what I have understand there is this separation of concern because I can have a single Map that can be displayed in different way using differents View objects.
Is it this reasoning correct or am I missing something?
其实恰恰相反。不同的 map 可以共享相同的 view .这是一个例子: http://openlayers.org/en/master/examples/side-by-side.html
Ok, but from where is take this map? Is it a GoogleMap map or what? This is pretty obscure for me... ... What is a layer?
map 是图层的集合。层是地理数据集/数据源(例如矢量特征、栅格图 block 和图像)的可视化表示。例如:
var osm = new ol.layer.Tile({
source: new ol.source.OSM();
});
这定义了一个使用 OpenStreetMap 瓦片图像作为源的瓦片层。如果您将源替换为 ol.source.BingMaps
,您的图层将使用来自 Bing 的图 block 图像。
But I have this doubt because I can't understand who is the map provider in OpenLayer (Google Maps or what?) and if I can also speciy a specific Map Provider.
This doubt is also generated because I have see that using OpenLayer I can use Bing Map as layer but from what I know Bing Map is a map provider alternative to Google Maps.
OpenLayers 是一个用于创建交互式 map 的库。 OpenLayers 不是数据提供者,但它允许使用来自不同提供者的数据,例如来自 OpenStreetMap 或 Bing 的图 block 。
Google 有一个 JavaScript 库,即 Google Maps JavaScript API,但 Google 还是其街道 map 和卫星图像图 block 的数据提供商。
我希望这能让它更清楚一点。我建议你看看 OpenLayers 3 Workshop在 mapschool.io和/或 Learning Lunches: How to Make a Map 更好地了解基础知识。
关于javascript - OpenLayer 3 中层的概念究竟是如何使用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34788766/