读书笔记一,openlayer创建地图
步骤:
1.Including the OpenLayers library files
2.Creating an HTML element that the map will appear in
3. Creating a map object from the Map class
4. Creating a layer object from a Layer class
5. Adding the layer to the map
6. Defining the map’s extent (setting the area the map will initially be displaying)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>创建电子地图</title>
<!-- 导入OpenLayers.js -->
<script type="text/javascript" src="scripts/OpenLayers.js"></script>
<script type="text/javascript">
function init(){
//创建一个map对象
//参数1 : div id
//参数2 : options json类型
var map = new OpenLayers.Map("map1",{});
//创建一个Layer(图层)对象
var wms = new OpenLayers.Layer.WMS(
//WMS : Web Map Service
"OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers:"basic"},
{}
);
//把Layer添加到map中
map.addLayer(wms);
if(!map.getCenter()){
//定义地图的缩放级别
map.zoomToMaxExtent();
}
}
</script>
</head>
<body onload="init()">
<!-- 为地图显示创建一个html元素 -->
<div id="map1" style="width:500px;height:500px;"></div>
</body>
</html>
转载自:https://blog.csdn.net/liuchao937/article/details/39348145