OpenLayers3入门篇-创建点和线
转自:https://blog.csdn.net/adventure_xph/article/details/52005413
样例代码-创建点
1.创建Featrue,设置geometry属性
var saoguan = new ol.Feature({
geometry:new ol.geom.Point(ol.proj.fromLonLat([113.5991,24.8166]))
});
2.设置此点的样式
saoguan.setStyle(new ol.style.Style({
image:new ol.style.Icon({
color:'#4271AE',
src:'data/dot.png'
})
})
);
3.传入source
var source = new ol.source.Vector({
features:[saoguan]
});
4.传入layer,设置点
var layer = new ol.layer.Vector({
source: source
});
5.设置底图layer
var rasterLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
6.最后将地图layer和点layer一并传入map中
var map = new ol.Map({
layers: [rasterLayer, layer],
target: document.getElementById('map'),
view: new ol.View({
center: ol.proj.fromLonLat([113.5991,24.8166]),
zoom: 3
})
});
————————————————
版权声明:本文为CSDN博主「adventure_xph」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/adventure_xph/article/details/52005413