ali safa
ali safa

Reputation: 1

Select Location on Open Layers map by marker or icon

I am new in Open Layers. I want to get location from user by setting marker or icon in Open Layers and get location using Angular.

Upvotes: 0

Views: 869

Answers (1)

Solomon
Solomon

Reputation: 169

This will create a marker on click and you can read the location of it

let vectorLayer = new ol.layer.Vector({
    source: new ol.source.Vector(),
});

map.addLayer(vectorLayer);
    
    

map.on('click', function (evt) {
           let marker = new ol.Feature(new ol.geom.Point(evt.coordinate));
    marker.setStyle(
        new ol.style.Style({
            image: new ol.style.Circle({
                radius: 50,
                fill: new ol.style.Fill({color: 'red'})
            })
        })
    );
    vectorLayer.getSource().addFeature(marker);
        });

Upvotes: 0

Related Questions