首页 / 浏览问题 / 云GIS / 问题详情
react加载iServer底图报错
216EXP 2020年08月10日

问题: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.报错

请问这个是什么问题呢?

1个回答

您好,看您的报错内容是编译错误,import导入失败,您再重新排查一下您的代码中import部分。
2,248EXP 2020年08月12日

从官方复制的代码

...