如果你还没有完成Day01的内容,请先去了解喔!!
阶层
在我们新增座标点在地图上之前,我们需要了解到openlayers中的阶层问题如下
mapvectorsourcefeature点、线、面几何物件js
const map = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], target: 'map', view: new ol.View({ projection: "EPSG:3857", center: ol.proj.fromLonLat([120.846642, 23.488793]), zoom: 7.5, maxZoom: 20, minZoom: 5, enableRotation: false, }), controls: []});# 这边要注意阶层与物件的新增let point = new ol.layer.Vector({ source: new ol.source.Vector({ features: [ new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([121, 23])) }) ] })}); # 新增一个layer后别忘了加到地图中,我自己就常常忘记XDmap.addLayer(point);
参考连结
https://github.com/weijung0923/learning-openlayers-micromastery/tree/day02