Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bringToBack issues #165

Open
mivilleb opened this issue Apr 20, 2020 · 1 comment
Open

bringToBack issues #165

mivilleb opened this issue Apr 20, 2020 · 1 comment

Comments

@mivilleb
Copy link

If I used this to get the a geojson polygon layer, the bringToBack works when I toggle the layer on and off:

Partial code:

. . .

var vaisigano_catchment = L.geoJson(null ,{
style: polystyle,
zindex: -999,
});

$.getJSON("data/vaisigano_catchment.geojson",function(data){
vaisigano_catchment.addData(data);
});

var map = L.map('map', {
    center: [-13.9,-171.7],
    zoom: 14,
    layers: [osm,obs_status,vaisigano_catchment]
});

. . .

map.on('overlayadd', function(e) {
    vaisigano_catchment.bringToBack();
});

If I use L.realtime instead of L.geojson, the call for bringToBack says it is not a function:

var vaisigano_catchment = L.realtime({
  url: 'data/vaisigano_catchment.geojson',
  crossOrigin: true,
  type: 'json'
}, {
   interval: 5 * 1000,
  onEachFeature: function (feature, latlng) {

   var level = feature.properties.Labels;

  if (level > 0) {

    var polygon = L.polygon(latlng._latlngs, {
      color: 'blue',
      opacity: 0.3,
      fillOpacity: 0.1
    }).addTo(map);
 } else if (level == 1) {

    var polygon = L.polygon(latlng._latlngs, {
      color: 'red',
      opacity: 0.3,
      fillOpacity: 0.1
    }).addTo(map);
 }
 return polygon;
}
});

vaisigano_catchment.on('update', function(e) {
  map.fitBounds(vaisigano_catchment.getBounds(), {maxZoom: 14});

  Object.keys(e.update).forEach(function(id) {
   var level = feature.properties.Labels;

  if (level > 0) {

    var polygon = L.polygon(latlng._latlngs, {
      color: 'blue',
      opacity: 0.3,
      fillOpacity: 0.1
    }).addTo(map);
 } else if (level == 1) {

    var polygon = L.polygon(latlng._latlngs, {
      color: 'red',
      opacity: 0.3,
      fillOpacity: 0.1
    }).addTo(map);
 }
 return polygon;
}.bind(this));
});

var map = L.map('map', {
    center: [-13.9,-171.7],
    zoom: 14,
    layers: [osm,obs_status,vaisigano_catchment]
});

. . .

map.on('overlayadd', function(e) {
    vaisigano_catchment.bringToBack();
});

What do I have to do to make bringtoBack work when using realtime?

@perliedman
Copy link
Owner

It's correct that the realtime layer does not have bringToFront/bringToBack. It would not be too hard to add those, and maybe also eachLayer would be useful.

Help to add these would be welcome, I no longer actively work with this plugin, so it's not likely I will do it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants