<!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>
<script src="point.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 = new ol.layer.Vector({
source: new ol.source.Vector(),
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(0, 0, 0, 0.3)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 2
}),
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
}); //地图初始化
function InitMap() {
map = new ol.Map({
layers: [new ol.layer.Vector({
source: new ol.source.Vector(),
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;
}
}
}), layer],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([120.277, 36.330]),
minZoom: 1,
zoom: 16
})
});
} /*显示并编辑区域**********************************************************************************/
function AddPolygon() {
var coordinates = [[
ol.proj.fromLonLat([120.26829957962033, 36.32791869064661]),
ol.proj.fromLonLat([120.27445793151853, 36.330650012922234]),
ol.proj.fromLonLat([120.2671408653259, 36.33063272637348]),
ol.proj.fromLonLat([120.26829957962033, 36.32791869064661])
]] var plygon = new ol.geom.Polygon(coordinates)
//多边形要素类
var feature = new ol.Feature({
geometry: plygon
}); layer.getSource().addFeature(feature); //标注,当使用多边形时,自动计算中心坐标?
//标注,如果使用文字标注,图形将会被文字覆盖
var featureText = new ol.Feature({
geometry: plygon,
name: "标注1"
}); featureText.setStyle(new ol.style.Style({
//文本样式
text: new ol.style.Text({
//对齐方式
textAlign: 'center',
//文本基线
textBaseline: 'middle',
//字体样式
font: 'normal 14px 微软雅黑',
//文本内容
text: featureText.get('name')
})
})) layer.getSource().addFeature(featureText); //清除
//layer.getSource().clear(); var points = [[
ol.proj.fromLonLat([120.27681827545163, 36.33236136226455]),
ol.proj.fromLonLat([120.28038024902342, 36.33141061727086]),
ol.proj.fromLonLat([120.27681827545163, 36.33001040806349]),
ol.proj.fromLonLat([120.27681827545163, 36.33236136226455])
]] var plygon2 = new ol.geom.Polygon(points)
//多边形要素类
var feature2 = new ol.Feature({
geometry: plygon2
}); layer.getSource().addFeature(feature2); //标注,当使用多边形时,自动计算中心坐标?
//标注,如果使用文字标注,图形将会被文字覆盖
var featureText2 = new ol.Feature({
geometry: plygon2,
name: "标注2"
}); featureText2.setStyle(new ol.style.Style({
//文本样式
text: new ol.style.Text({
//对齐方式
textAlign: 'center',
//文本基线
textBaseline: 'middle',
//字体样式
font: 'normal 14px 微软雅黑',
//文本内容
text: featureText2.get('name')
})
})) layer.getSource().addFeature(featureText2);
} </script>
</body> </html>

  

openlayers图层加标注的更多相关文章

  1. Openlayers Overlay加载gif图片

    说明: 项目中使用vector图层做图片撒点功能,发现加载gif没有效果.网上查找资料发现,openlayers不支持gif图片样式. 后面采用overlay的方式,gif图片赋值给DOM元素 解决方 ...

  2. Android GIS开发系列-- 入门季(15) 网络图层加载

    一.首先我们来看一个网络图层: http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer,这是全 ...

  3. OpenLayers 3加载本地Google切片地图

    OpenLayers  提供了ol.source.XYZ 接口用以加载切片地图. 本地切片地图是用地图切片下载器下载的Google道路图层,由于软件未激活,所以每张切片地图上都有软件作者的联系方式,请 ...

  4. openlayers 3加载GeoServer发布的wfs类型服务

    转:https://blog.csdn.net/u013323965/article/details/52449502 问题产生:      openlayer3加载WFS存在跨域问题,需要用json ...

  5. OpenLayers图层

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  6. 使用openlayers 3 在线加载天地图及GeoServer发布的地图

    使用openlayers3来加载天地图卫星图和标注图层,GeoServer发布地图,一并用openlayers测试加载出来,顺便实现了7种地图控件.下面直接贴代码: <!DOCTYPE html ...

  7. (转)Openlayers 2.X加载天地图

    http://blog.csdn.net/gisshixisheng/article/details/44621923 概述: 在前面的章节,讲到了Arcgis for js加载天地图,在本节讲述如何 ...

  8. 通过openlayers加载dwg格式的CAD图并与互联网地图叠加

    Openlayers介绍 ​ Openlayers是一个基于Javacript开发,免费.开源的前端地图开发库,使用它,可以很容易的开发出WebGIS系统.目前Openlayers支持地图瓦片.矢量数 ...

  9. MeteoInfoLab脚本示例:加载地图图层

    应用最广泛的的地图数据应该是shape格式,网络上有很多免费下载资源.MeteoInfoLab中读取shape文件的函数是shaperead,参数即文件名,返回数据包含图形和属性信息的图层对象.矢量图 ...

随机推荐

  1. LwIP与IPv6

    2.0.0中才开始支持IPv6,在此版本中改写了SNMP,但还没有IPv6的统计量.目前最新版本是2.0.2,其中SNMP也没有IPv6统计量(哪些?与IP的统计量有何区别?) 1.4.1中虽然有ip ...

  2. mongo操作备忘

    #查看collection内 某个字段条目数 db.dictionary_system.find({"name":"xxx"}).count() #清空某个co ...

  3. light oj1028 - Trailing Zeroes (I)

    1028 - Trailing Zeroes (I)   We know what a base of a number is and what the properties are. For exa ...

  4. C#后台异步消息队列实现

    简介 基于生产者消费者模式,我们可以开发出线程安全的异步消息队列. 知识储备 什么是生产者消费者模式? 为了方便理解,我们暂时将它理解为垃圾的产生到结束的过程. 简单来说,多住户产生垃圾(生产者)将垃 ...

  5. 简化MVVM属性设置和修改 - .NET CORE(C#) WPF开发

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简化MVVM属性设置和修改 - .NET CORE(C#) WPF开发 阅读导航 常用类属性设 ...

  6. GitLab Container Registry

    通过将GitLab Container Registry集成到GitLab中,每个项目都可以拥有自己的空间来存储其Docker镜像. 1. 启用Container Registry 如果在你的项目的侧 ...

  7. 源码浅析:InnoDB聚集索引如何定位到数据的物理位置,并从磁盘读取

    索引结构概述: MyISAM索引文件和数据文件是分离的,索引文件仅保存数据记录的地址.这与Oracle的索引结构相似,比较好理解.那么,常用的Innodb聚集索引结构是怎样的呢? InnoDB的数据文 ...

  8. hive中parquet存储格式数据类型timestamp的问题

    当存储格式为parquet 且 字段类型为 timestamp 且 数据用hive执行sql写入. 这样的字段在使用impala读取时会少8小时.建议存储为sequence格式或者将字段类型设置为st ...

  9. Spring Boot JPA分页 PageRequest报错

    在使用Spring Boot JPA分页 PageRequest分页时,出现如下错误: 本来以为是包导入出现了问题,结果发现并不是.导入包如下: 后来在网上查找相关资料,发现这样的用法,好像也可以用, ...

  10. CMD命令下图片合成一句话木马命令

    非常简单,我们只需要一张图片1.jpg一句话木马写好的php文件 1.php之后我们进入到命令行.注意:将php文件和图片文件放到同一目录下,cmd也要跳转到放文件的目录下之后执行命令 copy .j ...