fuentesloic / cartine

https://fuentesloic.github.io/cartine/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

layerGroup regarded like a simple maker

fuentesloic opened this issue · comments

You code :

  // add the layer to the current federation
  let fedLayer = new InitLayer(federation, lat, lng);
  federations[federation].push(fedLayer);

According your code, you create a new objet each time that you need a marker and you put this new object inside the array federations which have the same federation.
BUT
originally my constructor was considered to create a layerGroup.

class InitLayer {
  constructor(federation, lat, lng) {
    this.federation = federation;
    this.layer = L.layerGroup().addLayer(L.marker([lat, lng]));
  }
}

Now you create a layerGroup for each marker.

I need a number of layerGroup just as much as l have a number of federation (so eleven ... I think).
Because If I have 1000 layerGroup like now, I can't use the controller that is the final goal.

So my idea was to init a layerGroup with the first marker:
this.layer = L.layerGroup().addLayer(L.marker([x, y]));
and after, added a new marker with the federation key
this.layer = L.layerGroup().addLayer(L.marker([x, y]).addLayer(L.marker([x1, y1]));
and so on

Maybe you have thinking to something that I don't understand ??

I haven't.
Then why can't you just:

  if (!(federation in federations)) {
    federations[federation] = L.layerGroup();
  }
  federations[federation].addLayer(L.marker([lat, lng]);

It would dramastically simplify and you wouldn't event need the InitLayer() thing

ONLY SHIT !!!!!!!!

I guess you mean "Holy shit!" ;)

that was between "holy shit" and "only that shit" ... I pretty sad because I don't find out the solution by myself ... I was so far far away ^^ that was so simple but I could not figured that will work ...