javascript - Angular 2 Leaflet Tiles 巨大间隙

标签 javascript css angular sass leaflet

在我的 Angular 2 应用程序之外使用相同的配置,传单加载正常,但这就是 Angular 2 中发生的情况:

如果我移动 map ,则会加载不同的图 block ,但同样的问题仍然存在。

html:

<div class="leaflet-maps" id="map"></div>

组件:

    let el = this._elementRef.nativeElement.querySelector('.leaflet-maps');

    let map = L.map("map", {
        zoomControl: false,
        center: L.latLng(37.8, -96),
        zoom: 5,
        minZoom: 4,
        maxZoom: 19
    });

    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);

我已通过以下方式加载传单 css 文件:

styleUrls: ['./maps.component.scss']

我粘贴传单 css 内容的位置

/* required styles */

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,

....

enter image description here

最佳答案

这解决了我的问题:

import { Component, ViewEncapsulation} from '@angular/core';

@Component({
    selector: 'maps',
    templateUrl: 'maps.component.html',
    styleUrls: ['./maps.component.scss'],
    encapsulation: ViewEncapsulation.None  // <--
})

关于javascript - Angular 2 Leaflet Tiles 巨大间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42144763/

相关文章:

javascript - React JS 追加

html - 枢轴图标不可点击

php - 如何做另一个 Action ,但仍然在 cakephp 的浏览器中显示相同的 url

javascript - 如何将 'selective-input' 设置为 Angular 中的表单字段?

html - Angular Material 努力调整对话框元素的宽度

javascript - 如何将数组上的更改反射(reflect)到 lit-element 中渲染的 html 中?

javascript - 从 JSONP 中提取函数的 JSON 参数

javascript - 使用 Three.js 在 3D 场景中绘制不规则的水

html - 根据数据库值将不同的背景颜色设置为部分

angular - AWS Cognito Angular 示例 : URIError: URI malformed