How would I clear all markers from map?










0















This is a function with which I add the markers to the map:



function markersresult() 
a++;
var addressPoints = count;

markers = L.markerClusterGroup(
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
iconCreateFunction: function(cluster)
return new L.DivIcon(
iconSize: new L.Point(20, 20)
);

);

for (var i = 0; i < addressPoints.length; i++)
var a = addressPoints[i];
var marker = L.circleMarker(L.latLng(a[0], a[1]));
markers.addLayer(marker);
marker.on('click', function(e)
$('#results').modal('show');
$("#results .modal-body").html("<p>1 Risultato</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
var curPos = e.target.getLatLng();
$("#longiTude").val(curPos.lng);
$("#latiTude").val(curPos.lat);
var lat = e.target.getLatLng().lat;
var lng = e.target.getLatLng().lng;
);


map.addLayer(markers);

//count = ;
markers.on('clusterclick', function(a)
console.log('cluster ' + a.layer.getAllChildMarkers().length);
var childrenMarkerCluster = a.layer.getAllChildMarkers();
var lat = null;
var lng = null;
$.each(childrenMarkerCluster, function(ind, marker)
var markerPosition = marker.getLatLng();
if (lat === null && lng === null)
// store the coordinates of first marker
lat = markerPosition.lat;
lng = markerPosition.lng;
childrenMarkerInSamePosition = true;
$("#longiTude").val(lng);
$("#latiTude").val(lat);
else
);

$('#results').modal('show');
$("#results .modal-body").html("<p>" + a.layer.getAllChildMarkers().length + " risultati</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
);



On click on this button markers should clear:



$("#riprova").on("click", function()
// REMOVE MARKERS
);


I am not sure where I should do this markers.clearMarkers(); as within the button click gives me




markers.clearMarkers is not a function











share|improve this question
























  • What is typeof(markers) inside your click handler?

    – Phylogenesis
    Nov 14 '18 at 16:11















0















This is a function with which I add the markers to the map:



function markersresult() 
a++;
var addressPoints = count;

markers = L.markerClusterGroup(
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
iconCreateFunction: function(cluster)
return new L.DivIcon(
iconSize: new L.Point(20, 20)
);

);

for (var i = 0; i < addressPoints.length; i++)
var a = addressPoints[i];
var marker = L.circleMarker(L.latLng(a[0], a[1]));
markers.addLayer(marker);
marker.on('click', function(e)
$('#results').modal('show');
$("#results .modal-body").html("<p>1 Risultato</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
var curPos = e.target.getLatLng();
$("#longiTude").val(curPos.lng);
$("#latiTude").val(curPos.lat);
var lat = e.target.getLatLng().lat;
var lng = e.target.getLatLng().lng;
);


map.addLayer(markers);

//count = ;
markers.on('clusterclick', function(a)
console.log('cluster ' + a.layer.getAllChildMarkers().length);
var childrenMarkerCluster = a.layer.getAllChildMarkers();
var lat = null;
var lng = null;
$.each(childrenMarkerCluster, function(ind, marker)
var markerPosition = marker.getLatLng();
if (lat === null && lng === null)
// store the coordinates of first marker
lat = markerPosition.lat;
lng = markerPosition.lng;
childrenMarkerInSamePosition = true;
$("#longiTude").val(lng);
$("#latiTude").val(lat);
else
);

$('#results').modal('show');
$("#results .modal-body").html("<p>" + a.layer.getAllChildMarkers().length + " risultati</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
);



On click on this button markers should clear:



$("#riprova").on("click", function()
// REMOVE MARKERS
);


I am not sure where I should do this markers.clearMarkers(); as within the button click gives me




markers.clearMarkers is not a function











share|improve this question
























  • What is typeof(markers) inside your click handler?

    – Phylogenesis
    Nov 14 '18 at 16:11













0












0








0








This is a function with which I add the markers to the map:



function markersresult() 
a++;
var addressPoints = count;

markers = L.markerClusterGroup(
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
iconCreateFunction: function(cluster)
return new L.DivIcon(
iconSize: new L.Point(20, 20)
);

);

for (var i = 0; i < addressPoints.length; i++)
var a = addressPoints[i];
var marker = L.circleMarker(L.latLng(a[0], a[1]));
markers.addLayer(marker);
marker.on('click', function(e)
$('#results').modal('show');
$("#results .modal-body").html("<p>1 Risultato</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
var curPos = e.target.getLatLng();
$("#longiTude").val(curPos.lng);
$("#latiTude").val(curPos.lat);
var lat = e.target.getLatLng().lat;
var lng = e.target.getLatLng().lng;
);


map.addLayer(markers);

//count = ;
markers.on('clusterclick', function(a)
console.log('cluster ' + a.layer.getAllChildMarkers().length);
var childrenMarkerCluster = a.layer.getAllChildMarkers();
var lat = null;
var lng = null;
$.each(childrenMarkerCluster, function(ind, marker)
var markerPosition = marker.getLatLng();
if (lat === null && lng === null)
// store the coordinates of first marker
lat = markerPosition.lat;
lng = markerPosition.lng;
childrenMarkerInSamePosition = true;
$("#longiTude").val(lng);
$("#latiTude").val(lat);
else
);

$('#results').modal('show');
$("#results .modal-body").html("<p>" + a.layer.getAllChildMarkers().length + " risultati</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
);



On click on this button markers should clear:



$("#riprova").on("click", function()
// REMOVE MARKERS
);


I am not sure where I should do this markers.clearMarkers(); as within the button click gives me




markers.clearMarkers is not a function











share|improve this question
















This is a function with which I add the markers to the map:



function markersresult() 
a++;
var addressPoints = count;

markers = L.markerClusterGroup(
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
iconCreateFunction: function(cluster)
return new L.DivIcon(
iconSize: new L.Point(20, 20)
);

);

for (var i = 0; i < addressPoints.length; i++)
var a = addressPoints[i];
var marker = L.circleMarker(L.latLng(a[0], a[1]));
markers.addLayer(marker);
marker.on('click', function(e)
$('#results').modal('show');
$("#results .modal-body").html("<p>1 Risultato</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
var curPos = e.target.getLatLng();
$("#longiTude").val(curPos.lng);
$("#latiTude").val(curPos.lat);
var lat = e.target.getLatLng().lat;
var lng = e.target.getLatLng().lng;
);


map.addLayer(markers);

//count = ;
markers.on('clusterclick', function(a)
console.log('cluster ' + a.layer.getAllChildMarkers().length);
var childrenMarkerCluster = a.layer.getAllChildMarkers();
var lat = null;
var lng = null;
$.each(childrenMarkerCluster, function(ind, marker)
var markerPosition = marker.getLatLng();
if (lat === null && lng === null)
// store the coordinates of first marker
lat = markerPosition.lat;
lng = markerPosition.lng;
childrenMarkerInSamePosition = true;
$("#longiTude").val(lng);
$("#latiTude").val(lat);
else
);

$('#results').modal('show');
$("#results .modal-body").html("<p>" + a.layer.getAllChildMarkers().length + " risultati</p><button id='goToResul' type='button' class='primary-btn'>Go to result</button>");
);



On click on this button markers should clear:



$("#riprova").on("click", function()
// REMOVE MARKERS
);


I am not sure where I should do this markers.clearMarkers(); as within the button click gives me




markers.clearMarkers is not a function








javascript jquery leaflet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 15:54









Rory McCrossan

244k29212248




244k29212248










asked Nov 14 '18 at 15:12









rob.mrob.m

3,749113983




3,749113983












  • What is typeof(markers) inside your click handler?

    – Phylogenesis
    Nov 14 '18 at 16:11

















  • What is typeof(markers) inside your click handler?

    – Phylogenesis
    Nov 14 '18 at 16:11
















What is typeof(markers) inside your click handler?

– Phylogenesis
Nov 14 '18 at 16:11





What is typeof(markers) inside your click handler?

– Phylogenesis
Nov 14 '18 at 16:11












1 Answer
1






active

oldest

votes


















1














$("#riprova").on("click", function()
markers.clearLayers();
);


Docs at:



https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers






share|improve this answer

























  • yes I know but where do I put it?

    – rob.m
    Nov 14 '18 at 15:20











  • I've updated the answer - put it where you commented '// REMOVE MARKERS'.

    – peeebeee
    Nov 14 '18 at 15:22











  • it is not removing the markers, I have already tried it

    – rob.m
    Nov 14 '18 at 15:23






  • 1





    Oh ok. Your question doesn't mention that. What happens instead?

    – peeebeee
    Nov 14 '18 at 15:25











  • nothing at all, no error, markers just won't clear

    – rob.m
    Nov 14 '18 at 15:25










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303329%2fhow-would-i-clear-all-markers-from-map%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














$("#riprova").on("click", function()
markers.clearLayers();
);


Docs at:



https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers






share|improve this answer

























  • yes I know but where do I put it?

    – rob.m
    Nov 14 '18 at 15:20











  • I've updated the answer - put it where you commented '// REMOVE MARKERS'.

    – peeebeee
    Nov 14 '18 at 15:22











  • it is not removing the markers, I have already tried it

    – rob.m
    Nov 14 '18 at 15:23






  • 1





    Oh ok. Your question doesn't mention that. What happens instead?

    – peeebeee
    Nov 14 '18 at 15:25











  • nothing at all, no error, markers just won't clear

    – rob.m
    Nov 14 '18 at 15:25















1














$("#riprova").on("click", function()
markers.clearLayers();
);


Docs at:



https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers






share|improve this answer

























  • yes I know but where do I put it?

    – rob.m
    Nov 14 '18 at 15:20











  • I've updated the answer - put it where you commented '// REMOVE MARKERS'.

    – peeebeee
    Nov 14 '18 at 15:22











  • it is not removing the markers, I have already tried it

    – rob.m
    Nov 14 '18 at 15:23






  • 1





    Oh ok. Your question doesn't mention that. What happens instead?

    – peeebeee
    Nov 14 '18 at 15:25











  • nothing at all, no error, markers just won't clear

    – rob.m
    Nov 14 '18 at 15:25













1












1








1







$("#riprova").on("click", function()
markers.clearLayers();
);


Docs at:



https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers






share|improve this answer















$("#riprova").on("click", function()
markers.clearLayers();
);


Docs at:



https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 15:22

























answered Nov 14 '18 at 15:20









peeebeeepeeebeee

1,07911219




1,07911219












  • yes I know but where do I put it?

    – rob.m
    Nov 14 '18 at 15:20











  • I've updated the answer - put it where you commented '// REMOVE MARKERS'.

    – peeebeee
    Nov 14 '18 at 15:22











  • it is not removing the markers, I have already tried it

    – rob.m
    Nov 14 '18 at 15:23






  • 1





    Oh ok. Your question doesn't mention that. What happens instead?

    – peeebeee
    Nov 14 '18 at 15:25











  • nothing at all, no error, markers just won't clear

    – rob.m
    Nov 14 '18 at 15:25

















  • yes I know but where do I put it?

    – rob.m
    Nov 14 '18 at 15:20











  • I've updated the answer - put it where you commented '// REMOVE MARKERS'.

    – peeebeee
    Nov 14 '18 at 15:22











  • it is not removing the markers, I have already tried it

    – rob.m
    Nov 14 '18 at 15:23






  • 1





    Oh ok. Your question doesn't mention that. What happens instead?

    – peeebeee
    Nov 14 '18 at 15:25











  • nothing at all, no error, markers just won't clear

    – rob.m
    Nov 14 '18 at 15:25
















yes I know but where do I put it?

– rob.m
Nov 14 '18 at 15:20





yes I know but where do I put it?

– rob.m
Nov 14 '18 at 15:20













I've updated the answer - put it where you commented '// REMOVE MARKERS'.

– peeebeee
Nov 14 '18 at 15:22





I've updated the answer - put it where you commented '// REMOVE MARKERS'.

– peeebeee
Nov 14 '18 at 15:22













it is not removing the markers, I have already tried it

– rob.m
Nov 14 '18 at 15:23





it is not removing the markers, I have already tried it

– rob.m
Nov 14 '18 at 15:23




1




1





Oh ok. Your question doesn't mention that. What happens instead?

– peeebeee
Nov 14 '18 at 15:25





Oh ok. Your question doesn't mention that. What happens instead?

– peeebeee
Nov 14 '18 at 15:25













nothing at all, no error, markers just won't clear

– rob.m
Nov 14 '18 at 15:25





nothing at all, no error, markers just won't clear

– rob.m
Nov 14 '18 at 15:25

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303329%2fhow-would-i-clear-all-markers-from-map%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党