即使使用 DragRotateAndZoom 交互,我的地图也不会随着 openlayers 6.2 和 angular 9 移动
My map won't move with openlayers 6.2 and angular 9, even with DragRotateAndZoom interaction
我正在尝试创建地图,正如我在其他网站和示例中看到的那样,每个人都可以通过鼠标单击和拖动来移动他们的地图。但是我的地图根本不会移动,有人知道我做错了什么吗?
这些是我正在使用的 components.ts 和 component.html 文件。我按照 https://openlayers.org/en/latest/doc/tutorials/bundle.html 上的说明操作,但没有安装 parcel,因为我使用的是 angular.
map.component.ts
ngOnInit(): void {
this.mapInit();
}
mapInit() {
var mousePositionControl = new MousePosition({
coordinateFormat: createStringXY(4),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var source = new OSM();
var overviewMapControl = new OverviewMap({
layers: [
new TileLayer({
source: source
})
]
});
this.map = new Map({
target: 'map',
interactions: defaultInteractions().extend([
new DragRotateAndZoom
]),
layers: [
new TileLayer({
source: source
}),
],
view: new View({
center: fromLonLat([19.833549, 45.267136]),
zoom: 7
}),
controls: defaultControls().extend([
overviewMapControl,
new FullScreen(),
mousePositionControl,
new ZoomToExtent({
extent: [
813079.7791264898, 5929220.284081122,
848966.9639063801, 5936863.986909639,
]
})
])
});
地图.component.html
<html lang="en">
<head>
<title>Drag, Rotate, and Zoom</title>
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<div id="mouse-position"></div>
</body>
</html>
这与本期相同:https://github.com/openlayers/openlayers/issues/10663
ol.css 的最新版本未包含在 HTML 中。
添加:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css">
我正在尝试创建地图,正如我在其他网站和示例中看到的那样,每个人都可以通过鼠标单击和拖动来移动他们的地图。但是我的地图根本不会移动,有人知道我做错了什么吗?
这些是我正在使用的 components.ts 和 component.html 文件。我按照 https://openlayers.org/en/latest/doc/tutorials/bundle.html 上的说明操作,但没有安装 parcel,因为我使用的是 angular.
map.component.ts
ngOnInit(): void {
this.mapInit();
}
mapInit() {
var mousePositionControl = new MousePosition({
coordinateFormat: createStringXY(4),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var source = new OSM();
var overviewMapControl = new OverviewMap({
layers: [
new TileLayer({
source: source
})
]
});
this.map = new Map({
target: 'map',
interactions: defaultInteractions().extend([
new DragRotateAndZoom
]),
layers: [
new TileLayer({
source: source
}),
],
view: new View({
center: fromLonLat([19.833549, 45.267136]),
zoom: 7
}),
controls: defaultControls().extend([
overviewMapControl,
new FullScreen(),
mousePositionControl,
new ZoomToExtent({
extent: [
813079.7791264898, 5929220.284081122,
848966.9639063801, 5936863.986909639,
]
})
])
});
地图.component.html
<html lang="en">
<head>
<title>Drag, Rotate, and Zoom</title>
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<div id="mouse-position"></div>
</body>
</html>
这与本期相同:https://github.com/openlayers/openlayers/issues/10663
ol.css 的最新版本未包含在 HTML 中。
添加:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css">