首页 / 浏览问题 / WebGIS / 问题详情
vue openlayer mvt报错
6EXP 2025年04月02日
报错代码 ol-debug.js:7119 Uncaught TypeError: Cannot read properties of null (reading 'getExtent') at ol.tilegrid.extentFromProjection (ol-debug.js:7119:27) at ol.tilegrid.createForProjection (ol-debug.js:7105:28) at ol.source.VectorTile.getTileGridForProjection (ol-debug.js:81001:52) at CanvasVectorTileLayerRenderer.prepareFrame (TileLayer.js:146:1) at CanvasVectorTileLayerRenderer.prepareFrame (VectorTileLayer.js:143:1) at CanvasMapRenderer.renderFrame (Map.js:157:1) at Map.renderFrame_ (PluggableMap.js:1226:1) at Map.eval (PluggableMap.js:189:1)

1个回答

我的openlayer版本为5.3.3,怎么解决
6EXP 2025年04月02日
methods: {

    initializeMap() {

      var projection = getProjection(this.projection);

      var projectionExtent = projection.getExtent();

      var size = getWidth(projectionExtent) / 256;

      var resolutions = new Array(18);

      var matrixIds = new Array(18);

      for (var z = 1; z < 19; ++z) {

        resolutions[z] = size / Math.pow(2, z);

        matrixIds[z] = z;

      }

      const wmtsUrl_1 = "http://t{0-7}.tianditu.gov.cn/vec_c/wmts?tk=";

      const wmtsUrl_2 = "http://t{0-7}.tianditu.gov.cn/cva_c/wmts?tk=";

      var webKey = "9ac697d71f93e52eff098753a4bcee28";

      this.view = new View({

        center: [112.08, 27.79],

        projection: projection,

        zoom: 8.0

      });

      // Initialize map object

      this.map = new Map({

        controls: [],

        layers: [

          new TileLayer({

            opacity: 0.7,

            source: new WMTS({

              url: wmtsUrl_1 + webKey,

              layer: "vec",

              matrixSet: "c",

              format: "tiles",

              projection: this.projection,

              tileGrid: new WMTSTileGrid({

                origin: getTopLeft(projectionExtent),

                resolutions: resolutions,

                matrixIds: matrixIds

              }),

              wrapX: true

            })

          }),

          new TileLayer({

            opacity: 0.7,

            source: new WMTS({

              url: wmtsUrl_2 + webKey,

              layer: "cva",

              matrixSet: "c",

              format: "tiles",

              projection: this.projection,

              tileGrid: new WMTSTileGrid({

                origin: getTopLeft(projectionExtent),

                resolutions: resolutions,

                matrixIds: matrixIds

              }),

              wrapX: true

            })

          })

        ],

        target: "map",

        view: this.view

      });

      this.loadMVTLayer();

    },

    loadMVTLayer() {

      const styleURL = "http://10.143.1.190:8090/iserver/services/map-mvt-GEO_WELL_P_R/restjsr/v1/vectortile/maps/GEO_WELL_P_R/style.json";

      const layerSource = new ol.source.VectorTileSuperMapRest({

        style: styleURL,

        projection: this.projection,

        format: new ol.format.MVT({

          featureClass: ol.Feature,

        }),

      });

      const style = new ol.supermap.MapboxStyles({

        style: styleURL,

        map: this.map,

      });

      style.on("styleloaded", () => {

        this.vtLayer = new ol.layer.VectorTile({

          declutter: true,

          source: layerSource,

          style: style.getStyleFunction(),

        });

        this.vtLayer.setZIndex(2);

        this.map.addLayer(this.vtLayer);

      });

    }

  },
6EXP 2025年04月02日
...