Named exports instead of static functions from ol/geom/Polygon
This commit is contained in:
@@ -6,7 +6,7 @@ import _ol_GeolocationProperty_ from './GeolocationProperty.js';
|
||||
import _ol_Object_ from './Object.js';
|
||||
import _ol_events_ from './events.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import Polygon from './geom/Polygon.js';
|
||||
import {circular as circularPolygon} from './geom/Polygon.js';
|
||||
import _ol_has_ from './has.js';
|
||||
import {toRadians} from './math.js';
|
||||
import {get as getProjection, getTransformFromProjections, identityTransform} from './proj.js';
|
||||
@@ -167,7 +167,7 @@ Geolocation.prototype.positionChange_ = function(position) {
|
||||
this.set(_ol_GeolocationProperty_.POSITION, projectedPosition);
|
||||
this.set(_ol_GeolocationProperty_.SPEED,
|
||||
coords.speed === null ? undefined : coords.speed);
|
||||
var geometry = Polygon.circular(this.position_, coords.accuracy);
|
||||
var geometry = circularPolygon(this.position_, coords.accuracy);
|
||||
geometry.applyTransform(this.transform_);
|
||||
this.set(_ol_GeolocationProperty_.ACCURACY_GEOMETRY, geometry);
|
||||
this.changed();
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ import _ol_coordinate_ from './coordinate.js';
|
||||
import {inAndOut} from './easing.js';
|
||||
import {getForViewAndSize, getCenter, getHeight, getWidth, isEmpty} from './extent.js';
|
||||
import GeometryType from './geom/GeometryType.js';
|
||||
import Polygon from './geom/Polygon.js';
|
||||
import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
import SimpleGeometry from './geom/SimpleGeometry.js';
|
||||
import {clamp, modulo} from './math.js';
|
||||
import _ol_obj_ from './obj.js';
|
||||
@@ -884,10 +884,10 @@ _ol_View_.prototype.fit = function(geometryOrExtent, opt_options) {
|
||||
24); // Invalid extent or geometry provided as `geometry`
|
||||
assert(!isEmpty(geometryOrExtent),
|
||||
25); // Cannot fit empty extent provided as `geometry`
|
||||
geometry = Polygon.fromExtent(geometryOrExtent);
|
||||
geometry = polygonFromExtent(geometryOrExtent);
|
||||
} else if (geometryOrExtent.getType() === GeometryType.CIRCLE) {
|
||||
geometryOrExtent = geometryOrExtent.getExtent();
|
||||
geometry = Polygon.fromExtent(geometryOrExtent);
|
||||
geometry = polygonFromExtent(geometryOrExtent);
|
||||
geometry.rotate(this.getRotation(), getCenter(geometryOrExtent));
|
||||
} else {
|
||||
geometry = geometryOrExtent;
|
||||
|
||||
+11
-11
@@ -367,6 +367,8 @@ Polygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
|
||||
this.changed();
|
||||
};
|
||||
|
||||
export default Polygon;
|
||||
|
||||
|
||||
/**
|
||||
* Create an approximation of a circle on the surface of a sphere.
|
||||
@@ -380,7 +382,7 @@ Polygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
|
||||
* @return {ol.geom.Polygon} The "circular" polygon.
|
||||
* @api
|
||||
*/
|
||||
Polygon.circular = function(center, radius, opt_n, opt_sphereRadius) {
|
||||
export function circular(center, radius, opt_n, opt_sphereRadius) {
|
||||
var n = opt_n ? opt_n : 32;
|
||||
/** @type {Array.<number>} */
|
||||
var flatCoordinates = [];
|
||||
@@ -393,7 +395,7 @@ Polygon.circular = function(center, radius, opt_n, opt_sphereRadius) {
|
||||
polygon.setFlatCoordinates(
|
||||
GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
|
||||
return polygon;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -402,7 +404,7 @@ Polygon.circular = function(center, radius, opt_n, opt_sphereRadius) {
|
||||
* @return {ol.geom.Polygon} The polygon.
|
||||
* @api
|
||||
*/
|
||||
Polygon.fromExtent = function(extent) {
|
||||
export function fromExtent(extent) {
|
||||
var minX = extent[0];
|
||||
var minY = extent[1];
|
||||
var maxX = extent[2];
|
||||
@@ -413,7 +415,7 @@ Polygon.fromExtent = function(extent) {
|
||||
polygon.setFlatCoordinates(
|
||||
GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
|
||||
return polygon;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -425,7 +427,7 @@ Polygon.fromExtent = function(extent) {
|
||||
* @return {ol.geom.Polygon} Polygon geometry.
|
||||
* @api
|
||||
*/
|
||||
Polygon.fromCircle = function(circle, opt_sides, opt_angle) {
|
||||
export function fromCircle(circle, opt_sides, opt_angle) {
|
||||
var sides = opt_sides ? opt_sides : 32;
|
||||
var stride = circle.getStride();
|
||||
var layout = circle.getLayout();
|
||||
@@ -437,10 +439,9 @@ Polygon.fromCircle = function(circle, opt_sides, opt_angle) {
|
||||
}
|
||||
var ends = [flatCoordinates.length];
|
||||
polygon.setFlatCoordinates(layout, flatCoordinates, ends);
|
||||
Polygon.makeRegular(
|
||||
polygon, circle.getCenter(), circle.getRadius(), opt_angle);
|
||||
makeRegular(polygon, circle.getCenter(), circle.getRadius(), opt_angle);
|
||||
return polygon;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -451,7 +452,7 @@ Polygon.fromCircle = function(circle, opt_sides, opt_angle) {
|
||||
* @param {number=} opt_angle Start angle for the first vertex of the polygon in
|
||||
* radians. Default is 0.
|
||||
*/
|
||||
Polygon.makeRegular = function(polygon, center, radius, opt_angle) {
|
||||
export function makeRegular(polygon, center, radius, opt_angle) {
|
||||
var flatCoordinates = polygon.getFlatCoordinates();
|
||||
var layout = polygon.getLayout();
|
||||
var stride = polygon.getStride();
|
||||
@@ -466,5 +467,4 @@ Polygon.makeRegular = function(polygon, center, radius, opt_angle) {
|
||||
flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle));
|
||||
}
|
||||
polygon.setFlatCoordinates(layout, flatCoordinates, ends);
|
||||
};
|
||||
export default Polygon;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import Polygon, {fromCircle, makeRegular} from '../geom/Polygon.js';
|
||||
import DrawEventType from '../interaction/DrawEventType.js';
|
||||
import _ol_interaction_Pointer_ from '../interaction/Pointer.js';
|
||||
import _ol_interaction_Property_ from '../interaction/Property.js';
|
||||
@@ -795,10 +795,10 @@ Draw.createRegularPolygon = function(opt_sides, opt_angle) {
|
||||
var radius = Math.sqrt(
|
||||
_ol_coordinate_.squaredDistance(center, end));
|
||||
var geometry = opt_geometry ? /** @type {ol.geom.Polygon} */ (opt_geometry) :
|
||||
Polygon.fromCircle(new Circle(center), opt_sides);
|
||||
fromCircle(new Circle(center), opt_sides);
|
||||
var angle = opt_angle ? opt_angle :
|
||||
Math.atan((end[1] - center[1]) / (end[0] - center[0]));
|
||||
Polygon.makeRegular(geometry, center, radius, angle);
|
||||
makeRegular(geometry, center, radius, angle);
|
||||
return geometry;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ import Event from '../events/Event.js';
|
||||
import {boundingExtent, getArea} from '../extent.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
import _ol_interaction_ExtentEventType_ from '../interaction/ExtentEventType.js';
|
||||
import _ol_interaction_Pointer_ from '../interaction/Pointer.js';
|
||||
import _ol_layer_Vector_ from '../layer/Vector.js';
|
||||
@@ -376,7 +376,7 @@ _ol_interaction_Extent_.prototype.createOrUpdateExtentFeature_ = function(extent
|
||||
if (!extent) {
|
||||
extentFeature = new _ol_Feature_({});
|
||||
} else {
|
||||
extentFeature = new _ol_Feature_(Polygon.fromExtent(extent));
|
||||
extentFeature = new _ol_Feature_(polygonFromExtent(extent));
|
||||
}
|
||||
this.extentFeature_ = extentFeature;
|
||||
this.extentOverlay_.getSource().addFeature(extentFeature);
|
||||
@@ -384,7 +384,7 @@ _ol_interaction_Extent_.prototype.createOrUpdateExtentFeature_ = function(extent
|
||||
if (!extent) {
|
||||
extentFeature.setGeometry(undefined);
|
||||
} else {
|
||||
extentFeature.setGeometry(Polygon.fromExtent(extent));
|
||||
extentFeature.setGeometry(polygonFromExtent(extent));
|
||||
}
|
||||
}
|
||||
return extentFeature;
|
||||
|
||||
@@ -10,7 +10,7 @@ import EventType from '../events/EventType.js';
|
||||
import {boundingExtent, createEmpty} from '../extent.js';
|
||||
import {TRUE, FALSE} from '../functions.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {fromCircle} from '../geom/Polygon.js';
|
||||
import _ol_interaction_Pointer_ from '../interaction/Pointer.js';
|
||||
import _ol_obj_ from '../obj.js';
|
||||
import _ol_source_Vector_ from '../source/Vector.js';
|
||||
@@ -435,7 +435,7 @@ _ol_interaction_Snap_.prototype.updateFeature_ = function(feature) {
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Snap_.prototype.writeCircleGeometry_ = function(feature, geometry) {
|
||||
var polygon = Polygon.fromCircle(geometry);
|
||||
var polygon = fromCircle(geometry);
|
||||
var coordinates = polygon.getCoordinates()[0];
|
||||
var i, ii, segment, segmentData;
|
||||
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user