I'm using the OpenLayers 5 for my project in angular 6. I implemented it to show a map and it is working :-). But I can't make it show any markers, please help me!!! Show examples with this version OpenLayers...
import OlMap from 'ol/Map';
import OlXYZ from 'ol/source/XYZ';
import OlTileLayer from 'ol/layer/Tile';
import OlView from 'ol/View';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import {fromLonLat} from 'ol/proj';
export class MyComponent implements OnInit {
map: OlMap;
source: OlXYZ;
layer: OlTileLayer;
view: OlView;
marker: Feature;
ngOnInit() {
this.marker = new Feature({
geometry: new Point([27.46164, 53.902257])
});
this.source = new OlXYZ({
url: 'http://tile.osm.org/{z}/{x}/{y}.png',
features: [this.marker]
});
this.layer = new OlTileLayer({
source: this.source
});
this.view = new OlView({
center: fromLonLat([27.56164, 53.902257]),
zoom: 14
});
this.map = new OlMap({
target: 'map',
layers: [this.layer],
view: this.view
});
}
}
You need a vector layer and a vector source to add features. Something like the following: