Changing markers on the mapbox without reinitialising the map
up vote
0
down vote
favorite
I have a mapbox map with some markers and I want,depending on some onclick events,to remove them and add others without generating again the map.
By the way the div of the map is just a simple div:
<div id="map" class="map" style='width: 100%; height: 900px;display:block;'><div>
My method:
var mapPopupsJS = L.mapbox.map('map', 'mapbox.streets', {minZoom: 3})
.setView([ 44.4267674,26.1025384 ], 5 );
function setMarkers(){
switch(vm.country){
case 0:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJson').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 179:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonRO').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 93:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCR').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 95:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonHU').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 17:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 189:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSL').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 22:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBG').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 13:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonDE').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 53:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 191:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSK').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
}}
setMarkers();
In the beginning the vm.country is 0 so I go on the first case.Ignore those $ signs,I'm working on linux and when I copy pase from nano...you know...there is no problem with this line of code.
When I run this code I don't get any erros.I have all the markers for the first time and when the vm.country changes markers changes BUT the only bad thing is that the map is blank.Literally white...only the markers are displayed and I don't know why.
Can you help me please?
Thank you!
javascript leaflet mapbox mapbox-gl-js mapbox-gl
add a comment |
up vote
0
down vote
favorite
I have a mapbox map with some markers and I want,depending on some onclick events,to remove them and add others without generating again the map.
By the way the div of the map is just a simple div:
<div id="map" class="map" style='width: 100%; height: 900px;display:block;'><div>
My method:
var mapPopupsJS = L.mapbox.map('map', 'mapbox.streets', {minZoom: 3})
.setView([ 44.4267674,26.1025384 ], 5 );
function setMarkers(){
switch(vm.country){
case 0:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJson').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 179:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonRO').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 93:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCR').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 95:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonHU').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 17:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 189:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSL').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 22:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBG').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 13:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonDE').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 53:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 191:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSK').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
}}
setMarkers();
In the beginning the vm.country is 0 so I go on the first case.Ignore those $ signs,I'm working on linux and when I copy pase from nano...you know...there is no problem with this line of code.
When I run this code I don't get any erros.I have all the markers for the first time and when the vm.country changes markers changes BUT the only bad thing is that the map is blank.Literally white...only the markers are displayed and I don't know why.
Can you help me please?
Thank you!
javascript leaflet mapbox mapbox-gl-js mapbox-gl
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a mapbox map with some markers and I want,depending on some onclick events,to remove them and add others without generating again the map.
By the way the div of the map is just a simple div:
<div id="map" class="map" style='width: 100%; height: 900px;display:block;'><div>
My method:
var mapPopupsJS = L.mapbox.map('map', 'mapbox.streets', {minZoom: 3})
.setView([ 44.4267674,26.1025384 ], 5 );
function setMarkers(){
switch(vm.country){
case 0:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJson').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 179:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonRO').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 93:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCR').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 95:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonHU').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 17:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 189:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSL').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 22:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBG').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 13:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonDE').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 53:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 191:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSK').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
}}
setMarkers();
In the beginning the vm.country is 0 so I go on the first case.Ignore those $ signs,I'm working on linux and when I copy pase from nano...you know...there is no problem with this line of code.
When I run this code I don't get any erros.I have all the markers for the first time and when the vm.country changes markers changes BUT the only bad thing is that the map is blank.Literally white...only the markers are displayed and I don't know why.
Can you help me please?
Thank you!
javascript leaflet mapbox mapbox-gl-js mapbox-gl
I have a mapbox map with some markers and I want,depending on some onclick events,to remove them and add others without generating again the map.
By the way the div of the map is just a simple div:
<div id="map" class="map" style='width: 100%; height: 900px;display:block;'><div>
My method:
var mapPopupsJS = L.mapbox.map('map', 'mapbox.streets', {minZoom: 3})
.setView([ 44.4267674,26.1025384 ], 5 );
function setMarkers(){
switch(vm.country){
case 0:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJson').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 179:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonRO').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 93:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCR').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 95:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonHU').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 17:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 189:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSL').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 22:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonBG').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 13:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonDE').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 53:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonCS').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
case 191:
mapPopupsJS.eachLayer(function (layer) {
mapPopupsJS.removeLayer(layer);
});
var myLayer = L.mapbox.featureLayer().loadURL('/getGeoJsonSK').addTo(mapPopupsJS);
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
var content = '<p><strong>' + feature.properties.title + '</strong><br></p><img src="' + feature.properties.image + '" alt="IMAGE UNAVAILABLE" onerror="onImgError(th$
marker.bindPopup(content);
});
mapPopupsJS.scrollWheelZoom.enable();
break;
}}
setMarkers();
In the beginning the vm.country is 0 so I go on the first case.Ignore those $ signs,I'm working on linux and when I copy pase from nano...you know...there is no problem with this line of code.
When I run this code I don't get any erros.I have all the markers for the first time and when the vm.country changes markers changes BUT the only bad thing is that the map is blank.Literally white...only the markers are displayed and I don't know why.
Can you help me please?
Thank you!
javascript leaflet mapbox mapbox-gl-js mapbox-gl
javascript leaflet mapbox mapbox-gl-js mapbox-gl
asked Nov 4 at 10:00
G.Emilian
527
527
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139589%2fchanging-markers-on-the-mapbox-without-reinitialising-the-map%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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