一個地圖初步就這樣完成了。css
具體參考文檔:http://weilin.me/ol3-primer/ch12/12-01-01.htmlhtml
而後就是配置:node
其中的view center 設置就是顯示某一局部的中心,就是限制顯示局部區域。git
先定義map,而後把後臺數據好比圖片,經緯度等放入this.nodeData.set(name,value),npm
而後在其餘地方就經過this.nodeData.get(name)能拿到feature。api
let feature = map.forEachFeatureAtPixel(event.pixel, function (feature, layer) { return feature; });
這段代碼放到點擊事件內能夠轉換能夠拿到當前feature的經緯度,圖片類型,也能夠拿到當前feature的id. 能夠進行路由跳轉等。
let line = new Feature({ id: id, geometry: new LineString( [[sLongitude, sLatitude], [eLongitude, eLatitude]]) }); line.setStyle(new Style({ text: new Text({ // 默認這個字體,能夠修改爲其餘的,格式和css的字體設置同樣 font: '16px sans-serif', text: lineName, placement: 'line', textBaseline: 'top', fill: new Fill({ color: color ? color : 'blue' }) }), stroke: new Stroke({ width: color === 'red' ? 2 : 1, color: color ? color : 'blue' }) })); // 添加到以前的建立的layer中去 this.layer.addFeature(line);
詳細請參考此中文文檔: http://weilin.me/ol3-primer/index.html字體