Code: Select all
var marker1;
var marker2;
var visible;
var nonvisible;
$(function () {
$('input.leaflet-control-findspot').on('click', _findtheSPot);
});
_findtheSPot = function () {
/////////i still figure out this code below to remove the marker,nothing error showed////////
if (mymap.hasLayer(visible)) {
mymap.removeLayer(visible);
}
if (mymap.hasLayer(nonvisible)) {
mymap.removeLayer(nonvisible);
}
var visible = L.layerGroup().addTo(mymap);
var nonvisible = L.layerGroup().addTo(mymap);
/////////i still figure out this code above to remove the marker,nothing error showed////////
$.ajax({
type: "POST",
data: {
arrayraw: solararray,
lat: objlat,
long: objlng,
objheight: document.getElementById('leaflet-control-inputOheight').value
},
cache: false,
url: "php/ujicoba.php",
dataType: "json",
beforeSend: function () {
$("#route-loading").show();
},
success: function (data) {
$("#route-loading").hide();
/////////this code uses an array to show the marker in the map////////
for (var i = 0; i < data.length; i++) {
if (data[i].ket == "visible") {
L.marker([data[i].lat, data[i].long], { icon: L.icon(icontargetMarker1) }).addTo(visible);
} else {
L.marker([data[i].lat, data[i].long], { icon: L.icon(icontargetMarker2) }).addTo(nonvisible);
}
/////////this code uses an array to show the marker in the map////////
}
}
,
error: function () {
$("#route-loading").hide();
alert('Failed to get server respond');
}
});
Code: Select all
if (mymap.hasLayer(visible)) {
mymap.clearLayers();
visible.clearLayers();
}
if (mymap.hasLayer(nonvisible)) {
mymap.clearLayers();
nonvisible.clearLayers();
}