I am using Leaflet to add 3 markers on a floor plan. It works fine. then I tried to let Math.random to produce the coordinates in pixels every 3 secs, remove the old marker and add a new marker. But I found the setTimeout() doesn't work. I tried many solutions, all failed. Please could you guide?
one more question: the control.scale doesn't work either. The scale is still at the bottomleft and ft bar is still there.
I am using Leaflet to add 3 markers on a floor plan. It works fine. then I tried to let Math.random to produce the coordinates in pixels every 3 secs, remove the old marker and add a new marker. But I found the setTimeout() doesn't work. I tried many solutions, all failed. Please could you guide?
one more question: the control.scale doesn't work either. The scale is still at the bottomleft and ft bar is still there.
<script>
var map = L.map('map', {
crs: L.CRS.Simple,
Zoom: 0,
maxZoom:16,
minZoom: -5
});
var bounds = [[0,0], [1079,2159]]; // [y, x]
var image = L.imageOverlay('officemap.jpeg', bounds).addTo(map);
map.setView( [539,1075], 0); // ([y , x] , zoom)
map.fitBounds(bounds);
//L.control.scale('topleft', '50', 'True', 'False', 'True' ).addTo(map); // doesn't work !!!
L.control.scale().addTo(map);
var yx = L.latLng;
var xy = function(x, y) {
if (L.Util.isArray(x)) { // When doing xy([x, y]);
return yx(x[1], x[0]);
}
return yx(y, x); // When doing xy(x, y);
};
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var sol = xy(1079, 539);
//var mizar = xy(2159, 1079);
//var mizar = xy(getRandomIntInclusive(0, 2159), getRandomIntInclusive(0, 1079));
var kruegerZ = xy(0, 0);
var maker_text="I am good!!!";
//var maker_text_array =['Name:', 'Age:', 'Group:'];
L.marker(sol).addTo(map).bindTooltip( 'Sol');
L.marker(kruegerZ).addTo(map).bindTooltip(maker_text);
//var previous_maker=null;
var current_marker=null;
/*
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
};
*/
var i="100";
var mizar = xy(getRandomIntInclusive(0, 2159), getRandomIntInclusive(0, 1079));
current_marker=L.marker(mizar).addTo(map).bindTooltip(i);
function del_add(){
alter("in set");
map.removeLayer(current_marker);
mizar= xy(getRandomIntInclusive(0, 2159), getRandomIntInclusive(0, 1079));
current_marker=L.marker(mizar).addTo(map).bindTooltip("I am OK");
};
//for(var j=0; j<10; j++){
setTimeout("del_add()", 100);
//};
//alert("done");
// var travel = L.polyline([sol, deneb]).addTo(map);
</script>