【问题标题】:What type of file does the openLayer/TileLayer/source require?openLayer/TileLayer/source 需要什么类型的文件?
【发布时间】:2019-06-19 08:44:47
【问题描述】:
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-坐标,y坐标),但这给了我错误,错误是:

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

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

【问题讨论】:

    标签: openlayers openlayers-3 angular-openlayers


    【解决方案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]'
            })
        })
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-16
      • 2018-06-01
      • 2015-12-23
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多