openLayer / TileLayer /源需要什么类型的文件?

时间:2019-06-19 08:44:47

标签: openlayers openlayers-3 angular-openlayers

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的源代码部分:源代码,我需要提供哪种文件,目前,我有一个文件夹,该文件夹具有不同的栅格图像,该文件夹的名称按此顺序排列:坐标,y坐标),但这给了我错误,错误是:

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

要解决此错误,我需要在源代码中提供的类型,这对我有所帮助。

1 个答案:

答案 0 :(得分: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]'
        })
    })
]