如何用OpenLayers画矩形

Gemma_Lemon 2015-12-08 08:29:27
<!DOCTYPE html>
<html>
<head>
<title>Graticule example</title>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.11.2/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.11.2/build/ol.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
</div>
<script>
var map = new ol.Map({
view:new ol.View({
center:[36,56],
zoom:5,
maxZoom:28
}),
layers:[
new ol.layer.Tile({
source:new ol.source.OSM({
layer:'osm'}),
opacity:0.9,
zIndex:5
})

],
target:'map'
});

var rectangular = new ol.Feature(
new ol.geom.Polygon([[[36,29],[36,129],[99,129],[99,29],[36,29]]])
);

var featureOverlay= new ol.layer.Vector({
source:new ol.source.Vector({features:[rectangular]
}),
style:new ol.style.Style({
fill:new ol.style.Fill({
color:'rgba(255,255,255,0.2)'
}),
stroke:new ol.style.Stroke({
color:'#ffcc33',
width:2
}),
image:new ol.style.Circle({
radius:7,
fill:new ol.style.Fill({
color:'#ffcc33'
})
})
})
});
featureOverlay.setMap(map);
</script>
</body>
</html>
这是我的代码,但是为什么不能够显示矩形,是哪里出错了呀,跪求大神指点呐....帮帮忙....谢谢
...全文
905 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
了然无一 2019-10-13
  • 打赏
  • 举报
回复
大佬这个栅格的点击事件怎么写啊,能否加个微信,yuan370403
qq_35580840 2016-12-08
  • 打赏
  • 举报
回复
我想知道问题解决了吗

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧