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

Snapping between intersection of two different layers don't work #1552

Open
rezw4n opened this issue Jan 6, 2025 · 2 comments
Open

Snapping between intersection of two different layers don't work #1552

rezw4n opened this issue Jan 6, 2025 · 2 comments
Labels
needs decision Pro ⭐ Related to Leaflet-Geoman Pro ⭐

Comments

@rezw4n
Copy link

rezw4n commented Jan 6, 2025

Hello, I'm using Geoman Pro for our organization. I was trying to draw a circle of a specific radius and then use the split tool to split a polygon starting from the intersection of that circle and polygon, but the intersection of those two layers is not snappable. Is there a solution for this issue?
chrome_vx92lDWwwe

We were hoping that the intersection would be something like this: Stackoverflow Answer

@Falke-Design
Copy link
Collaborator

This is currently not implemented. We will discuss internally if we want to implement this feature.

As workaround you can use following:

<script src="https://cdn.jsdelivr.net/npm/sweepline-intersections@2.0.1/dist/sweeplineIntersections.min.js"></script>
function createIntersectionPoints(layers) {
  // calculate instersection points between layers
  const intersectionPointLayers = [];
  for (let i = 0; i < layers.length; i += 1) {
    const layer = layers[i];
    if (layer instanceof L.Polyline) {
      for (let j = i + 1; j < layers.length; j += 1) {
        const otherLayer = layers[j];
        if (otherLayer instanceof L.Polyline && layer !== otherLayer) {
          const layerGroup = L.layerGroup([layer, otherLayer]);
          sweeplineIntersections(layerGroup.toGeoJSON(), true).forEach(
            (lnglat) => {
              console.log(lnglat);
              intersectionPointLayers.push(
                L.marker([lnglat[1], lnglat[0]], {
                  pmIgnore: true,
                  snapIgnore: false,
                })
              );
            }
          );
        }
      }
    }
  }
  return intersectionPointLayers;
}

// For Draw modes
map.pm.Draw.getShapes().forEach((shape) => {
  map.pm.Draw[shape]._createSnapList = function () {
    // it doesn't matter from which prototype _createSnapList is called
    L.PM.Draw.Line.prototype._createSnapList.call(this);
    this._snapList = this._snapList.concat(
      createIntersectionPoints(this._snapList)
    );
  };
});

// for created layers in edit mode
map.on('pm:create', ({ layer }) => {
  layer.pm._createSnapList = function () {
    // it doesn't matter from which prototype _createSnapList is called
    L.PM.Draw.Line.prototype._createSnapList.call(this);
    this._snapList = this._snapList.concat(
      createIntersectionPoints(this._snapList)
    );
  };
});

@Falke-Design Falke-Design added Pro ⭐ Related to Leaflet-Geoman Pro ⭐ needs decision labels Jan 7, 2025
@rezw4n
Copy link
Author

rezw4n commented Feb 13, 2025

This is currently not implemented. We will discuss internally if we want to implement this feature.

As workaround you can use following:

<script src="https://cdn.jsdelivr.net/npm/sweepline-intersections@2.0.1/dist/sweeplineIntersections.min.js"></script>
function createIntersectionPoints(layers) {
  // calculate instersection points between layers
  const intersectionPointLayers = [];
  for (let i = 0; i < layers.length; i += 1) {
    const layer = layers[i];
    if (layer instanceof L.Polyline) {
      for (let j = i + 1; j < layers.length; j += 1) {
        const otherLayer = layers[j];
        if (otherLayer instanceof L.Polyline && layer !== otherLayer) {
          const layerGroup = L.layerGroup([layer, otherLayer]);
          sweeplineIntersections(layerGroup.toGeoJSON(), true).forEach(
            (lnglat) => {
              console.log(lnglat);
              intersectionPointLayers.push(
                L.marker([lnglat[1], lnglat[0]], {
                  pmIgnore: true,
                  snapIgnore: false,
                })
              );
            }
          );
        }
      }
    }
  }
  return intersectionPointLayers;
}

// For Draw modes
map.pm.Draw.getShapes().forEach((shape) => {
  map.pm.Draw[shape]._createSnapList = function () {
    // it doesn't matter from which prototype _createSnapList is called
    L.PM.Draw.Line.prototype._createSnapList.call(this);
    this._snapList = this._snapList.concat(
      createIntersectionPoints(this._snapList)
    );
  };
});

// for created layers in edit mode
map.on('pm:create', ({ layer }) => {
  layer.pm._createSnapList = function () {
    // it doesn't matter from which prototype _createSnapList is called
    L.PM.Draw.Line.prototype._createSnapList.call(this);
    this._snapList = this._snapList.concat(
      createIntersectionPoints(this._snapList)
    );
  };
});

I tried this, but it causes out-of-memory crash. Is there any other alternative solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision Pro ⭐ Related to Leaflet-Geoman Pro ⭐
Projects
None yet
Development

No branches or pull requests

2 participants