How to use the ol/geom/Polygon function in ol

To help you get started, we’ve selected a few ol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('splits the given convex polygon geometry with a more complex line', () => {
          const line = new OlFeature({
            geometry: new OlGeomLineString(lineStringLFormedCoords)
          });
          const got = GeometryUtil.splitByLine(poly, line, 'EPSG:4326');
          const exp = [
            new OlFeature({
              geometry: new OlGeomPolygon(splitBoxLFormedCoords1)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(splitBoxLFormedCoords2)
            })
          ];
          expect(format.writeFeatures(got)).toEqual(format.writeFeatures(exp));
        });
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('splits the given convex polygon geometry with a more complex line', () => {
          const line = new OlFeature({
            geometry: new OlGeomLineString(lineStringLFormedCoords)
          });
          const got = GeometryUtil.splitByLine(poly, line, 'EPSG:4326');
          const exp = [
            new OlFeature({
              geometry: new OlGeomPolygon(splitBoxLFormedCoords1)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(splitBoxLFormedCoords2)
            })
          ];
          expect(format.writeFeatures(got)).toEqual(format.writeFeatures(exp));
        });
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('splits the given convex polygon geometry with a more complex line', () => {
          poly = new OlGeomPolygon(boxCoords);
          const line = new OlGeomLineString(lineStringLFormedCoords);
          const got = GeometryUtil.splitByLine(poly, line, 'EPSG:4326');
          const exp = [
            new OlGeomPolygon(splitBoxLFormedCoords1),
            new OlGeomPolygon(splitBoxLFormedCoords2)
          ];
          got.forEach((polygon, i) => {
            expect(polygon.getCoordinates()).toEqual(exp[i].getCoordinates());
          });
        });
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('returns the intersection of two instances of ol.geom.Polygon', () => {
          const poly1 = new OlGeomPolygon(boxCoords);
          const poly2 = new OlGeomPolygon(boxCoords3);
          const intersectionGeometry = GeometryUtil.intersection(poly1, poly2, 'EPSG:4326');
          expect(intersectionGeometry instanceof OlGeomGeometry).toBe(true);
          expect(intersectionGeometry.getCoordinates()).toEqual(intersectionCoords);
        });
        it('returns null if no intersection is found', () => {
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('returns the intersection of two instances of ol.geom.Polygon', () => {
          const poly1 = new OlFeature({
            geometry: new OlGeomPolygon(boxCoords)
          });
          const poly2 = new OlFeature({
            geometry: new OlGeomPolygon(boxCoords3)
          });
          const intersectionFeature = GeometryUtil.intersection(poly1, poly2, 'EPSG:4326');
          expect(intersectionFeature instanceof OlFeature).toBe(true);
          expect(intersectionFeature.getGeometry().getCoordinates()).toEqual(intersectionCoords);
        });
        it('returns null if no intersection is found', () => {
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
it('splits a complex polygon geometry (including hole) with a straight line',() => {
          poly = new OlFeature({
            geometry: new OlGeomPolygon(holeCoords2)
          });
          const line = new OlFeature({
            geometry: new OlGeomLineString(holeCoords2CutLine)
          });
          const got = GeometryUtil.splitByLine(poly, line, 'EPSG:4326');
          const exp = [
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly1)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly2)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly3)
            })
          ];
github Viglino / ol-ext / src / render / Cspline.js View on Github external
ol_geom_Polygon.prototype.calcCSpline_ = function(options)
{	var g=[], g0=this.getCoordinates();
	for (var i=0; i
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.spec.js View on Github external
poly = new OlFeature({
            geometry: new OlGeomPolygon(holeCoords2)
          });
          const line = new OlFeature({
            geometry: new OlGeomLineString(holeCoords2CutLine)
          });
          const got = GeometryUtil.splitByLine(poly, line, 'EPSG:4326');
          const exp = [
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly1)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly2)
            }),
            new OlFeature({
              geometry: new OlGeomPolygon(holeCoords2ExpPoly3)
            })
          ];
          expect(got.length).toBe(3);
          got.forEach((polygon, i) => {
            polygon.getGeometry().getCoordinates()[0].sort().forEach(coord=>{
              coord.forEach(()=>{
                expect(exp[i].getGeometry().getCoordinates()[0].sort()).toContainEqual(coord);
              });
            });
          });
        });
      });
github Viglino / ol-ext / src / source / GeoImage.js View on Github external
ol_source_GeoImage.prototype.calculateExtent = function(usemask) {
  var polygon;
  if (usemask!==false && this.getMask()) {
    polygon = new ol_geom_Polygon([this.getMask()])
  } else {
    var center = this.getCenter();
    var scale = this.getScale();
    var width = this.getGeoImage().width * scale[0];
    var height = this.getGeoImage().height * scale[1];
    var extent = ol_extent_boundingExtent([
      [ center[0]-width/2, center[1]-height/2 ],
      [ center[0]+width/2, center[1]+height/2 ]
    ]);
    polygon = ol_geom_Polygon_fromExtent(extent);
    polygon.rotate(-this.getRotation(), center);
  }
  var ext = polygon.getExtent();
  return ext;
};
github devilesk / dota-interactive-map / src / js / controls / draw.js View on Github external
const dx = center[0] - last[0];
                    const dy = center[1] - last[1];
                    const radius = Math.sqrt(dx * dx + dy * dy);
                    const rotation = Math.atan2(dy, dx);
                    const newCoordinates = [];
                    const numPoints = 12;
                    for (let i = 0; i < numPoints; ++i) {
                        const angle = rotation + i * 2 * Math.PI / numPoints;
                        const fraction = i % 2 === 0 ? 1 : 0.5;
                        const offsetX = radius * fraction * Math.cos(angle);
                        const offsetY = radius * fraction * Math.sin(angle);
                        newCoordinates.push([center[0] + offsetX, center[1] + offsetY]);
                    }
                    newCoordinates.push(newCoordinates[0].slice());
                    if (!geometry) {
                        geometry = new Polygon([newCoordinates]);
                    }
                    else {
                        geometry.setCoordinates([newCoordinates]);
                    }
                    return geometry;
                };
            }