要包含我做过的OpenLayers : npm install ol --save
并实施如下:
import React, { Component } from 'react';
import 'ol/ol.css';
import ol from 'ol';
import Map from 'ol/map';
import View from 'ol/view';
import Tile from 'ol/layer/tile';
class MapComponent extends Component {
componentDidMount() {
var map = new ol.Map({
view: new ol.View({
center: [0, 0],
zoom: 1
}),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map'
});
}
render() {
return (
<div id="map"></div>
)
}
}
export default MapComponent;
错误:未捕获的TypeError: WEBPACK_IMPORTED_MODULE_1_ol .a.View不是构造函数
答案 0 :(得分:0)
您已从ol单独导入View。您应该尝试使用:
view: new View({...
同样适用于上面一行的地图。