cod*_*bot 4 css openlayers angular angular6 openlayers-5
我刚刚开始在我的angular 6中使用openlayers 5,并且按照本教程进行操作,同时也在研究这个SO问题。我的角度分量现在有
import ol-map from 'ol/map';
import ol-xyz from 'ol/source/xyz';
import ol-tile from 'ol/layer/tile';
import ol-view from 'ol/View';
import * as ol-proj from 'ol/proj';
Run Code Online (Sandbox Code Playgroud)
在我班上
olmap: ol-map;
source: ol-xyz;
layer: ol-tile;
view: ol-view;
Run Code Online (Sandbox Code Playgroud)
然后在我的 ngOnInit
this.source = new ol-xyz({
url: 'https://api.tiles.mapbox.com/v4/mapbox.light/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw'
});
this.layer = new ol-tile({
source: this.source
});
this.view = new ol-view({
center: ol-proj.fromLonLat([6.661594, 50.433237]),
zoom: 3,
});
this.olmap = new ol-map({
target: 'map',
layers: [this.layer],
view: this.view
});
Run Code Online (Sandbox Code Playgroud)
这可行,但我不了解openlayers的样式。我将缩放按钮作为简单,无样式的按钮放在地图下面div。我在这里想念什么?如何插入opelayers CSS样式?
谢谢
您需要将OpenLayers样式表添加到文件的styles各个部分angular.json(此配置位于.angular-cli.jsonAngular 6之前)。
OpenLayers 5样式表
node_modules/ol/ol.css
OpenLayers 4样式表
node_modules/openlayers/dist/ol.css
angular.json
{
...
"projects": {
"<project name>": {
...
"architect": {
"build": {
...
"options": {
...
"styles": [
"node_modules/ol/ol.css",
"src/styles.css"
],
...
},
...
},
...
"test": {
...
"options": {
...
"styles": [
"node_modules/ol/ol.css",
"src/styles.css"
],
...
}
},
...
}
},
...
},
...
}
Run Code Online (Sandbox Code Playgroud)