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
})
});
}
}
My question is for the source part of the TileLayer: source, what kind of file do i need to provide, currently i have a folder with different raster images with name of the folder being in this order: (zoomlevel,x-coordinate,y-coordinate) but this gives me error and the error is:
TypeError: Cannot create property 'ol_lm' on string '/assets/jp2'
To solve this error i need the type i need to provide in source and would be helpful is i could get some insight on this.
The Layer object needs a "source" object from the OpenLayers lib, which in your case should be an xyz source:
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]'
})
})
]