react加载iServer底图报错

0 投票

问题:create-react-app脚手架,加载的SuperMap iClient for OpenLayers6版本,报错:

./node_modules/@supermap/iclient-ol/mapping/WebMap.js
Attempted import error: 'VectorTileSuperMapRest' is not exported from 'ol/source' (imported as 'olSource').

基础环境:

1.create-react-app脚手架搭建react环境;

2.npm方式引入css文件;

3.npm 安装ol

依次安装

npm install ol 

npm install @supermap/iclient-openlayers 

4.加载主地图文件

import React from "react";
import Map from "ol/Map";
import View from "ol/View";
import TileLayer from "ol/layer/Tile";
import * as control from "ol/control";
import { Logo, TileSuperMapRest } from "@supermap/iclient-ol";

class AddMap extends React.Component {
  componentDidMount() {
    var url =
      "https://iserver.supermap.io/iserver/services/map-world/rest/maps/World";
    try {
      var map = new Map({
        target: "map",
        controls: control
          .defaults({ attributionOptions: { collapsed: false } })
          .extend([new Logo()]),
        view: new View({
          center: [0, 0],
          zoom: 2,
          projection: "EPSG:4326",
        }),
      });
      var layer = new TileLayer({
        source: new TileSuperMapRest({
          url: url,
          wrapX: true,
        }),
        projection: "EPSG:4326",
      });
      map.addLayer(layer);
    } catch (error) {}
  }

  render() {
    return <div id="map"></div>;
  }
}
export default AddMap;

5.报错

请问这个是什么问题呢?

8月 10 分类:  74次浏览 | 用户: johnforrest 牛刀小试 (211 分)

1个回答

0 投票
您好,看您的报错内容是编译错误,import导入失败,您再重新排查一下您的代码中import部分。
8月 12 用户: 张定祥 锋芒毕露 (354 分)

从官方复制的代码

...