<!doctype html>
<html lang="en">
<script>
/**
* 此页面是一个HelloWord 以及Operlayers的控件显示
*/
</script>
<head>
<meta charset='utf-8'/>
<title>OpenLayers1</title>
<script type="text/javascript" src="static/js/ol-debug.js"> </script>
<link rel="stylesheet" type="text/css" href="static/css/ol.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.mouse-position-wrapper{
width:300px;
height:29px;
color:lightslategrey;
position:absolute;
right:20px;
bottom:6px;
z-index:999;
}
/**
* 旋转控件的样式位置
*/
.ol-rotate{
right:40px;
}
/**
* 比例尺控件显示位置
*/
.ol-scale-line {
left:100px;
}
/**
* 缩放到图层控件的位置
*/
.ol-zoomslider{
top:100px;
left: 9px;
}
</style>
<script type="text/javascript">
// 初始化地图
var map;
$(function(){
init();
});
function init(){
// 初始化地图参数
map = new ol.Map({
target: 'map',// DOM中地图容器的id
layers: [ ],// 图层可以在地图初始化一起进行初始化也可以后期通过addLayer方法进行添加
view:new ol.View({ // 视图
center:[12723401,3578457],// 设置地图中心坐标点
zoom:8,// 设置初始化显示层级
minZoom:7,// 最小显示层级
maxZoom:14 // 最大显示层级
}),
//控件
controls: ol.control.defaults().extend([
/**
* new ol.control.FullScreen(), 全屏控件
* new ol.control.MousePosition() 鼠标位置控件
* new ol.control.OverviewMap() 全局地图控件
* new ol.control.Rotate({ autoHide:false })地图旋转控件
* new ol.control.ScaleLine({ }) 比例尺控件
* new ol.control.ZoomToExtent({ }) 缩放到图层控件
*/
new ol.control.FullScreen(),
new ol.control.MousePosition({
coordinateFormat : ol.coordinate.createStringXY(4),
projection : 'EPSG:4326',
className:'custom-mouse-position',//样式
target:document.getElementById('mouse-position')//显示位置
}),
new ol.control.OverviewMap(),
new ol.control.Rotate({
autoHide:false
}),
new ol.control.ZoomSlider({ }),
new ol.control.ZoomToExtent({ }),
new ol.control.ScaleLine({ })
])
});
//创建一个使用Open Street Map地图源的瓦片图层
var tilelayers = new ol.layer.Tile({ source:new ol.source.OSM() });
map.addLayer(tilelayers);
}
</script>
</head>
<body>
<div id='map' style='width:100%;height:100%;'>
</div>
<!--显示坐标的HTML元素-->
<div id="mouse-position" class="mouse-position-wrapper">
<div class="custom-mouse-position"></div>
</div>
</body>
</html>
<html lang="en">
<script>
/**
* 此页面是一个HelloWord 以及Operlayers的控件显示
*/
</script>
<head>
<meta charset='utf-8'/>
<title>OpenLayers1</title>
<script type="text/javascript" src="static/js/ol-debug.js"> </script>
<link rel="stylesheet" type="text/css" href="static/css/ol.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.mouse-position-wrapper{
width:300px;
height:29px;
color:lightslategrey;
position:absolute;
right:20px;
bottom:6px;
z-index:999;
}
/**
* 旋转控件的样式位置
*/
.ol-rotate{
right:40px;
}
/**
* 比例尺控件显示位置
*/
.ol-scale-line {
left:100px;
}
/**
* 缩放到图层控件的位置
*/
.ol-zoomslider{
top:100px;
left: 9px;
}
</style>
<script type="text/javascript">
// 初始化地图
var map;
$(function(){
init();
});
function init(){
// 初始化地图参数
map = new ol.Map({
target: 'map',// DOM中地图容器的id
layers: [ ],// 图层可以在地图初始化一起进行初始化也可以后期通过addLayer方法进行添加
view:new ol.View({ // 视图
center:[12723401,3578457],// 设置地图中心坐标点
zoom:8,// 设置初始化显示层级
minZoom:7,// 最小显示层级
maxZoom:14 // 最大显示层级
}),
//控件
controls: ol.control.defaults().extend([
/**
* new ol.control.FullScreen(), 全屏控件
* new ol.control.MousePosition() 鼠标位置控件
* new ol.control.OverviewMap() 全局地图控件
* new ol.control.Rotate({ autoHide:false })地图旋转控件
* new ol.control.ScaleLine({ }) 比例尺控件
* new ol.control.ZoomToExtent({ }) 缩放到图层控件
*/
new ol.control.FullScreen(),
new ol.control.MousePosition({
coordinateFormat : ol.coordinate.createStringXY(4),
projection : 'EPSG:4326',
className:'custom-mouse-position',//样式
target:document.getElementById('mouse-position')//显示位置
}),
new ol.control.OverviewMap(),
new ol.control.Rotate({
autoHide:false
}),
new ol.control.ZoomSlider({ }),
new ol.control.ZoomToExtent({ }),
new ol.control.ScaleLine({ })
])
});
//创建一个使用Open Street Map地图源的瓦片图层
var tilelayers = new ol.layer.Tile({ source:new ol.source.OSM() });
map.addLayer(tilelayers);
}
</script>
</head>
<body>
<div id='map' style='width:100%;height:100%;'>
</div>
<!--显示坐标的HTML元素-->
<div id="mouse-position" class="mouse-position-wrapper">
<div class="custom-mouse-position"></div>
</div>
</body>
</html>