Skip to content

Feature Request -Hide Marker Icon until Map Is Clicked #27

@bbehling

Description

@bbehling

It would be helpful if we had an option to not show the Marker Icon until the map is clicked.

I was able to override this behavior in the L.Draw.Marker._onMouseMove Event by setting the opacity of the marker to 0.

L.Draw.Marker = L.Draw.Marker.extend({
_onMouseMove: function (e) {
var latlng = e.latlng;
this._tooltip.updatePosition(latlng);
this._mouseMarker.setLatLng(latlng);

    if (!this._marker) {
        this._marker = new L.Marker(latlng, {
            icon: this.options.icon,
            zIndexOffset: this.options.zIndexOffset,
            opacity: 0, //Override: Hide marker
        });
        // Bind to both marker and map to make sure we get the click event.
        this._marker.on('click', this._onClick, this);
        this._map
			.on('click', this._onClick, this)
			.addLayer(this._marker);
    }
    else {
        latlng = this._mouseMarker.getLatLng();
        this._marker.setLatLng(latlng);
    }
}

});

However, it would seem more feasible to do something like changing:

if (!this._marker)

to

if (!this._marker && this.options.showMarkerOnMouseMove)

Use case here is quite simple...we don't see the marker until the map is clicked, similar to the polygon draw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions