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