0
import { Component, OnInit } from '@angular/core';
import {Map} from'ol';
import TileLayer from 'ol/layer/Tile';
import Stamen from 'ol/source/Stamen';
import View from 'ol/View';
import {transform} from 'ol/proj';
import Zoomify from 'ol/source/Zoomify';
import Projection from 'ol/proj/Projection';
const hongkong =  transform([114.15769,22.28552], 'EPSG:4326', 'EPSG:3857');

@Component({
  selector: 'app-own-tile',
  templateUrl: './own-tile.component.html',
  styleUrls: ['./own-tile.component.css']
})
export class OwnTileComponent implements OnInit {  
  map: Map;
  width = 512;
  height = 512;

constructor() 
{ 
}

  ngOnInit() {    
let url = '/assets/jp2';    
this.map = new Map({
      target: 'map',
      layers: [
        new TileLayer({
          source: url
    })  
      ],
      view: new View({
        center: [0, 0],
        zoom: 0
      })
    });

  }

}

我的问题是关于 TileLayer 的源部分:源,我需要提供什么样的文件,目前我有一个包含不同光栅图像的文件夹,文件夹的名称按以下顺序排列:(zoomlevel,x-coordinate,y -coordinate) 但这给了我错误,错误是:

TypeError:无法在字符串“/assets/jp2”上创建属性“ol_lm”

为了解决这个错误,我需要我需要在源代码中提供的类型,如果我能对此有所了解,将会很有帮助。

4

1 回答 1

1

Layer 对象需要来自 OpenLayers 库的“源”对象,在您的情况下应该是 xyz 源:


import TileLayer from 'ol/layer/Tile'
import XYZSource from 'ol/source/XYZ'

layers: [
    new TileLayer({
        source: new XYZSource({
            url: 'path/to/tiles/{z}/{x}/{y}.[png/jpg/etc]'
        })
    })
]
于 2019-06-23T15:30:52.033 回答