<!DOCTYPE html>
<html>
<head>
<title>Accessible Map</title>
<link rel="stylesheet" href="https://openlayers.org/en/v3.20.1/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script
src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL">
</script>
<script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script>
<style>
a.skiplink {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
padding: 0;
border: 0;
height: 1px;
width: 1px;
overflow: hidden;
}
a.skiplink:focus {
clip: auto;
height: auto;
width: auto;
background-color: #fff;
padding: 0.3em;
}
#map:focus {
outline: #4A74A8 solid 0.15em;
}
</style>
</head>
<body>
<div id="map" class="map" tabindex="0"></div>
<script>
var map = new ol.Map({
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([106.359506, 26.302920]),
zoom: 6
}),
layers: [
// 底图
new ol.layer.Tile({
source: new ol.source.OSM()
})
]
})
//起点
var startPoint = [
{
"lon": 106.359506,
"lat": 26.302920
},
{
"lon": 106.62741873770544,
"lat": 26.621248800337924
},
{
"lon": 106.62904814,
"lat": 26.622542270337924
},
{
"lon": 106.62728025,
"lat": 26.622559845418413
},
{
"lon": 106.62916610,
"lat": 26.6204520337924
}
];
//终点
var endPoint = [{
"lon": 107.66656545,
"lat": 36.032545411
}];
var startName = '起点';
//添加时钟源图标
var ClockIconData = [{
"lon": 106.62825793,
"lat": 26.62167320
}]
var startIconLayers = []
for(var i = 0; i < startPoint.length; i++){
// 将点转换成地图识别的格式
var coordinate = ol.proj.transform([startPoint[i].lon, startPoint[i].lat], 'EPSG:4326', 'EPSG:3857')
var startIconFeatures = [];
startIconFeatures[0] = new ol.Feature({
geometry: new ol.geom.Point(coordinate)
});
var startIconLayer = // 基站图标图层
new ol.layer.Vector({
source: new ol.source.Vector({
features: startIconFeatures
}),
style: new ol.style.Style({
image: new ol.style.Icon({
src: 'anchor.png'
}),
text: new ol.style.Text({
text: '基站--------'+ i,
scale: 1.3,
fill: new ol.style.Fill({
color: '#000000'
}),
stroke: new ol.style.Stroke({
color: '#FFFF99',
width: 3.5
})
})
})
})
startIconLayers.push(startIconLayer);
}
for(var i = 0; i< startIconLayers.length ;i++){
map.addLayer(startIconLayers[i]);
}
function addStartAndEnd(startPoint, IconName) {
// 遍历得到点的集合
var startIconFeatures = []
var clockNamelist = []
for (var i = 0; i < startPoint.length; i++) {
// 将点转换成地图识别的格式
var coordinate = ol.proj.transform([startPoint[0].lon, startPoint[0].lat], 'EPSG:4326', 'EPSG:3857')
startIconFeatures[i] = new ol.Feature({
geometry: new ol.geom.Point(coordinate)
})
}
var startIconLayer = // 基站图标图层
new ol.layer.Vector({
source: new ol.source.Vector({
features: startIconFeatures
}),
style: new ol.style.Style({
image: new ol.style.Icon({
src: 'anchor.png'
}),
text: new ol.style.Text({
text: IconName,
scale: 1.3,
fill: new ol.style.Fill({
color: '#000000'
}),
stroke: new ol.style.Stroke({
color: '#FFFF99',
width: 3.5
})
})
})
})
return startIconLayer;
}
map.addLayer(addStartAndEnd(startPoint, '起点'))
map.addLayer(addStartAndEnd(endPoint, '终点'))
</script>
</body>
</html>
openlayers画几个图标
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 加载geoJson数据的两种方法 sprite图标渲染 resolution为分辨率/img/sprite.png...
- 1.问题背景:一般在写轨迹回放的时候,车辆行进方向会有一个朝向的问题,这个需要实时计算,不断修正车子前进方向。2....
- 记录一个使用canvas 将一张图片等比缩放,裁剪为一个圆 1、原始图片 2、绘制后在地图中呈现的样式 3、设置...