css - 无法以 Angular 获取 openlayers css

标签 css angular openlayers angular6 openlayers-5

我刚开始在我的 angular 6 中使用 openlayers 5,我关注 this tutorial也在寻找this SO question .我的 Angular 组件现在有

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 样式?

谢谢

enter image description here

最佳答案

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

OpenLayers 5/6 样式表
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"
            ],
            ...
          }
        },
        ...
      }
    },
    ...
  },
  ...
}

关于css - 无法以 Angular 获取 openlayers css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51602298/

相关文章:

css - 没有填充的输入占位符

angular - 显示:none and *ngIf = 'false' ?有什么区别

javascript - 使用 Open Layers 自动绘制路径的第一个顶点

javascript - 带 OpelLayers 的网络 map ,极坐标投影

javascript - 在openlayers中是否有一种简单的方法来简化绘制的多边形中的顶点?

html - 重叠两个 div 元素

html - 带有 CSS 选择器的表格中的剧透

html - 使位置固定不可滚动

html - 固定图像周围有 "border"

angular - 如何在点击angular2时获取当前索引