Show label and remove marker from map

quma

I use openStreetMap in my Angular 6 application like below. Add a marker to the map works fine but show a label of the marker if clicked on it does not work and actually I dont know why. Also I have no idea how to remove this marker or how an event is sent if the marker is clicked with a single click. Does anyone have hints how I can do it - I tried a lot but without success.

ngOnInit() {
this.map = new ol.Map({
  target: 'map',
  controls: ol.control.defaults({
    attributionOptions: {
      collapsible: false
    }
  }),
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  view: new ol.View({
    center: ol.proj.fromLonLat([this.latitude, this.longitude]),
    zoom: 10
  })
});

var that = this;
this.map.on('dblclick', function (args) {
  var lonlat = ol.proj.transform(args.coordinate, 'EPSG:3857', 'EPSG:4326');
  var lon = lonlat[0];
  var lat = lonlat[1]; 

  const feature1 = new ol.Feature({
    geometry: new ol.geom.Point(ol.proj.fromLonLat([lon, lat])),
    labelPoint: new ol.geom.Point(ol.proj.fromLonLat([lon, lat])),
    sname: 'My Marker 1'
  });
  const feature2 = new ol.Feature({
    geometry: new ol.geom.Point(ol.proj.fromLonLat([lon+1, lat+1])),
    labelPoint: new ol.geom.Point(ol.proj.fromLonLat([lon+1, lat+1])),
    sname: 'My Marker 2'
  });
  let features = [];
  features.push(feature1);
  features.push(feature2); 

  var layer = new ol.layer.Vector({
      source: new ol.source.Vector({
          features: features
        }),
      style: new ol.style.Style({
          image: new ol.style.Icon({
            anchor: [0.5, 0.5],
            anchorXUnits: "fraction",
            anchorYUnits: "fraction",
            src: "assets/img/marker.png"
          })
        })
    });
  that.map.addLayer(layer);
});
}
cabesuon

You will need a couple of features to achieve your goal,

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android Google Map Marker With Label?

show leaflet marker popup from outside of map dynamically

How can I remove the marker from the map based on the list of locations?

Remove google.maps.marker.AdvancedMarkerView from map

On HighMaps, how do I show state abbreviations instead of state name on a U.S. map and remove data label from point

Show marker to Google Map on Click

How to remove specific multiple marker from google map instead of single or all marker

Remove a marker from a GoogleMap

Hide/show map marker on Here map

How to remove string from ArrayList after show it in a label?

Google map marker label text color change

Label not being added to Google Map marker

Always show map marker title in Android

How to show a FancyBox video on a Google Map marker?

how to show multiple marker on google map android

How to show google map and marker on the same layout?

Google map with marker does not show in android browser

HERE map does not show a local image with a marker

Remove line from marker in legend

Retrieve location from server and show in Google map marker using volley library?

Swift & Firebase: Retrieving location data from Firebase to show on Google map marker

Show multiple marker on google map (API V2 ) from database

Google map marker - Info window needs to remove the marker

How to remove native marker of google map

How to add and remove marker clusters on a leaflet map?

how to remove clusterMark on my marker on Google map?

how to remove previous marker in google map

Cannot remove marker on Google Map (Java)

Remove label from the clone?