L.Control.extend < Link

59 views
Skip to first unread message

Jm d

unread,
Sep 29, 2023, 2:09:34 PM9/29/23
to Leaflet
Hello Everyone

I've created a L.Control.extend.
I would like when I click on : exit the page and return to index page.

My code

L.Control.ExitCarto = L.Control.extend({
onAdd: function(map)
{
        var img = L.DomUtil.create('img');
img.src = 'Marqueurs/stop.png';
img.style.width = '18';
img.id = 'stop';
        return img;
}
});

L.control.ExitCarto = function(opts) {return new L.Control.ExitCarto(opts);}
L.control.ExitCarto({ position: 'topright'}).addTo(Rcarte);

var sortir = document.getElementById('stop');
sortir.addEventListener('click', function ()
{
var a = document.createElement('a');
a.id = 'sortir';
a.href = '../index.php';
sortir.appendChild(a);
document.body.appendChild(a);
console.log(a);
alert('click 02');
});

Alert is ok and console.log also ( <a id="sortir" href="../index.php">).
But nothing is happening.

Any idea ?
Thanks for your help.
Jean Michel

Jm d

unread,
Sep 30, 2023, 3:10:29 AM9/30/23
to Leaflet
Hi everyone

I've founded : create a DIV create a BUTTON and put it in the  DIV and create an IMAGE and put it in the BUTTON 
All is good now.

Jean Michel

Edwin Corrigan

unread,
Sep 30, 2023, 8:45:19 AM9/30/23
to leafl...@googlegroups.com
Hi Jean Michel,

I'm not fully sure what you're trying to do, but I think you want 'index.php' to open when you click the 'stop' image? 

The code to do that is in the attached html file. When coffee image is clicked google.com will open.

If I've missed what you're looking for, please update the index.html file to show me what you're trying to do


--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leaflet-js/7eaa5715-c317-4342-9cfd-a67dcfe4ec04n%40googlegroups.com.
index.html

Jm d

unread,
Sep 30, 2023, 10:47:56 AM9/30/23
to Leaflet
Hi
Here is my code to create a button with link to return to "Home page". (see attached file)
I've always the problem : click is seen on console but not active.

Jean Michel

L.Control.Quitter = L.Control.extend(
{
options: {position: 'topright'},
onAdd: function(map)
{
var link = L.DomUtil.create('a','my-link-class');
var div = L.DomUtil.create('div', 'leaflet-bar my-control',link);
div.title = "Menu principal";
var myButton = L.DomUtil.create('button', '', div);
link.href = "....return to index page....";
let myImage = L.DomUtil.create('img', 'my-button-class', myButton);
myImage.src = "Marqueurs/stop2.png";
myImage.style = "margin-left:0px;margin-top:2px;width:20px;height:20px";
L.DomEvent.disableClickPropagation(div);
L.DomEvent.on(div, 'click', function()
{
console.log('click');
});

return div;  
},
onRemove: function(map) {}
});
var control = new L.Control.Quitter()
control.addTo(Rcarte);
Button Exit.png

Jm d

unread,
Sep 30, 2023, 12:14:17 PM9/30/23
to Leaflet
Hi M. Corrigan
Many thanks.much simpler than I thought. It"s ok now

Jean Michel

Le samedi 30 septembre 2023 à 14:45:19 UTC+2, Edwin Corrigan a écrit :
Reply all
Reply to author
Forward
0 new messages