Merge remote-tracking branch 'openlayers/master' into vector-api
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
goog.provide('ol.Feature');
|
||||
goog.provide('ol.FeatureEvent');
|
||||
goog.provide('ol.FeatureEventType');
|
||||
goog.provide('ol.FeatureRenderIntent');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
goog.require('ol.layer.VectorLayerRenderIntent');
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +27,12 @@ goog.require('ol.layer.VectorLayerRenderIntent');
|
||||
*/
|
||||
ol.Feature = function(opt_values) {
|
||||
|
||||
/**
|
||||
* @type {ol.Extent}
|
||||
* @private
|
||||
*/
|
||||
this.geometryExtent_ = null;
|
||||
|
||||
goog.base(this, opt_values);
|
||||
|
||||
/**
|
||||
@@ -42,19 +47,12 @@ ol.Feature = function(opt_values) {
|
||||
*/
|
||||
this.geometryName_;
|
||||
|
||||
/**
|
||||
* Original of this feature when it was modified.
|
||||
* @type {ol.Feature}
|
||||
* @private
|
||||
*/
|
||||
this.original_ = null;
|
||||
|
||||
/**
|
||||
* The render intent for this feature.
|
||||
* @type {ol.layer.VectorLayerRenderIntent|string}
|
||||
* @type {ol.FeatureRenderIntent|string}
|
||||
* @private
|
||||
*/
|
||||
this.renderIntent_ = ol.layer.VectorLayerRenderIntent.DEFAULT;
|
||||
this.renderIntent_ = ol.FeatureRenderIntent.DEFAULT;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.style.Symbolizer>}
|
||||
@@ -114,15 +112,6 @@ ol.Feature.prototype.getGeometry = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the original of this feature when it was modified.
|
||||
* @return {ol.Feature} Original.
|
||||
*/
|
||||
ol.Feature.prototype.getOriginal = function() {
|
||||
return this.original_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get any symbolizers set directly on the feature.
|
||||
* @return {Array.<ol.style.Symbolizer>} Symbolizers (or null if none).
|
||||
@@ -134,12 +123,14 @@ ol.Feature.prototype.getSymbolizers = function() {
|
||||
|
||||
/**
|
||||
* Listener for geometry change events.
|
||||
* @param {ol.geom.GeometryEvent} evt Geometry event.
|
||||
* @param {goog.events.Event} evt Change event.
|
||||
* @private
|
||||
*/
|
||||
ol.Feature.prototype.handleGeometryChange_ = function(evt) {
|
||||
var oldExtent = this.geometryExtent_;
|
||||
this.geometryExtent_ = this.getGeometry().getBounds();
|
||||
this.dispatchEvent(new ol.FeatureEvent(
|
||||
ol.FeatureEventType.CHANGE, this, evt.oldExtent));
|
||||
ol.FeatureEventType.CHANGE, this, oldExtent));
|
||||
};
|
||||
|
||||
|
||||
@@ -151,10 +142,10 @@ ol.Feature.prototype.handleGeometryChange_ = function(evt) {
|
||||
*/
|
||||
ol.Feature.prototype.set = function(key, value) {
|
||||
var geometry = this.getGeometry();
|
||||
var oldExtent = null;
|
||||
var oldExtent = this.geometryExtent_;
|
||||
if (goog.isDefAndNotNull(geometry)) {
|
||||
oldExtent = geometry.getBounds();
|
||||
if (key === this.geometryName_) {
|
||||
this.geometryExtent_ = null;
|
||||
goog.events.unlisten(geometry, goog.events.EventType.CHANGE,
|
||||
this.handleGeometryChange_, false, this);
|
||||
}
|
||||
@@ -164,6 +155,7 @@ ol.Feature.prototype.set = function(key, value) {
|
||||
this.geometryName_ = key;
|
||||
}
|
||||
if (key === this.geometryName_) {
|
||||
this.geometryExtent_ = value.getBounds();
|
||||
goog.events.listen(value, goog.events.EventType.CHANGE,
|
||||
this.handleGeometryChange_, false, this);
|
||||
}
|
||||
@@ -198,15 +190,6 @@ ol.Feature.prototype.setGeometry = function(geometry) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the original of this feature when it was modified.
|
||||
* @param {ol.Feature} original Original.
|
||||
*/
|
||||
ol.Feature.prototype.setOriginal = function(original) {
|
||||
this.original_ = original;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the renderIntent for this feature.
|
||||
* @return {string} Render intent.
|
||||
@@ -247,6 +230,18 @@ ol.Feature.prototype.setSymbolizers = function(symbolizers) {
|
||||
ol.Feature.DEFAULT_GEOMETRY = 'geometry';
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.FeatureRenderIntent = {
|
||||
DEFAULT: 'default',
|
||||
FUTURE: 'future',
|
||||
HIDDEN: 'hidden',
|
||||
SELECTED: 'selected',
|
||||
TEMPORARY: 'temporary'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
goog.provide('ol.geom.AbstractCollection');
|
||||
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
|
||||
|
||||
|
||||
@@ -77,21 +75,12 @@ ol.geom.AbstractCollection.prototype.getType = goog.abstractMethod;
|
||||
|
||||
/**
|
||||
* Listener for component change events.
|
||||
* @param {ol.geom.GeometryEvent} evt Geometry event.
|
||||
* @param {goog.events.Event} evt Change event.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.AbstractCollection.prototype.handleComponentChange = function(evt) {
|
||||
this.bounds = null;
|
||||
var oldExtent = ol.extent.createEmpty();
|
||||
var components = this.components;
|
||||
for (var i = components.length - 1; i >= 0; --i) {
|
||||
var component = components[i];
|
||||
ol.extent.extend(oldExtent,
|
||||
component === evt.target && !goog.isNull(evt.oldExtent) ?
|
||||
evt.oldExtent : component.getBounds());
|
||||
}
|
||||
this.dispatchEvent(new ol.geom.GeometryEvent(goog.events.EventType.CHANGE,
|
||||
this, oldExtent));
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
goog.provide('ol.geom.GeometryEvent');
|
||||
goog.provide('ol.geom.GeometryType');
|
||||
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Observable');
|
||||
goog.require('ol.TransformFunction');
|
||||
|
||||
|
||||
/**
|
||||
* Geometry types.
|
||||
*
|
||||
* @enum {string}
|
||||
* @todo stability stable
|
||||
*/
|
||||
ol.geom.GeometryType = {
|
||||
POINT: 'Point',
|
||||
LINE_STRING: 'LineString',
|
||||
LINEAR_RING: 'LinearRing',
|
||||
POLYGON: 'Polygon',
|
||||
MULTI_POINT: 'MultiPoint',
|
||||
MULTI_LINE_STRING: 'MultiLineString',
|
||||
MULTI_POLYGON: 'MultiPolygon',
|
||||
GEOMETRY_COLLECTION: 'GeometryCollection'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {goog.events.EventTarget}
|
||||
* @extends {ol.Observable}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Geometry = function() {
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.geom.Geometry, goog.events.EventTarget);
|
||||
goog.inherits(ol.geom.Geometry, ol.Observable);
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,36 +74,9 @@ ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||
ol.geom.Geometry.prototype.transform = goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for geometry events.
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
* @param {string} type Event type.
|
||||
* @param {ol.geom.Geometry} target The target geometry.
|
||||
* @param {ol.Extent} oldExtent The previous geometry extent.
|
||||
* Dispatch a generic event with type "change."
|
||||
*/
|
||||
ol.geom.GeometryEvent = function(type, target, oldExtent) {
|
||||
goog.base(this, type, target);
|
||||
|
||||
this.oldExtent = oldExtent;
|
||||
};
|
||||
goog.inherits(ol.geom.GeometryEvent, goog.events.Event);
|
||||
|
||||
|
||||
/**
|
||||
* Geometry types.
|
||||
*
|
||||
* @enum {string}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.GeometryType = {
|
||||
POINT: 'point',
|
||||
LINESTRING: 'linestring',
|
||||
LINEARRING: 'linearring',
|
||||
POLYGON: 'polygon',
|
||||
MULTIPOINT: 'multipoint',
|
||||
MULTILINESTRING: 'multilinestring',
|
||||
MULTIPOLYGON: 'multipolygon',
|
||||
GEOMETRYCOLLECTION: 'geometrycollection'
|
||||
ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
|
||||
|
||||
@@ -15,7 +13,7 @@ goog.require('ol.geom.GeometryType');
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.CoordinateArray} coordinates Array of coordinates (e.g.
|
||||
* [[x0, y0], [x1, y1]]).
|
||||
* `[[x0, y0], [x1, y1]]`).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.LineString = function(coordinates) {
|
||||
@@ -90,7 +88,7 @@ ol.geom.LineString.prototype.getBounds = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LineString.prototype.getType = function() {
|
||||
return ol.geom.GeometryType.LINESTRING;
|
||||
return ol.geom.GeometryType.LINE_STRING;
|
||||
};
|
||||
|
||||
|
||||
@@ -116,11 +114,9 @@ ol.geom.LineString.prototype.distanceFromCoordinate = function(coordinate) {
|
||||
* @param {ol.CoordinateArray} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setCoordinates = function(coordinates) {
|
||||
var oldBounds = this.bounds_;
|
||||
this.bounds_ = null;
|
||||
this.coordinates_ = coordinates;
|
||||
this.dispatchEvent(new ol.geom.GeometryEvent(goog.events.EventType.CHANGE,
|
||||
this, oldBounds));
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
@@ -134,5 +130,5 @@ ol.geom.LineString.prototype.transform = function(transform) {
|
||||
coord = coordinates[i];
|
||||
transform(coord, coord, coord.length);
|
||||
}
|
||||
this.setCoordinates(coordinates); // for change event
|
||||
this.setCoordinates(coordinates); // for invalidating bounds
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
|
||||
|
||||
@@ -12,7 +10,7 @@ goog.require('ol.geom.GeometryType');
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.Coordinate} coordinates Coordinate values (e.g. [x, y]).
|
||||
* @param {ol.Coordinate} coordinates Coordinate values (e.g. `[x, y]`).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.Point = function(coordinates) {
|
||||
@@ -79,11 +77,9 @@ ol.geom.Point.prototype.getType = function() {
|
||||
* @param {ol.Coordinate} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.Point.prototype.setCoordinates = function(coordinates) {
|
||||
var oldBounds = this.bounds_;
|
||||
this.bounds_ = null;
|
||||
this.coordinates_ = coordinates;
|
||||
this.dispatchEvent(new ol.geom.GeometryEvent(goog.events.EventType.CHANGE,
|
||||
this, oldBounds));
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
@@ -93,5 +89,5 @@ ol.geom.Point.prototype.setCoordinates = function(coordinates) {
|
||||
ol.geom.Point.prototype.transform = function(transform) {
|
||||
var coordinates = this.getCoordinates();
|
||||
transform(coordinates, coordinates, coordinates.length);
|
||||
this.setCoordinates(coordinates); // for change event
|
||||
this.setCoordinates(coordinates); // for invalidating bounds
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ goog.require('goog.events.EventType');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
|
||||
@@ -108,19 +107,11 @@ ol.geom.Polygon.prototype.getRings = function() {
|
||||
|
||||
/**
|
||||
* Listener for ring change events.
|
||||
* @param {ol.geom.GeometryEvent} evt Geometry event.
|
||||
* @param {goog.events.Event} evt Change event.
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Polygon.prototype.handleRingChange_ = function(evt) {
|
||||
var ring = evt.target;
|
||||
var oldExtent = null;
|
||||
if (ring === this.rings_[0]) {
|
||||
oldExtent = evt.oldExtent;
|
||||
} else {
|
||||
oldExtent = this.getBounds();
|
||||
}
|
||||
this.dispatchEvent(new ol.geom.GeometryEvent(goog.events.EventType.CHANGE,
|
||||
this, oldExtent));
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.MapBrowserEvent.EventType');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
@@ -209,6 +210,7 @@ ol.interaction.Draw.prototype.atFinish_ = function(event) {
|
||||
if (this.mode_ === ol.interaction.DrawMode.LINESTRING) {
|
||||
potentiallyDone = geometry.getCoordinates().length > 2;
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
potentiallyDone = geometry.getRings()[0].getCoordinates().length > 3;
|
||||
}
|
||||
if (potentiallyDone) {
|
||||
@@ -270,22 +272,29 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
|
||||
var geometry = this.sketchFeature_.getGeometry();
|
||||
var coordinates, last;
|
||||
if (this.mode_ === ol.interaction.DrawMode.POINT) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||
last = geometry.getCoordinates();
|
||||
last[0] = coordinate[0];
|
||||
last[1] = coordinate[1];
|
||||
geometry.setCoordinates(last);
|
||||
} else {
|
||||
if (this.mode_ === ol.interaction.DrawMode.LINESTRING) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
coordinates = geometry.getCoordinates();
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
} else {
|
||||
goog.asserts.assert(this.mode_ === ol.interaction.DrawMode.POLYGON);
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
geometry = geometry.getRings()[0];
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LinearRing);
|
||||
coordinates = geometry.getCoordinates();
|
||||
}
|
||||
if (this.atFinish_(event)) {
|
||||
// snap to finish
|
||||
coordinate = this.finishCoordinate_.slice();
|
||||
}
|
||||
this.sketchPoint_.getGeometry().setCoordinates(coordinate);
|
||||
var point = this.sketchPoint_.getGeometry();
|
||||
goog.asserts.assertInstanceof(point, ol.geom.Point);
|
||||
point.setCoordinates(coordinate);
|
||||
last = coordinates[coordinates.length - 1];
|
||||
last[0] = coordinate[0];
|
||||
last[1] = coordinate[1];
|
||||
@@ -304,11 +313,13 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
|
||||
var geometry = this.sketchFeature_.getGeometry();
|
||||
var coordinates, last;
|
||||
if (this.mode_ === ol.interaction.DrawMode.LINESTRING) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
this.finishCoordinate_ = coordinate.slice();
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates.push(coordinate.slice());
|
||||
geometry.setCoordinates(coordinates);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
var ring = geometry.getRings()[0];
|
||||
coordinates = ring.getCoordinates();
|
||||
coordinates.push(coordinate.slice());
|
||||
@@ -329,10 +340,12 @@ ol.interaction.Draw.prototype.finishDrawing_ = function(event) {
|
||||
var geometry = sketchFeature.getGeometry();
|
||||
var coordinates = geometry.getCoordinates();
|
||||
if (this.mode_ === ol.interaction.DrawMode.LINESTRING) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
// remove the redundant last point
|
||||
coordinates.pop();
|
||||
geometry.setCoordinates(coordinates);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
// force clockwise order for exterior ring
|
||||
sketchFeature.setGeometry(new ol.geom.Polygon(coordinates));
|
||||
}
|
||||
|
||||
@@ -339,8 +339,9 @@ ol.interaction.Modify.prototype.createOrUpdateVertexFeature_ =
|
||||
this.vertexFeature_ = vertexFeature;
|
||||
this.sketchLayer_.getVectorSource().addFeatures([vertexFeature]);
|
||||
} else {
|
||||
var geometry = vertexFeature.getGeometry();
|
||||
geometry.setCoordinates(coordinates);
|
||||
var point = vertexFeature.getGeometry();
|
||||
goog.asserts.assertInstanceof(point, ol.geom.Point);
|
||||
point.setCoordinates(coordinates);
|
||||
}
|
||||
if (this.sketchLayer_.getStyle() !== style) {
|
||||
this.sketchLayer_.setStyle(style);
|
||||
@@ -505,6 +506,7 @@ ol.interaction.Modify.prototype.insertVertex_ =
|
||||
var segment = segmentData.segment;
|
||||
var feature = segmentData.feature;
|
||||
var geometry = segmentData.geometry;
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
var index = segmentData.index;
|
||||
var coordinates = geometry.getCoordinates();
|
||||
coordinates.splice(index + 1, 0, vertex);
|
||||
|
||||
@@ -272,6 +272,7 @@ ol.renderer.canvas.Vector.prototype.renderPointFeatures_ =
|
||||
}
|
||||
for (j = 0, jj = components.length; j < jj; ++j) {
|
||||
point = components[j];
|
||||
goog.asserts.assertInstanceof(point, ol.geom.Point);
|
||||
vec = [point.get(0), point.get(1), 0];
|
||||
goog.vec.Mat4.multVec3(this.transform_, vec, vec);
|
||||
context.drawImage(content, Math.round(vec[0] + xOffset),
|
||||
@@ -404,6 +405,7 @@ ol.renderer.canvas.Vector.prototype.renderPolygonFeatures_ =
|
||||
}
|
||||
for (j = 0, jj = components.length; j < jj; ++j) {
|
||||
poly = components[j];
|
||||
goog.asserts.assertInstanceof(poly, ol.geom.Polygon);
|
||||
rings = poly.getRings();
|
||||
numRings = rings.length;
|
||||
if (numRings > 0) {
|
||||
@@ -535,9 +537,11 @@ ol.renderer.canvas.Vector.getLabelVectors = function(geometry) {
|
||||
}
|
||||
var type = geometry.getType();
|
||||
if (type == ol.geom.GeometryType.POINT) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||
return [[geometry.get(0), geometry.get(1), 0]];
|
||||
}
|
||||
if (type == ol.geom.GeometryType.POLYGON) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
var coordinates = geometry.getInteriorPoint();
|
||||
return [[coordinates[0], coordinates[1], 0]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user