6

我刚开始在我的 angular 6 中使用 openlayers 5,我按照本教程进行操作,并且还在查看这个 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 的样式。我在 map 下将缩放按钮作为简单的无样式按钮div。我在这里想念什么?如何插入 opelayers css 样式?

谢谢

在此处输入图像描述

4

1 回答 1

10

您需要将 OpenLayers 样式表添加到文件的styles各个部分angular.json此配置在.angular-cli.jsonAngular 6 之前)。

OpenLayers 5/6 样式表
node_modules/ol/ol.css

OpenLayers 4 样式表
node_modules/openlayers/dist/ol.css

角.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"
            ],
            ...
          }
        },
        ...
      }
    },
    ...
  },
  ...
}
于 2018-08-03T09:55:32.347 回答