Marker's note

Hello!

How can i attach a note for a marker?

With this code:

marker = new OpenLayers.Marker(new OpenLayers.LonLat(90,10),icon.clone());
marker.events.register('mousedown', marker, function(evt) { alert(this.icon.url); OpenLayers.Event.stop(evt); });

I put a popup window, but i want a note that will show marker’s coordinates and color, for example.

Regards

I don’t think you can use the Marker functions from OpenLayers for this. Markers in OL are very, very basic. So the solution is to create an OL Feature for each marker and attach an image and onClick properties. Below is an example copied from OpenStreetBugs (looking at other projects who have the same functions is always a good start):

function putMarker(x, y, popupContent, marktype) {
  var iconclone;
  if (marktype == 0) {
    iconclone = icon_error.clone();
  } else if (marktype == 1) {
    iconclone = icon_valid.clone();
  } else {
    iconclone = icon_error.clone();
  }
  var feature = new OpenLayers.Feature(markers, new OpenLayers.LonLat(x, y), {icon:iconclone});
  feature.closeBox = false;
  feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud);
  feature.data.popupContentHTML = popupContent;
  feature.data.overflow = "hidden";
  var marker = feature.createMarker();
  var markerClick = function (evt) {
    currentFeature = this;
    if (clicked) {
      if (currentPopup == this.popup) {
        this.popup.hide();
        clicked = false;
      } else {
        currentPopup.hide();
        showPop(this);
      }
    } else {
      showPop(this);
      clicked = true;
    }
    OpenLayers.Event.stop(evt);
  };
  var markerOver = function (evt) {
    document.body.style.cursor='pointer';
    if (!clicked) showPop(this);
    OpenLayers.Event.stop(evt);
  };
  var markerOut = function (evt) {
    document.body.style.cursor='auto';
    if (!clicked && currentPopup != null) currentPopup.hide();
    OpenLayers.Event.stop(evt);
  };
  marker.events.register("mousedown", feature, markerClick);
  marker.events.register("mouseover", feature, markerOver);
  marker.events.register("mouseout", feature, markerOut);

  layerMarkers.addMarker(marker);
  return feature;
}