-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1204 from OpenGeoscience/split-annotation-js
refactor: Refactor annotation code to make it less monolithic.
- Loading branch information
Showing
10 changed files
with
1,446 additions
and
1,364 deletions.
There are no files selected for viewing
1,374 changes: 11 additions & 1,363 deletions
1,374
src/annotation.js → src/annotation/annotation.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const $ = require('jquery'); | ||
const inherit = require('../inherit'); | ||
const registerAnnotation = require('../registry').registerAnnotation; | ||
const markerFeature = require('../markerFeature'); | ||
|
||
const ellipseAnnotation = require('./ellipseAnnotation'); | ||
|
||
/** | ||
* Circle annotation class. | ||
* | ||
* Circles are a subset of rectangles with a fixed aspect ratio. | ||
* | ||
* @class | ||
* @alias geo.circleAnnotation | ||
* @extends geo.annotation | ||
* | ||
* @param {geo.circleAnnotation.spec?} [args] Options for the annotation. | ||
* @param {string} [annotationName='circle'] Override the annotation name. | ||
*/ | ||
var circleAnnotation = function (args, annotationName) { | ||
'use strict'; | ||
args = $.extend({}, args, {constraint: 1}); | ||
if (!(this instanceof circleAnnotation)) { | ||
return new circleAnnotation(args, annotationName); | ||
} | ||
ellipseAnnotation.call(this, args, annotationName || 'circle'); | ||
}; | ||
inherit(circleAnnotation, ellipseAnnotation); | ||
var circleRequiredFeatures = {}; | ||
circleRequiredFeatures[markerFeature.capabilities.feature] = true; | ||
registerAnnotation('circle', circleAnnotation, circleRequiredFeatures); | ||
|
||
module.exports = circleAnnotation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const $ = require('jquery'); | ||
const inherit = require('../inherit'); | ||
const registerAnnotation = require('../registry').registerAnnotation; | ||
const markerFeature = require('../markerFeature'); | ||
|
||
const annotationState = require('./annotation').state; | ||
const rectangleAnnotation = require('./rectangleAnnotation'); | ||
|
||
/** | ||
* Ellipse annotation class. | ||
* | ||
* Ellipses are always rendered as markers. | ||
* | ||
* @class | ||
* @alias geo.ellipseAnnotation | ||
* @extends geo.annotation | ||
* | ||
* @param {geo.ellipseAnnotation.spec?} [args] Options for the annotation. | ||
* @param {string} [annotationName='ellipse'] Override the annotation name. | ||
*/ | ||
var ellipseAnnotation = function (args, annotationName) { | ||
'use strict'; | ||
if (!(this instanceof ellipseAnnotation)) { | ||
return new ellipseAnnotation(args, annotationName); | ||
} | ||
|
||
rectangleAnnotation.call(this, args, annotationName || 'ellipse'); | ||
|
||
var m_this = this; | ||
|
||
/** | ||
* Get a list of renderable features for this annotation. | ||
* | ||
* @returns {array} An array of features. | ||
*/ | ||
this.features = function () { | ||
var opt = m_this.options(), | ||
state = m_this.state(), | ||
features; | ||
features = []; | ||
if (opt.corners && opt.corners.length >= 4) { | ||
const style = m_this.styleForState(state); | ||
const w = ((opt.corners[0].x - opt.corners[1].x) ** 2 + (opt.corners[0].y - opt.corners[1].y) ** 2) ** 0.5; | ||
const h = ((opt.corners[0].x - opt.corners[3].x) ** 2 + (opt.corners[0].y - opt.corners[3].y) ** 2) ** 0.5; | ||
const radius = Math.max(w, h) / 2 / m_this.layer().map().unitsPerPixel(0); | ||
const aspect = w ? h / w : 1e20; | ||
const rotation = -Math.atan2(opt.corners[1].y - opt.corners[0].y, opt.corners[1].x - opt.corners[0].x); | ||
features = [{ | ||
marker: { | ||
x: (opt.corners[0].x + opt.corners[1].x + opt.corners[2].x + opt.corners[3].x) / 4, | ||
y: (opt.corners[0].y + opt.corners[1].y + opt.corners[2].y + opt.corners[3].y) / 4, | ||
style: $.extend( | ||
{}, style, | ||
{ | ||
radius: radius, | ||
symbolValue: aspect, | ||
rotation: rotation, | ||
strokeOffset: 0, | ||
radiusIncludesStroke: false, | ||
scaleWithZoom: markerFeature.scaleMode.fill, | ||
rotateWithMap: true, | ||
strokeOpacity: style.stroke === false ? 0 : style.strokeOpacity, | ||
fillOpacity: style.fill === false ? 0 : style.fillOpacity | ||
}) | ||
} | ||
}]; | ||
} | ||
if (state === annotationState.edit) { | ||
m_this._addEditHandles(features, opt.corners); | ||
} | ||
return features; | ||
}; | ||
}; | ||
inherit(ellipseAnnotation, rectangleAnnotation); | ||
|
||
var ellipseRequiredFeatures = {}; | ||
ellipseRequiredFeatures[markerFeature.capabilities.feature] = true; | ||
registerAnnotation('ellipse', ellipseAnnotation, ellipseRequiredFeatures); | ||
|
||
module.exports = ellipseAnnotation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const annotation = require('./annotation'); | ||
|
||
/** | ||
* @namespace geo.annotation | ||
*/ | ||
module.exports = { | ||
state: annotation.state, | ||
actionOwner: annotation.actionOwner, | ||
annotation: annotation.annotation, | ||
_editHandleFeatureLevel: annotation._editHandleFeatureLevel, | ||
defaultEditHandleStyle: annotation.defaultEditHandleStyle, | ||
constrainAspectRatio: annotation.constrainAspectRatio, | ||
baseAnnotation: annotation, | ||
circleAnnotation: require('./circleAnnotation'), | ||
ellipseAnnotation: require('./ellipseAnnotation'), | ||
lineAnnotation: require('./lineAnnotation'), | ||
pointAnnotation: require('./pointAnnotation'), | ||
polygonAnnotation: require('./polygonAnnotation'), | ||
rectangleAnnotation: require('./rectangleAnnotation'), | ||
squareAnnotation: require('./squareAnnotation') | ||
}; |
Oops, something went wrong.