无法以角度获取openlayers CSS

时间:2018-07-30 21:07:21

标签: css angular openlayers angular6 openlayers-5

我刚开始在我的角度6中使用openlayers 5,然后跟随this tutorial并同时观察this SO question。我的角度分量现在有

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';

在我班上

 olmap: ol-map;
 source: ol-xyz;
 layer: ol-tile;
 view: ol-view;

,然后在我的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
});

这可行,但我不了解openlayers的样式。我在地图div下获得了缩放按钮,它们是简单,无样式的按钮。我在这里想念什么?如何插入opelayers CSS样式?

谢谢

enter image description here

1 个答案:

答案 0 :(得分:4)

您需要将OpenLayers样式表添加到styles文件的angular.json部分(此配置位于Angular 6之前的.angular-cli.json)。 / p>

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"
            ],
            ...
          }
        },
        ...
      }
    },
    ...
  },
  ...
}