【发布时间】:2020-04-07 00:54:15
【问题描述】:
我想在简单的角度网站中显示地图。 component.ts 的代码是
import { Component, OnInit } from '@angular/core';
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import {OSM, TileDebug} from 'ol/source';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
constructor() { }
ngOnInit(): void {
var map = new Map({
layers: [
new TileLayer({
source: new OSM()
}),
new TileLayer({
source: new TileDebug()
})
],
target: 'mapdiv',
view: new View({
center: [0, 0],
zoom: 1
})
});
}
}
component.html 的代码是
<div id = 'mapdiv'></div>
地图显示在浏览器 (Chrome) 上,但不可移动(可拖动)。
【问题讨论】:
-
澄清一下,您正在查看地图,包括 OSM 和调试,但您不能平移?
-
是的。地图可见,但无法平移和放大。
标签: angular typescript components maps openlayers