Merge pull request #9289 from sbrunner/vector-source-geom
Vector source geom
This commit is contained in:
+4
-3
@@ -5,6 +5,7 @@ import {Tile as TileLayer, Vector as VectorLayer} from '../src/ol/layer.js';
|
|||||||
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
|
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
|
||||||
import {Circle as CircleStyle, Fill, Stroke, Style} from '../src/ol/style.js';
|
import {Circle as CircleStyle, Fill, Stroke, Style} from '../src/ol/style.js';
|
||||||
|
|
||||||
|
/** @type {VectorSource<import("../src/ol/geom/SimpleGeometry.js").default>} */
|
||||||
const source = new VectorSource({
|
const source = new VectorSource({
|
||||||
url: 'data/geojson/switzerland.geojson',
|
url: 'data/geojson/switzerland.geojson',
|
||||||
format: new GeoJSON()
|
format: new GeoJSON()
|
||||||
@@ -51,21 +52,21 @@ const zoomtoswitzerland =
|
|||||||
document.getElementById('zoomtoswitzerland');
|
document.getElementById('zoomtoswitzerland');
|
||||||
zoomtoswitzerland.addEventListener('click', function() {
|
zoomtoswitzerland.addEventListener('click', function() {
|
||||||
const feature = source.getFeatures()[0];
|
const feature = source.getFeatures()[0];
|
||||||
const polygon = /** @type {import("../src/ol/geom/SimpleGeometry.js").default} */ (feature.getGeometry());
|
const polygon = feature.getGeometry();
|
||||||
view.fit(polygon, {padding: [170, 50, 30, 150]});
|
view.fit(polygon, {padding: [170, 50, 30, 150]});
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
const zoomtolausanne = document.getElementById('zoomtolausanne');
|
const zoomtolausanne = document.getElementById('zoomtolausanne');
|
||||||
zoomtolausanne.addEventListener('click', function() {
|
zoomtolausanne.addEventListener('click', function() {
|
||||||
const feature = source.getFeatures()[1];
|
const feature = source.getFeatures()[1];
|
||||||
const point = /** @type {import("../src/ol/geom/SimpleGeometry.js").default} */ (feature.getGeometry());
|
const point = feature.getGeometry();
|
||||||
view.fit(point, {padding: [170, 50, 30, 150], minResolution: 50});
|
view.fit(point, {padding: [170, 50, 30, 150], minResolution: 50});
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
const centerlausanne = document.getElementById('centerlausanne');
|
const centerlausanne = document.getElementById('centerlausanne');
|
||||||
centerlausanne.addEventListener('click', function() {
|
centerlausanne.addEventListener('click', function() {
|
||||||
const feature = source.getFeatures()[1];
|
const feature = source.getFeatures()[1];
|
||||||
const point = /** @type {import("../src/ol/geom/Point.js").default} */ (feature.getGeometry());
|
const point = feature.getGeometry();
|
||||||
const size = map.getSize();
|
const size = map.getSize();
|
||||||
view.centerOn(point.getCoordinates(), size, [570, 500]);
|
view.centerOn(point.getCoordinates(), size, [570, 500]);
|
||||||
}, false);
|
}, false);
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ const routeFeature = new Feature({
|
|||||||
type: 'route',
|
type: 'route',
|
||||||
geometry: route
|
geometry: route
|
||||||
});
|
});
|
||||||
const geoMarker = new Feature({
|
const geoMarker = /** @type Feature<import("../src/ol/geom/Point").default> */(new Feature({
|
||||||
type: 'geoMarker',
|
type: 'geoMarker',
|
||||||
geometry: new Point(routeCoords[0])
|
geometry: new Point(routeCoords[0])
|
||||||
});
|
}));
|
||||||
const startMarker = new Feature({
|
const startMarker = new Feature({
|
||||||
type: 'icon',
|
type: 'icon',
|
||||||
geometry: new Point(routeCoords[0])
|
geometry: new Point(routeCoords[0])
|
||||||
@@ -191,7 +191,7 @@ function stopAnimation(ended) {
|
|||||||
|
|
||||||
// if animation cancelled set the marker at the beginning
|
// if animation cancelled set the marker at the beginning
|
||||||
const coord = ended ? routeCoords[routeLength - 1] : routeCoords[0];
|
const coord = ended ? routeCoords[routeLength - 1] : routeCoords[0];
|
||||||
const geometry = /** @type {import("../src/ol/geom/Point").default} */ (geoMarker.getGeometry());
|
const geometry = geoMarker.getGeometry();
|
||||||
geometry.setCoordinates(coord);
|
geometry.setCoordinates(coord);
|
||||||
//remove listener
|
//remove listener
|
||||||
vectorLayer.un('postrender', moveFeature);
|
vectorLayer.un('postrender', moveFeature);
|
||||||
|
|||||||
+6
-5
@@ -57,10 +57,11 @@ import BaseObject, {getChangeEventType} from './Object.js';
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
|
* @template {import("./geom/Geometry.js").default} Geometry
|
||||||
*/
|
*/
|
||||||
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.
|
||||||
@@ -106,7 +107,7 @@ class Feature extends BaseObject {
|
|||||||
|
|
||||||
if (opt_geometryOrProperties) {
|
if (opt_geometryOrProperties) {
|
||||||
if (typeof /** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry === 'function') {
|
if (typeof /** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry === 'function') {
|
||||||
const geometry = /** @type {import("./geom/Geometry.js").default} */ (opt_geometryOrProperties);
|
const geometry = /** @type {Geometry} */ (opt_geometryOrProperties);
|
||||||
this.setGeometry(geometry);
|
this.setGeometry(geometry);
|
||||||
} else {
|
} else {
|
||||||
/** @type {Object<string, *>} */
|
/** @type {Object<string, *>} */
|
||||||
@@ -140,13 +141,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_))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +219,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
|
||||||
*/
|
*/
|
||||||
|
|||||||
+14
-14
@@ -373,7 +373,7 @@ class Draw extends PointerInteraction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sketch point.
|
* Sketch point.
|
||||||
* @type {Feature}
|
* @type {Feature<Point>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.sketchPoint_ = null;
|
this.sketchPoint_ = null;
|
||||||
@@ -387,7 +387,7 @@ class Draw extends PointerInteraction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sketch line. Used when drawing polygon.
|
* Sketch line. Used when drawing polygon.
|
||||||
* @type {Feature}
|
* @type {Feature<LineString>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.sketchLine_ = null;
|
this.sketchLine_ = null;
|
||||||
@@ -669,7 +669,7 @@ class Draw extends PointerInteraction {
|
|||||||
this.sketchPoint_ = new Feature(new Point(coordinates));
|
this.sketchPoint_ = new Feature(new Point(coordinates));
|
||||||
this.updateSketchFeatures_();
|
this.updateSketchFeatures_();
|
||||||
} else {
|
} else {
|
||||||
const sketchPointGeom = /** @type {Point} */ (this.sketchPoint_.getGeometry());
|
const sketchPointGeom = this.sketchPoint_.getGeometry();
|
||||||
sketchPointGeom.setCoordinates(coordinates);
|
sketchPointGeom.setCoordinates(coordinates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ class Draw extends PointerInteraction {
|
|||||||
*/
|
*/
|
||||||
modifyDrawing_(event) {
|
modifyDrawing_(event) {
|
||||||
let coordinate = event.coordinate;
|
let coordinate = event.coordinate;
|
||||||
const geometry = /** @type {import("../geom/SimpleGeometry.js").default} */ (this.sketchFeature_.getGeometry());
|
const geometry = this.sketchFeature_.getGeometry();
|
||||||
let coordinates, last;
|
let coordinates, last;
|
||||||
if (this.mode_ === Mode.POINT) {
|
if (this.mode_ === Mode.POINT) {
|
||||||
last = this.sketchCoords_;
|
last = this.sketchCoords_;
|
||||||
@@ -730,7 +730,7 @@ class Draw extends PointerInteraction {
|
|||||||
last[1] = coordinate[1];
|
last[1] = coordinate[1];
|
||||||
this.geometryFunction_(/** @type {!LineCoordType} */ (this.sketchCoords_), geometry);
|
this.geometryFunction_(/** @type {!LineCoordType} */ (this.sketchCoords_), geometry);
|
||||||
if (this.sketchPoint_) {
|
if (this.sketchPoint_) {
|
||||||
const sketchPointGeom = /** @type {Point} */ (this.sketchPoint_.getGeometry());
|
const sketchPointGeom = this.sketchPoint_.getGeometry();
|
||||||
sketchPointGeom.setCoordinates(coordinate);
|
sketchPointGeom.setCoordinates(coordinate);
|
||||||
}
|
}
|
||||||
/** @type {LineString} */
|
/** @type {LineString} */
|
||||||
@@ -740,8 +740,8 @@ class Draw extends PointerInteraction {
|
|||||||
if (!this.sketchLine_) {
|
if (!this.sketchLine_) {
|
||||||
this.sketchLine_ = new Feature();
|
this.sketchLine_ = new Feature();
|
||||||
}
|
}
|
||||||
const ring = /** @type {Polygon} */ (geometry).getLinearRing(0);
|
const ring = geometry.getLinearRing(0);
|
||||||
sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry());
|
sketchLineGeom = this.sketchLine_.getGeometry();
|
||||||
if (!sketchLineGeom) {
|
if (!sketchLineGeom) {
|
||||||
sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
|
sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
|
||||||
this.sketchLine_.setGeometry(sketchLineGeom);
|
this.sketchLine_.setGeometry(sketchLineGeom);
|
||||||
@@ -751,7 +751,7 @@ class Draw extends PointerInteraction {
|
|||||||
sketchLineGeom.changed();
|
sketchLineGeom.changed();
|
||||||
}
|
}
|
||||||
} else if (this.sketchLineCoords_) {
|
} else if (this.sketchLineCoords_) {
|
||||||
sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry());
|
sketchLineGeom = this.sketchLine_.getGeometry();
|
||||||
sketchLineGeom.setCoordinates(this.sketchLineCoords_);
|
sketchLineGeom.setCoordinates(this.sketchLineCoords_);
|
||||||
}
|
}
|
||||||
this.updateSketchFeatures_();
|
this.updateSketchFeatures_();
|
||||||
@@ -764,7 +764,7 @@ class Draw extends PointerInteraction {
|
|||||||
*/
|
*/
|
||||||
addToDrawing_(event) {
|
addToDrawing_(event) {
|
||||||
const coordinate = event.coordinate;
|
const coordinate = event.coordinate;
|
||||||
const geometry = /** @type {import("../geom/SimpleGeometry.js").default} */ (this.sketchFeature_.getGeometry());
|
const geometry = this.sketchFeature_.getGeometry();
|
||||||
let done;
|
let done;
|
||||||
let coordinates;
|
let coordinates;
|
||||||
if (this.mode_ === Mode.LINE_STRING) {
|
if (this.mode_ === Mode.LINE_STRING) {
|
||||||
@@ -808,7 +808,7 @@ class Draw extends PointerInteraction {
|
|||||||
if (!this.sketchFeature_) {
|
if (!this.sketchFeature_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const geometry = /** @type {import("../geom/SimpleGeometry.js").default} */ (this.sketchFeature_.getGeometry());
|
const geometry = this.sketchFeature_.getGeometry();
|
||||||
let coordinates;
|
let coordinates;
|
||||||
/** @type {LineString} */
|
/** @type {LineString} */
|
||||||
let sketchLineGeom;
|
let sketchLineGeom;
|
||||||
@@ -822,7 +822,7 @@ class Draw extends PointerInteraction {
|
|||||||
} else if (this.mode_ === Mode.POLYGON) {
|
} else if (this.mode_ === Mode.POLYGON) {
|
||||||
coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
|
coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
|
||||||
coordinates.splice(-2, 1);
|
coordinates.splice(-2, 1);
|
||||||
sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry());
|
sketchLineGeom = this.sketchLine_.getGeometry();
|
||||||
sketchLineGeom.setCoordinates(coordinates);
|
sketchLineGeom.setCoordinates(coordinates);
|
||||||
this.geometryFunction_(this.sketchCoords_, geometry);
|
this.geometryFunction_(this.sketchCoords_, geometry);
|
||||||
}
|
}
|
||||||
@@ -846,7 +846,7 @@ class Draw extends PointerInteraction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let coordinates = this.sketchCoords_;
|
let coordinates = this.sketchCoords_;
|
||||||
const geometry = /** @type {import("../geom/SimpleGeometry.js").default} */ (sketchFeature.getGeometry());
|
const geometry = sketchFeature.getGeometry();
|
||||||
if (this.mode_ === Mode.LINE_STRING) {
|
if (this.mode_ === Mode.LINE_STRING) {
|
||||||
// remove the redundant last point
|
// remove the redundant last point
|
||||||
coordinates.pop();
|
coordinates.pop();
|
||||||
@@ -900,12 +900,12 @@ class Draw extends PointerInteraction {
|
|||||||
* Extend an existing geometry by adding additional points. This only works
|
* Extend an existing geometry by adding additional points. This only works
|
||||||
* on features with `LineString` geometries, where the interaction will
|
* on features with `LineString` geometries, where the interaction will
|
||||||
* extend lines by adding points to the end of the coordinates array.
|
* extend lines by adding points to the end of the coordinates array.
|
||||||
* @param {!Feature} feature Feature to be extended.
|
* @param {!Feature<LineString>} feature Feature to be extended.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
extend(feature) {
|
extend(feature) {
|
||||||
const geometry = feature.getGeometry();
|
const geometry = feature.getGeometry();
|
||||||
const lineString = /** @type {LineString} */ (geometry);
|
const lineString = geometry;
|
||||||
this.sketchFeature_ = feature;
|
this.sketchFeature_ = feature;
|
||||||
this.sketchCoords_ = lineString.getCoordinates();
|
this.sketchCoords_ = lineString.getCoordinates();
|
||||||
const last = this.sketchCoords_[this.sketchCoords_.length - 1];
|
const last = this.sketchCoords_[this.sketchCoords_.length - 1];
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Extent extends PointerInteraction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature for displaying the visible pointer
|
* Feature for displaying the visible pointer
|
||||||
* @type {Feature}
|
* @type {Feature<Point>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.vertexFeature_ = null;
|
this.vertexFeature_ = null;
|
||||||
@@ -265,7 +265,7 @@ class Extent extends PointerInteraction {
|
|||||||
this.vertexFeature_ = vertexFeature;
|
this.vertexFeature_ = vertexFeature;
|
||||||
this.vertexOverlay_.getSource().addFeature(vertexFeature);
|
this.vertexOverlay_.getSource().addFeature(vertexFeature);
|
||||||
} else {
|
} else {
|
||||||
const geometry = /** @type {Point} */ (vertexFeature.getGeometry());
|
const geometry = vertexFeature.getGeometry();
|
||||||
geometry.setCoordinates(vertex);
|
geometry.setCoordinates(vertex);
|
||||||
}
|
}
|
||||||
return vertexFeature;
|
return vertexFeature;
|
||||||
|
|||||||
@@ -660,7 +660,7 @@ class Modify extends PointerInteraction {
|
|||||||
this.vertexFeature_ = vertexFeature;
|
this.vertexFeature_ = vertexFeature;
|
||||||
this.overlay_.getSource().addFeature(vertexFeature);
|
this.overlay_.getSource().addFeature(vertexFeature);
|
||||||
} else {
|
} else {
|
||||||
const geometry = /** @type {Point} */ (vertexFeature.getGeometry());
|
const geometry = vertexFeature.getGeometry();
|
||||||
geometry.setCoordinates(coordinates);
|
geometry.setCoordinates(coordinates);
|
||||||
}
|
}
|
||||||
return vertexFeature;
|
return vertexFeature;
|
||||||
@@ -785,7 +785,7 @@ class Modify extends PointerInteraction {
|
|||||||
const vertexFeature = this.vertexFeature_;
|
const vertexFeature = this.vertexFeature_;
|
||||||
if (vertexFeature) {
|
if (vertexFeature) {
|
||||||
const insertVertices = [];
|
const insertVertices = [];
|
||||||
const geometry = /** @type {Point} */ (vertexFeature.getGeometry());
|
const geometry = vertexFeature.getGeometry();
|
||||||
const vertex = geometry.getCoordinates();
|
const vertex = geometry.getCoordinates();
|
||||||
const vertexExtent = boundingExtent([vertex]);
|
const vertexExtent = boundingExtent([vertex]);
|
||||||
const segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
|
const segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
this.coordCallback_ = options.coordCallback || function(feature, index) {
|
this.coordCallback_ = options.coordCallback || function(feature, index) {
|
||||||
const geom = /** @type {import("../../geom/Point").default} */ (feature.getGeometry());
|
const geom = feature.getGeometry();
|
||||||
return geom.getCoordinates()[index];
|
return geom.getCoordinates()[index];
|
||||||
};
|
};
|
||||||
this.opacityCallback_ = options.opacityCallback || function() {
|
this.opacityCallback_ = options.opacityCallback || function() {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class Cluster extends VectorSource {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
this.geometryFunction = options.geometryFunction || function(feature) {
|
this.geometryFunction = options.geometryFunction || function(feature) {
|
||||||
const geometry = /** @type {Point} */ (feature.getGeometry());
|
const geometry = feature.getGeometry();
|
||||||
assert(geometry.getType() == GeometryType.POINT,
|
assert(geometry.getType() == GeometryType.POINT,
|
||||||
10); // The default `geometryFunction` can only handle `Point` geometries
|
10); // The default `geometryFunction` can only handle `Point` geometries
|
||||||
return geometry;
|
return geometry;
|
||||||
|
|||||||
+40
-38
@@ -35,12 +35,13 @@ import RBush from '../structs/RBush.js';
|
|||||||
* @classdesc
|
* @classdesc
|
||||||
* Events emitted by {@link module:ol/source/Vector} instances are instances of this
|
* Events emitted by {@link module:ol/source/Vector} instances are instances of this
|
||||||
* type.
|
* type.
|
||||||
|
* @template {import("../geom/Geometry.js").default} Geometry
|
||||||
*/
|
*/
|
||||||
export class VectorSourceEvent extends Event {
|
export class VectorSourceEvent extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} type Type.
|
* @param {string} type Type.
|
||||||
* @param {import("../Feature.js").default=} opt_feature Feature.
|
* @param {import("../Feature.js").default<Geometry>=} opt_feature Feature.
|
||||||
*/
|
*/
|
||||||
constructor(type, opt_feature) {
|
constructor(type, opt_feature) {
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ export class VectorSourceEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The feature being added or removed.
|
* The feature being added or removed.
|
||||||
* @type {import("../Feature.js").default|undefined}
|
* @type {import("../Feature.js").default<Geometry>|undefined}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
this.feature = opt_feature;
|
this.feature = opt_feature;
|
||||||
@@ -154,8 +155,9 @@ export class VectorSourceEvent extends Event {
|
|||||||
* by this source are suitable for editing. See {@link module:ol/source/VectorTile~VectorTile} for
|
* by this source are suitable for editing. See {@link module:ol/source/VectorTile~VectorTile} for
|
||||||
* vector data that is optimized for rendering.
|
* vector data that is optimized for rendering.
|
||||||
*
|
*
|
||||||
* @fires VectorSourceEvent
|
* @fires VectorSourceEvent<Geometry>
|
||||||
* @api
|
* @api
|
||||||
|
* @template {import("../geom/Geometry.js").default} Geometry
|
||||||
*/
|
*/
|
||||||
class VectorSource extends Source {
|
class VectorSource extends Source {
|
||||||
/**
|
/**
|
||||||
@@ -215,7 +217,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {RBush<import("../Feature.js").default>}
|
* @type {RBush<import("../Feature.js").default<Geometry>>}
|
||||||
*/
|
*/
|
||||||
this.featuresRtree_ = useSpatialIndex ? new RBush() : null;
|
this.featuresRtree_ = useSpatialIndex ? new RBush() : null;
|
||||||
|
|
||||||
@@ -227,21 +229,21 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {!Object<string, import("../Feature.js").default>}
|
* @type {!Object<string, import("../Feature.js").default<Geometry>>}
|
||||||
*/
|
*/
|
||||||
this.nullGeometryFeatures_ = {};
|
this.nullGeometryFeatures_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lookup of features by id (the return from feature.getId()).
|
* A lookup of features by id (the return from feature.getId()).
|
||||||
* @private
|
* @private
|
||||||
* @type {!Object<string, import("../Feature.js").default>}
|
* @type {!Object<string, import("../Feature.js").default<Geometry>>}
|
||||||
*/
|
*/
|
||||||
this.idIndex_ = {};
|
this.idIndex_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lookup of features without id (keyed by getUid(feature)).
|
* A lookup of features without id (keyed by getUid(feature)).
|
||||||
* @private
|
* @private
|
||||||
* @type {!Object<string, import("../Feature.js").default>}
|
* @type {!Object<string, import("../Feature.js").default<Geometry>>}
|
||||||
*/
|
*/
|
||||||
this.undefIdIndex_ = {};
|
this.undefIdIndex_ = {};
|
||||||
|
|
||||||
@@ -253,7 +255,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Collection<import("../Feature.js").default>}
|
* @type {Collection<import("../Feature.js").default<Geometry>>}
|
||||||
*/
|
*/
|
||||||
this.featuresCollection_ = null;
|
this.featuresCollection_ = null;
|
||||||
|
|
||||||
@@ -285,7 +287,7 @@ class VectorSource extends Source {
|
|||||||
* Note: this also applies if an {@link module:ol/Collection} is used for features,
|
* Note: this also applies if an {@link module:ol/Collection} is used for features,
|
||||||
* meaning that if a feature with a duplicate id is added in the collection, it will
|
* meaning that if a feature with a duplicate id is added in the collection, it will
|
||||||
* be removed from it right away.
|
* be removed from it right away.
|
||||||
* @param {import("../Feature.js").default} feature Feature to add.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature to add.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
addFeature(feature) {
|
addFeature(feature) {
|
||||||
@@ -296,7 +298,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a feature without firing a `change` event.
|
* Add a feature without firing a `change` event.
|
||||||
* @param {import("../Feature.js").default} feature Feature.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
addFeatureInternal(feature) {
|
addFeatureInternal(feature) {
|
||||||
@@ -328,7 +330,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} featureKey Unique identifier for the feature.
|
* @param {string} featureKey Unique identifier for the feature.
|
||||||
* @param {import("../Feature.js").default} feature The feature.
|
* @param {import("../Feature.js").default<Geometry>} feature The feature.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
setupChangeEvents_(featureKey, feature) {
|
setupChangeEvents_(featureKey, feature) {
|
||||||
@@ -343,7 +345,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} featureKey Unique identifier for the feature.
|
* @param {string} featureKey Unique identifier for the feature.
|
||||||
* @param {import("../Feature.js").default} feature The feature.
|
* @param {import("../Feature.js").default<Geometry>} feature The feature.
|
||||||
* @return {boolean} The feature is "valid", in the sense that it is also a
|
* @return {boolean} The feature is "valid", in the sense that it is also a
|
||||||
* candidate for insertion into the Rtree.
|
* candidate for insertion into the Rtree.
|
||||||
* @private
|
* @private
|
||||||
@@ -368,7 +370,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a batch of features to the source.
|
* Add a batch of features to the source.
|
||||||
* @param {Array<import("../Feature.js").default>} features Features to add.
|
* @param {Array<import("../Feature.js").default<Geometry>>} features Features to add.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
addFeatures(features) {
|
addFeatures(features) {
|
||||||
@@ -379,7 +381,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add features without firing a `change` event.
|
* Add features without firing a `change` event.
|
||||||
* @param {Array<import("../Feature.js").default>} features Features.
|
* @param {Array<import("../Feature.js").default<Geometry>>} features Features.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
addFeaturesInternal(features) {
|
addFeaturesInternal(features) {
|
||||||
@@ -420,14 +422,14 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Collection<import("../Feature.js").default>} collection Collection.
|
* @param {!Collection<import("../Feature.js").default<Geometry>>} collection Collection.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
bindFeaturesCollection_(collection) {
|
bindFeaturesCollection_(collection) {
|
||||||
let modifyingCollection = false;
|
let modifyingCollection = false;
|
||||||
listen(this, VectorEventType.ADDFEATURE,
|
listen(this, VectorEventType.ADDFEATURE,
|
||||||
/**
|
/**
|
||||||
* @param {VectorSourceEvent} evt The vector source event
|
* @param {VectorSourceEvent<Geometry>} evt The vector source event
|
||||||
*/
|
*/
|
||||||
function(evt) {
|
function(evt) {
|
||||||
if (!modifyingCollection) {
|
if (!modifyingCollection) {
|
||||||
@@ -438,7 +440,7 @@ class VectorSource extends Source {
|
|||||||
});
|
});
|
||||||
listen(this, VectorEventType.REMOVEFEATURE,
|
listen(this, VectorEventType.REMOVEFEATURE,
|
||||||
/**
|
/**
|
||||||
* @param {VectorSourceEvent} evt The vector source event
|
* @param {VectorSourceEvent<Geometry>} evt The vector source event
|
||||||
*/
|
*/
|
||||||
function(evt) {
|
function(evt) {
|
||||||
if (!modifyingCollection) {
|
if (!modifyingCollection) {
|
||||||
@@ -454,7 +456,7 @@ class VectorSource extends Source {
|
|||||||
function(evt) {
|
function(evt) {
|
||||||
if (!modifyingCollection) {
|
if (!modifyingCollection) {
|
||||||
modifyingCollection = true;
|
modifyingCollection = true;
|
||||||
this.addFeature(/** @type {import("../Feature.js").default} */ (evt.element));
|
this.addFeature(/** @type {import("../Feature.js").default<Geometry>} */ (evt.element));
|
||||||
modifyingCollection = false;
|
modifyingCollection = false;
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
@@ -465,7 +467,7 @@ class VectorSource extends Source {
|
|||||||
function(evt) {
|
function(evt) {
|
||||||
if (!modifyingCollection) {
|
if (!modifyingCollection) {
|
||||||
modifyingCollection = true;
|
modifyingCollection = true;
|
||||||
this.removeFeature(/** @type {import("../Feature.js").default} */ (evt.element));
|
this.removeFeature(/** @type {import("../Feature.js").default<Geometry>} */ (evt.element));
|
||||||
modifyingCollection = false;
|
modifyingCollection = false;
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
@@ -518,7 +520,7 @@ class VectorSource extends Source {
|
|||||||
* stop and the function will return the same value.
|
* stop and the function will return the same value.
|
||||||
* Note: this function only iterate through the feature that have a defined geometry.
|
* Note: this function only iterate through the feature that have a defined geometry.
|
||||||
*
|
*
|
||||||
* @param {function(import("../Feature.js").default): T} callback Called with each feature
|
* @param {function(import("../Feature.js").default<Geometry>): T} callback Called with each feature
|
||||||
* on the source. Return a truthy value to stop iteration.
|
* on the source. Return a truthy value to stop iteration.
|
||||||
* @return {T|undefined} The return value from the last call to the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @template T
|
* @template T
|
||||||
@@ -540,7 +542,7 @@ class VectorSource extends Source {
|
|||||||
* value.
|
* value.
|
||||||
*
|
*
|
||||||
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
||||||
* @param {function(import("../Feature.js").default): T} callback Called with each feature
|
* @param {function(import("../Feature.js").default<Geometry>): T} callback Called with each feature
|
||||||
* whose goemetry contains the provided coordinate.
|
* whose goemetry contains the provided coordinate.
|
||||||
* @return {T|undefined} The return value from the last call to the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @template T
|
* @template T
|
||||||
@@ -571,7 +573,7 @@ class VectorSource extends Source {
|
|||||||
* features, equivalent to {@link module:ol/source/Vector~VectorSource#forEachFeature #forEachFeature()}.
|
* features, equivalent to {@link module:ol/source/Vector~VectorSource#forEachFeature #forEachFeature()}.
|
||||||
*
|
*
|
||||||
* @param {import("../extent.js").Extent} extent Extent.
|
* @param {import("../extent.js").Extent} extent Extent.
|
||||||
* @param {function(import("../Feature.js").default): T} callback Called with each feature
|
* @param {function(import("../Feature.js").default<Geometry>): T} callback Called with each feature
|
||||||
* whose bounding box intersects the provided extent.
|
* whose bounding box intersects the provided extent.
|
||||||
* @return {T|undefined} The return value from the last call to the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @template T
|
* @template T
|
||||||
@@ -595,7 +597,7 @@ class VectorSource extends Source {
|
|||||||
* {@link module:ol/source/Vector~VectorSource#forEachFeatureInExtent #forEachFeatureInExtent()} method instead.
|
* {@link module:ol/source/Vector~VectorSource#forEachFeatureInExtent #forEachFeatureInExtent()} method instead.
|
||||||
*
|
*
|
||||||
* @param {import("../extent.js").Extent} extent Extent.
|
* @param {import("../extent.js").Extent} extent Extent.
|
||||||
* @param {function(import("../Feature.js").default): T} callback Called with each feature
|
* @param {function(import("../Feature.js").default<Geometry>): T} callback Called with each feature
|
||||||
* whose geometry intersects the provided extent.
|
* whose geometry intersects the provided extent.
|
||||||
* @return {T|undefined} The return value from the last call to the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
* @template T
|
* @template T
|
||||||
@@ -604,7 +606,7 @@ class VectorSource extends Source {
|
|||||||
forEachFeatureIntersectingExtent(extent, callback) {
|
forEachFeatureIntersectingExtent(extent, callback) {
|
||||||
return this.forEachFeatureInExtent(extent,
|
return this.forEachFeatureInExtent(extent,
|
||||||
/**
|
/**
|
||||||
* @param {import("../Feature.js").default} feature Feature.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature.
|
||||||
* @return {T|undefined} The return value from the last call to the callback.
|
* @return {T|undefined} The return value from the last call to the callback.
|
||||||
*/
|
*/
|
||||||
function(feature) {
|
function(feature) {
|
||||||
@@ -623,7 +625,7 @@ class VectorSource extends Source {
|
|||||||
* Get the features collection associated with this source. Will be `null`
|
* Get the features collection associated with this source. Will be `null`
|
||||||
* unless the source was configured with `useSpatialIndex` set to `false`, or
|
* unless the source was configured with `useSpatialIndex` set to `false`, or
|
||||||
* with an {@link module:ol/Collection} as `features`.
|
* with an {@link module:ol/Collection} as `features`.
|
||||||
* @return {Collection<import("../Feature.js").default>} The collection of features.
|
* @return {Collection<import("../Feature.js").default<Geometry>>} The collection of features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getFeaturesCollection() {
|
getFeaturesCollection() {
|
||||||
@@ -633,7 +635,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all features on the source in random order.
|
* Get all features on the source in random order.
|
||||||
* @return {Array<import("../Feature.js").default>} Features.
|
* @return {Array<import("../Feature.js").default<Geometry>>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getFeatures() {
|
getFeatures() {
|
||||||
@@ -647,7 +649,7 @@ class VectorSource extends Source {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
/** @type {Array<import("../Feature.js").default>} */ (features)
|
/** @type {Array<import("../Feature.js").default<Geometry>>} */ (features)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,7 +657,7 @@ class VectorSource extends Source {
|
|||||||
/**
|
/**
|
||||||
* Get all features whose geometry intersects the provided coordinate.
|
* Get all features whose geometry intersects the provided coordinate.
|
||||||
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
||||||
* @return {Array<import("../Feature.js").default>} Features.
|
* @return {Array<import("../Feature.js").default<Geometry>>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getFeaturesAtCoordinate(coordinate) {
|
getFeaturesAtCoordinate(coordinate) {
|
||||||
@@ -675,7 +677,7 @@ class VectorSource extends Source {
|
|||||||
* This method is not available when the source is configured with
|
* This method is not available when the source is configured with
|
||||||
* `useSpatialIndex` set to `false`.
|
* `useSpatialIndex` set to `false`.
|
||||||
* @param {import("../extent.js").Extent} extent Extent.
|
* @param {import("../extent.js").Extent} extent Extent.
|
||||||
* @return {Array<import("../Feature.js").default>} Features.
|
* @return {Array<import("../Feature.js").default<Geometry>>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getFeaturesInExtent(extent) {
|
getFeaturesInExtent(extent) {
|
||||||
@@ -689,10 +691,10 @@ class VectorSource extends Source {
|
|||||||
* This method is not available when the source is configured with
|
* This method is not available when the source is configured with
|
||||||
* `useSpatialIndex` set to `false`.
|
* `useSpatialIndex` set to `false`.
|
||||||
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
||||||
* @param {function(import("../Feature.js").default):boolean=} opt_filter Feature filter function.
|
* @param {function(import("../Feature.js").default<Geometry>):boolean=} opt_filter Feature filter function.
|
||||||
* The filter function will receive one argument, the {@link module:ol/Feature feature}
|
* The filter function will receive one argument, the {@link module:ol/Feature feature}
|
||||||
* and it should return a boolean value. By default, no filtering is made.
|
* and it should return a boolean value. By default, no filtering is made.
|
||||||
* @return {import("../Feature.js").default} Closest feature.
|
* @return {import("../Feature.js").default<Geometry>} Closest feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getClosestFeatureToCoordinate(coordinate, opt_filter) {
|
getClosestFeatureToCoordinate(coordinate, opt_filter) {
|
||||||
@@ -712,7 +714,7 @@ class VectorSource extends Source {
|
|||||||
const filter = opt_filter ? opt_filter : TRUE;
|
const filter = opt_filter ? opt_filter : TRUE;
|
||||||
this.featuresRtree_.forEachInExtent(extent,
|
this.featuresRtree_.forEachInExtent(extent,
|
||||||
/**
|
/**
|
||||||
* @param {import("../Feature.js").default} feature Feature.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature.
|
||||||
*/
|
*/
|
||||||
function(feature) {
|
function(feature) {
|
||||||
if (filter(feature)) {
|
if (filter(feature)) {
|
||||||
@@ -759,7 +761,7 @@ class VectorSource extends Source {
|
|||||||
* `source.getFeatureById(2)` will return a feature with id `'2'` or `2`.
|
* `source.getFeatureById(2)` will return a feature with id `'2'` or `2`.
|
||||||
*
|
*
|
||||||
* @param {string|number} id Feature identifier.
|
* @param {string|number} id Feature identifier.
|
||||||
* @return {import("../Feature.js").default} The feature (or `null` if not found).
|
* @return {import("../Feature.js").default<Geometry>} The feature (or `null` if not found).
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
getFeatureById(id) {
|
getFeatureById(id) {
|
||||||
@@ -803,7 +805,7 @@ class VectorSource extends Source {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
handleFeatureChange_(event) {
|
handleFeatureChange_(event) {
|
||||||
const feature = /** @type {import("../Feature.js").default} */ (event.target);
|
const feature = /** @type {import("../Feature.js").default<Geometry>} */ (event.target);
|
||||||
const featureKey = getUid(feature);
|
const featureKey = getUid(feature);
|
||||||
const geometry = feature.getGeometry();
|
const geometry = feature.getGeometry();
|
||||||
if (!geometry) {
|
if (!geometry) {
|
||||||
@@ -851,7 +853,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the feature is contained within the source.
|
* Returns true if the feature is contained within the source.
|
||||||
* @param {import("../Feature.js").default} feature Feature.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature.
|
||||||
* @return {boolean} Has feature.
|
* @return {boolean} Has feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -933,7 +935,7 @@ class VectorSource extends Source {
|
|||||||
* Remove a single feature from the source. If you want to remove all features
|
* Remove a single feature from the source. If you want to remove all features
|
||||||
* at once, use the {@link module:ol/source/Vector~VectorSource#clear #clear()} method
|
* at once, use the {@link module:ol/source/Vector~VectorSource#clear #clear()} method
|
||||||
* instead.
|
* instead.
|
||||||
* @param {import("../Feature.js").default} feature Feature to remove.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature to remove.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
removeFeature(feature) {
|
removeFeature(feature) {
|
||||||
@@ -952,7 +954,7 @@ class VectorSource extends Source {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove feature without firing a `change` event.
|
* Remove feature without firing a `change` event.
|
||||||
* @param {import("../Feature.js").default} feature Feature.
|
* @param {import("../Feature.js").default<Geometry>} feature Feature.
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
removeFeatureInternal(feature) {
|
removeFeatureInternal(feature) {
|
||||||
@@ -973,7 +975,7 @@ class VectorSource extends Source {
|
|||||||
/**
|
/**
|
||||||
* Remove a feature from the id index. Called internally when the feature id
|
* Remove a feature from the id index. Called internally when the feature id
|
||||||
* may have changed.
|
* may have changed.
|
||||||
* @param {import("../Feature.js").default} feature The feature.
|
* @param {import("../Feature.js").default<Geometry>} feature The feature.
|
||||||
* @return {boolean} Removed the feature from the index.
|
* @return {boolean} Removed the feature from the index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user