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!










share|improve this question


























    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!










    share|improve this question
























      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!










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 4 at 10:00









      G.Emilian

      527




      527





























          active

          oldest

          votes











          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',
          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%2f53139589%2fchanging-markers-on-the-mapbox-without-reinitialising-the-map%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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




















































































          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings