<!DOCTYPE html>
<html> <head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="lib/OpenLayers/ol.css" type="text/css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="lib/OpenLayers/ol.js"></script>
<script src="olStyle/Light.js"></script>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
} .map {
width: 100%;
height: 100%;
background: #f6f6f4;
}
</style>
</head> <body>
<div id="map" class="map" data-id="11"></div>
<script type="text/javascript"> $(function () { InitMap(); AddPolygon();
}) var map;
var layer; //地图初始化
function InitMap() {
//初始化地图
layer = new ol.layer.Vector({
source: new ol.source.Vector(),
overlaps: false,
wrapX: false
}),
style: function (feature, resolution) {
switch (feature.get('layer')) {
case 'poi':
poiStyle.getText().setText(feature.get('name'));
return poiStyle;
case 'boundary': return boundaryStyle;
case 'lawn': return lawnStyle;
case 'road':
roadStyle.getText().setText(feature.get('name'));
return (resolution < 2) ? roadStyle : null;
case 'building':
return buildingStyle(feature, resolution);
case 'other':
otherStyle.getText().setText(feature.get('name'));
return otherStyle;
default: return null;
}
}
}); map = new ol.Map({
layers: [layer],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([120.277, 36.330]),
minZoom: 1,
zoom: 16
})
});
} /*显示并编辑区域**********************************************************************************/ function createLabelStyle(feature) {
//返回一个样式
return new ol.style.Style({
//把点的样式换成ICON图标
fill: new ol.style.Fill({
//填充颜色
color: 'rgba(37,241,239,0.2)'
}),
//图形样式,主要适用于点样式
image: new ol.style.Circle({
//半径大小
radius: 7,
//填充
fill: new ol.style.Fill({
//填充颜色
color: '#e81818'
})
}),
//层
zIndex: 20
});
}; function AddPolygon() { var coordinate = ol.proj.fromLonLat([120.277, 36.330]); var newFeature = new ol.Feature({
geometry: new ol.geom.Point(coordinate)
}); //设置点的样式
newFeature.setStyle(createLabelStyle(newFeature)); //清楚坐标点
//layer.getSource().clear(); //将当前要素添加到矢量数据源中
layer.getSource().addFeature(newFeature);
} </script>
</body> </html>

  

最新文章

  1. 流程开发Activiti 与SpringMVC整合实例
  2. gd库
  3. 云计算之路-阿里云上:13:43-13:44之间RDS故障影响了全站的正常访问
  4. [Docker] docker 基础学习笔记5(共6篇)
  5. svn使用相关问题:eclipse插件,加锁,解锁,偷锁,更新不了,记住密码
  6. linux笔记:linux常用命令-用户管理命令
  7. Android学习笔记(2)
  8. Android中的Handler的机制与用法详解
  9. git操作流程
  10. C# 我的注册表操作类
  11. fastreport.net cdoe 自己的代码
  12. 自己写的一个 java swing 的闹钟
  13. 知乎上看到的关于类.class,对象.getClass
  14. Algorithm --&gt; 邮票连续组合问题
  15. 【转】Javascript全局变量var与不var的区别
  16. python_正则表达式随笔
  17. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.e3mall.search.mapper.ItemMapper.getItemList
  18. 基于jquery二维码生成插件qrcode
  19. oracle中如何修改用户名和密码
  20. Ubuntu 16.04 安装 JDK 1.8

热门文章

  1. 原生servlet项目启动自动加载一个方法
  2. iOS - 一个简单的带标题的图标的实现
  3. javascript 客户端webSocket示例
  4. ubuntu 配置网卡,DNS, iptables
  5. OSCP收集
  6. Webpack中hash、chunkhash和contenthash三者的区别
  7. vue-cli项目引入jquery和bootstrap
  8. 干货!手把手教你使用数据可视化BI软件创建企业变更流程监控大屏
  9. 解决burpsuit 浏览器您的连接不是私密连接的问题
  10. 转载:字符编码简介 ASCII UTF-8 ISO8859-1