How can I add a marker to Open Layers map?

Discussão em 'Angular' iniciado por Emma Gorington, Junho 4, 2025.

  1. Currently building a map app. Trying all the methods I find in the internet to add a marker, still doesn't work. Am I doing it wrong?

    Here's my Angular code:

    Somehow, it's much easier with Leaflet, but I don't want to abandon Open Layers that early.

    export class MapComponent implements OnInit{

    map! : Map;
    marker! :any;
    center = fromLonLat([5.5697, 50.6330]);
    iconFeature = new Feature({
    geometry : new Point(fromLonLat([5.5697, 50.6330]))
    })

    ngOnInit(): void {

    this.map = new Map({
    view : new View({
    center : this.center,
    zoom : 0
    }),
    layers : [

    new LayerVector({
    source : new SourceVector({
    features : [this.iconFeature]
    }),
    style : new Style({
    image : new Icon({
    anchor : [0.5, 46],
    src : '../assets/istockphoto-1153114937-2048x2048-removebg-preview.png'
    })
    })
    })
    new TileLayer({
    source : new OSM()
    })
    ],
    target : "map"
    })
    }

    }

    Continue reading...

Compartilhe esta Página