How would I clear all markers from map?
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
// if it has already gotten a result false, stop the compare
if (childrenMarkerInSamePosition === false)
return;
if (markerPosition.lat !== lat
);
$('#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
add a comment |
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
// if it has already gotten a result false, stop the compare
if (childrenMarkerInSamePosition === false)
return;
if (markerPosition.lat !== lat
);
$('#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
What istypeof(markers)
inside your click handler?
– Phylogenesis
Nov 14 '18 at 16:11
add a comment |
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
// if it has already gotten a result false, stop the compare
if (childrenMarkerInSamePosition === false)
return;
if (markerPosition.lat !== lat
);
$('#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
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
// if it has already gotten a result false, stop the compare
if (childrenMarkerInSamePosition === false)
return;
if (markerPosition.lat !== lat
);
$('#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
javascript jquery leaflet
edited Nov 14 '18 at 15:54
Rory McCrossan
245k29212248
245k29212248
asked Nov 14 '18 at 15:12
rob.mrob.m
3,791113983
3,791113983
What istypeof(markers)
inside your click handler?
– Phylogenesis
Nov 14 '18 at 16:11
add a comment |
What istypeof(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
add a comment |
1 Answer
1
active
oldest
votes
$("#riprova").on("click", function()
markers.clearLayers();
);
Docs at:
https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers
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
|
show 4 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$("#riprova").on("click", function()
markers.clearLayers();
);
Docs at:
https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers
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
|
show 4 more comments
$("#riprova").on("click", function()
markers.clearLayers();
);
Docs at:
https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers
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
|
show 4 more comments
$("#riprova").on("click", function()
markers.clearLayers();
);
Docs at:
https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers
$("#riprova").on("click", function()
markers.clearLayers();
);
Docs at:
https://github.com/Leaflet/Leaflet.markercluster#adding-and-removing-markers
edited Nov 14 '18 at 15:22
answered Nov 14 '18 at 15:20
peeebeeepeeebeee
1,07711219
1,07711219
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
|
show 4 more comments
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
|
show 4 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What is
typeof(markers)
inside your click handler?– Phylogenesis
Nov 14 '18 at 16:11