Merge pull request #8657 from fgravin/fgravin_help_typescript
Typescript fixes
This commit is contained in:
+13
-14
@@ -54,7 +54,7 @@ import Style from './style/Style.js';
|
|||||||
*/
|
*/
|
||||||
class Feature extends BaseObject {
|
class Feature extends BaseObject {
|
||||||
/**
|
/**
|
||||||
* @param {import("./geom/Geometry.js").default|Object<string, *>=} opt_geometryOrProperties
|
* @param {Geometry|Object<string, *>=} opt_geometryOrProperties
|
||||||
* You may pass a Geometry object directly, or an object literal containing
|
* You may pass a Geometry object directly, or an object literal containing
|
||||||
* properties. If you pass an object literal, you may include a Geometry
|
* properties. If you pass an object literal, you may include a Geometry
|
||||||
* associated with a `geometry` key.
|
* associated with a `geometry` key.
|
||||||
@@ -78,7 +78,7 @@ class Feature extends BaseObject {
|
|||||||
/**
|
/**
|
||||||
* User provided style.
|
* User provided style.
|
||||||
* @private
|
* @private
|
||||||
* @type {import("./style/Style.js").default|Array<import("./style/Style.js").default>|import("./style/Style.js").StyleFunction}
|
* @type {Style|Array<Style>|import("./style/Style.js").StyleFunction}
|
||||||
*/
|
*/
|
||||||
this.style_ = null;
|
this.style_ = null;
|
||||||
|
|
||||||
@@ -99,10 +99,9 @@ class Feature extends BaseObject {
|
|||||||
this.handleGeometryChanged_, this);
|
this.handleGeometryChanged_, this);
|
||||||
|
|
||||||
if (opt_geometryOrProperties !== undefined) {
|
if (opt_geometryOrProperties !== undefined) {
|
||||||
if (opt_geometryOrProperties instanceof Geometry ||
|
if (opt_geometryOrProperties instanceof Geometry) {
|
||||||
!opt_geometryOrProperties) {
|
|
||||||
/** @type {?Geometry} */
|
const geometry = /** @type {Geometry} */ (opt_geometryOrProperties);
|
||||||
const geometry = opt_geometryOrProperties;
|
|
||||||
this.setGeometry(geometry);
|
this.setGeometry(geometry);
|
||||||
} else {
|
} else {
|
||||||
/** @type {Object<string, *>} */
|
/** @type {Object<string, *>} */
|
||||||
@@ -136,13 +135,13 @@ class Feature extends BaseObject {
|
|||||||
* Get the feature's default geometry. A feature may have any number of named
|
* Get the feature's default geometry. A feature may have any number of named
|
||||||
* geometries. The "default" geometry (the one that is rendered by default) is
|
* geometries. The "default" geometry (the one that is rendered by default) is
|
||||||
* set when calling {@link module:ol/Feature~Feature#setGeometry}.
|
* set when calling {@link module:ol/Feature~Feature#setGeometry}.
|
||||||
* @return {import("./geom/Geometry.js").default|undefined} The default geometry for the feature.
|
* @return {Geometry|undefined} The default geometry for the feature.
|
||||||
* @api
|
* @api
|
||||||
* @observable
|
* @observable
|
||||||
*/
|
*/
|
||||||
getGeometry() {
|
getGeometry() {
|
||||||
return (
|
return (
|
||||||
/** @type {import("./geom/Geometry.js").default|undefined} */ (this.get(this.geometryName_))
|
/** @type {Geometry|undefined} */ (this.get(this.geometryName_))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +170,7 @@ class Feature extends BaseObject {
|
|||||||
/**
|
/**
|
||||||
* Get the feature's style. Will return what was provided to the
|
* Get the feature's style. Will return what was provided to the
|
||||||
* {@link module:ol/Feature~Feature#setStyle} method.
|
* {@link module:ol/Feature~Feature#setStyle} method.
|
||||||
* @return {import("./style/Style.js").default|Array<import("./style/Style.js").default>|import("./style/Style.js").StyleFunction} The feature style.
|
* @return {Style|Array<Style>|import("./style/Style.js").StyleFunction} The feature style.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getStyle() {
|
getStyle() {
|
||||||
@@ -214,7 +213,7 @@ class Feature extends BaseObject {
|
|||||||
/**
|
/**
|
||||||
* Set the default geometry for the feature. This will update the property
|
* Set the default geometry for the feature. This will update the property
|
||||||
* with the name returned by {@link module:ol/Feature~Feature#getGeometryName}.
|
* with the name returned by {@link module:ol/Feature~Feature#getGeometryName}.
|
||||||
* @param {import("./geom/Geometry.js").default|undefined} geometry The new geometry.
|
* @param {Geometry|undefined} geometry The new geometry.
|
||||||
* @api
|
* @api
|
||||||
* @observable
|
* @observable
|
||||||
*/
|
*/
|
||||||
@@ -226,7 +225,7 @@ class Feature extends BaseObject {
|
|||||||
* Set the style for the feature. This can be a single style object, an array
|
* Set the style for the feature. This can be a single style object, an array
|
||||||
* of styles, or a function that takes a resolution and returns an array of
|
* of styles, or a function that takes a resolution and returns an array of
|
||||||
* styles. If it is `null` the feature has no style (a `null` style).
|
* styles. If it is `null` the feature has no style (a `null` style).
|
||||||
* @param {import("./style/Style.js").default|Array<import("./style/Style.js").default>|import("./style/Style.js").StyleFunction} style Style for this feature.
|
* @param {Style|Array<Style>|import("./style/Style.js").StyleFunction} style Style for this feature.
|
||||||
* @api
|
* @api
|
||||||
* @fires module:ol/events/Event~Event#event:change
|
* @fires module:ol/events/Event~Event#event:change
|
||||||
*/
|
*/
|
||||||
@@ -272,9 +271,9 @@ class Feature extends BaseObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the provided object into a feature style function. Functions passed
|
* Convert the provided object into a feature style function. Functions passed
|
||||||
* through unchanged. Arrays of import("./style/Style.js").default or single style objects wrapped
|
* through unchanged. Arrays of Style or single style objects wrapped
|
||||||
* in a new feature style function.
|
* in a new feature style function.
|
||||||
* @param {import("./style/Style.js").StyleFunction|!Array<import("./style/Style.js").default>|!import("./style/Style.js").default} obj
|
* @param {import("./style/Style.js").StyleFunction|!Array<Style>|!Style} obj
|
||||||
* A feature style function, a single style, or an array of styles.
|
* A feature style function, a single style, or an array of styles.
|
||||||
* @return {import("./style/Style.js").StyleFunction} A style function.
|
* @return {import("./style/Style.js").StyleFunction} A style function.
|
||||||
*/
|
*/
|
||||||
@@ -283,7 +282,7 @@ export function createStyleFunction(obj) {
|
|||||||
return obj;
|
return obj;
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* @type {Array<import("./style/Style.js").default>}
|
* @type {Array<Style>}
|
||||||
*/
|
*/
|
||||||
let styles;
|
let styles;
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
|
|||||||
@@ -174,9 +174,12 @@ class Geolocation extends BaseObject {
|
|||||||
* @param {PositionError} error error object.
|
* @param {PositionError} error error object.
|
||||||
*/
|
*/
|
||||||
positionError_(error) {
|
positionError_(error) {
|
||||||
error.type = EventType.ERROR;
|
const event = {
|
||||||
|
type: EventType.ERROR,
|
||||||
|
target: undefined
|
||||||
|
};
|
||||||
this.setTracking(false);
|
this.setTracking(false);
|
||||||
this.dispatchEvent(/** @type {{type: string, target: undefined}} */ (error));
|
this.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-1
@@ -114,7 +114,8 @@ class ImageTile extends Tile {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
handleImageLoad_() {
|
handleImageLoad_() {
|
||||||
if (this.image_.naturalWidth && this.image_.naturalHeight) {
|
if (this.image_ instanceof HTMLImageElement &&
|
||||||
|
this.image_.naturalWidth && this.image_.naturalHeight) {
|
||||||
this.state = TileState.LOADED;
|
this.state = TileState.LOADED;
|
||||||
} else {
|
} else {
|
||||||
this.state = TileState.EMPTY;
|
this.state = TileState.EMPTY;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class MapBrowserEventHandler extends EventTarget {
|
|||||||
this.dispatchEvent(newEvent);
|
this.dispatchEvent(newEvent);
|
||||||
} else {
|
} else {
|
||||||
// click
|
// click
|
||||||
this.clickTimeoutId_ = setTimeout(function() {
|
this.clickTimeoutId_ = window.setTimeout(function() {
|
||||||
this.clickTimeoutId_ = 0;
|
this.clickTimeoutId_ = 0;
|
||||||
const newEvent = new MapBrowserPointerEvent(
|
const newEvent = new MapBrowserPointerEvent(
|
||||||
MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
|
MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
|
||||||
|
|||||||
@@ -235,11 +235,12 @@ class Geometry extends BaseObject {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
transform(source, destination) {
|
transform(source, destination) {
|
||||||
source = getProjection(source);
|
/** @type {import("../proj/Projection.js").default} */
|
||||||
const transformFn = source.getUnits() == Units.TILE_PIXELS ?
|
const sourceProj = getProjection(source);
|
||||||
|
const transformFn = sourceProj.getUnits() == Units.TILE_PIXELS ?
|
||||||
function(inCoordinates, outCoordinates, stride) {
|
function(inCoordinates, outCoordinates, stride) {
|
||||||
const pixelExtent = source.getExtent();
|
const pixelExtent = sourceProj.getExtent();
|
||||||
const projectedExtent = source.getWorldExtent();
|
const projectedExtent = sourceProj.getWorldExtent();
|
||||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||||
composeTransform(tmpTransform,
|
composeTransform(tmpTransform,
|
||||||
projectedExtent[0], projectedExtent[3],
|
projectedExtent[0], projectedExtent[3],
|
||||||
@@ -247,12 +248,13 @@ class Geometry extends BaseObject {
|
|||||||
0, 0);
|
0, 0);
|
||||||
transform2D(inCoordinates, 0, inCoordinates.length, stride,
|
transform2D(inCoordinates, 0, inCoordinates.length, stride,
|
||||||
tmpTransform, outCoordinates);
|
tmpTransform, outCoordinates);
|
||||||
return getTransform(source, destination)(inCoordinates, outCoordinates, stride);
|
return getTransform(sourceProj, destination)(inCoordinates, outCoordinates, stride);
|
||||||
} :
|
} :
|
||||||
getTransform(source, destination);
|
getTransform(sourceProj, destination);
|
||||||
this.applyTransform(transformFn);
|
this.applyTransform(transformFn);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import Event from '../events/Event.js';
|
import _Event from '../events/Event.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +42,7 @@ import Event from '../events/Event.js';
|
|||||||
let HAS_BUTTONS = false;
|
let HAS_BUTTONS = false;
|
||||||
|
|
||||||
|
|
||||||
class PointerEvent extends Event {
|
class PointerEvent extends _Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for pointer events.
|
* A class for pointer events.
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ describe('ol.Feature', function() {
|
|||||||
|
|
||||||
it('returns null for null geometry (constructor)', function() {
|
it('returns null for null geometry (constructor)', function() {
|
||||||
const feature = new Feature(null);
|
const feature = new Feature(null);
|
||||||
expect(feature.getGeometry()).to.be(null);
|
expect(feature.getGeometry()).to.be(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns null for null geometry (setGeometry())', function() {
|
it('returns null for null geometry (setGeometry())', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user