Move code to be merged into src/attic
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
goog.provide('ol.Feature');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
*/
|
||||
ol.Feature = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.geom.Geometry}
|
||||
*/
|
||||
this.geometry_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.attributes_ = {};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.geom.Geometry} The geometry associated with the feature.
|
||||
*/
|
||||
ol.Feature.prototype.getGeometry = function() {
|
||||
return this.geometry_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geom the geometry for the feature.
|
||||
*/
|
||||
ol.Feature.prototype.setGeometry = function(geom) {
|
||||
this.geometry_ = geom;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!string} name the attribute value to retrieve.
|
||||
@return {string|number|boolean} the attribute value.
|
||||
*/
|
||||
ol.Feature.prototype.getAttribute = function(name) {
|
||||
return this.attributes_[name];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!string} name of the attribute to set.
|
||||
* @param {string|number|boolean} value the attribute value to set.
|
||||
*/
|
||||
ol.Feature.prototype.setAttribute = function(name, value) {
|
||||
this.attributes_[name] = value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} attrs An json structure containing key/value pairs.
|
||||
*/
|
||||
ol.Feature.prototype.setAttributes = function(attrs) {
|
||||
for (var key in attrs) {
|
||||
this.setAttribute(key, attrs[key]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Feature.prototype.destroy = function() {
|
||||
//remove attributes and geometry, etc.
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
-342
@@ -1,342 +0,0 @@
|
||||
goog.provide('ol.Popup');
|
||||
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Feature');
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @param {ol.Map} map the map on which the popup is placed.
|
||||
* @param {ol.Loc|ol.Feature=} opt_anchor the anchor object for the popup.
|
||||
* @param {string=} opt_placement the placement of the arrow on the popup.
|
||||
* @param {boolean=} opt_close include a close button on the popup
|
||||
*/
|
||||
ol.Popup = function(map, opt_anchor, opt_placement, opt_close) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Map}
|
||||
*/
|
||||
this.map_ = map;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Loc|ol.Feature|undefined}
|
||||
*/
|
||||
this.anchor_ = opt_anchor;
|
||||
|
||||
/**
|
||||
* can be 'top','bottom','right','left','auto'
|
||||
* TODO: 'auto' not yet implemented
|
||||
* @private
|
||||
* @type {!string}
|
||||
*/
|
||||
this.placement_ = goog.isDefAndNotNull(opt_placement)?opt_placement:'top';
|
||||
|
||||
/**
|
||||
* include a close button on the popup - defaults to true.
|
||||
* @private
|
||||
* @type {boolean|undefined}
|
||||
*/
|
||||
this.closeButton_ = goog.isDefAndNotNull(opt_close) ? opt_close : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.content_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.template_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.container_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.arrowOffset_ = 30; //FIXME: set this from CSS dynamically somehow?
|
||||
|
||||
/**
|
||||
* if the CSS sets either width or height assume the app is specifying the
|
||||
* size of the popup, if not auto size the popup.
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.autoSize_ = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
ol.Popup.CLASS_NAME = 'ol-popup';
|
||||
|
||||
/**
|
||||
* @return {ol.Map} Projection.
|
||||
*/
|
||||
ol.Popup.prototype.getMap = function() {
|
||||
return this.map_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map the map object to hold this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setMap = function(map) {
|
||||
this.map_ = map;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Feature|ol.Loc|undefined} the anchor .
|
||||
*/
|
||||
ol.Popup.prototype.getAnchor = function() {
|
||||
return this.anchor_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Feature|ol.Loc} anchor the anchor location to place this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setAnchor = function(anchor) {
|
||||
this.anchor_ = anchor;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} the placement value relative to the anchor.
|
||||
*/
|
||||
ol.Popup.prototype.getPlacement = function() {
|
||||
return this.placement_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} placement where to place this popup relative to the anchor.
|
||||
*/
|
||||
ol.Popup.prototype.setPlacement = function(placement) {
|
||||
if (!goog.isNull(this.container_)) {
|
||||
goog.dom.classes.remove(this.container_,
|
||||
ol.Popup.CLASS_NAME+'-'+this.placement_);
|
||||
goog.dom.classes.add(this.container_,ol.Popup.CLASS_NAME+'-'+placement);
|
||||
}
|
||||
this.placement_ = placement;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} static content to be displayed in the popup (HTML)
|
||||
*/
|
||||
ol.Popup.prototype.getContent = function() {
|
||||
return this.content_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} content the content to be displayed this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setContent = function(content) {
|
||||
this.content_ = content;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {string} generates the content
|
||||
*/
|
||||
ol.Popup.prototype.generateContent_ = function() {
|
||||
//set the content
|
||||
if ( goog.isDefAndNotNull(this.content_) ) {
|
||||
return this.content_;
|
||||
} else {
|
||||
if ( goog.isDefAndNotNull(this.template_) &&
|
||||
goog.isDefAndNotNull(this.anchor_) &&
|
||||
(this.anchor_ instanceof ol.Feature)) {
|
||||
//set content from feature attributes on the template
|
||||
//TODO: this.setContent(template.apply(this.anchor_.getAttributes()));
|
||||
return this.template_; //stub to return something
|
||||
} else {
|
||||
ol.error('ol.Popup unabale to generate any content');
|
||||
return '<p>no content</p>';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} the anchor .
|
||||
*/
|
||||
ol.Popup.prototype.getTemplate = function() {
|
||||
return this.template_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} template the map object to hold this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setTemplate = function(template) {
|
||||
this.template_ = template;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open the popup.
|
||||
* @param {ol.Feature|ol.Loc} opt_arg feature or location for the anchor
|
||||
*/
|
||||
ol.Popup.prototype.doOpen = function(opt_arg) {
|
||||
if (goog.isDef(opt_arg)) {
|
||||
this.setAnchor(opt_arg);
|
||||
}
|
||||
|
||||
//create popup container if it's not created already
|
||||
if (goog.isNull(this.container_)) {
|
||||
this.container_ = goog.dom.createElement('div');
|
||||
goog.dom.classes.add(this.container_,
|
||||
ol.Popup.CLASS_NAME, ol.Popup.CLASS_NAME+'-'+this.placement_);
|
||||
|
||||
//see if the style class sets width or height
|
||||
if (goog.style.getStyle(this.container_, 'width').length>0 ||
|
||||
goog.style.getStyle(this.container_, 'height').length>0 ) {
|
||||
this.autoSize_ = false;
|
||||
}
|
||||
|
||||
if (this.closeButton_) {
|
||||
var closeButton = goog.dom.createElement('div');
|
||||
goog.dom.appendChild(this.container_, closeButton);
|
||||
goog.dom.classes.add(closeButton, ol.Popup.CLASS_NAME+'-close');
|
||||
}
|
||||
this.map_.getEvents().register('click', this.clickHandler, this);
|
||||
goog.dom.appendChild(this.map_.getMapOverlay(), this.container_);
|
||||
}
|
||||
|
||||
this.childContent_=goog.dom.htmlToDocumentFragment(this.generateContent_());
|
||||
goog.dom.appendChild(this.container_, this.childContent_);
|
||||
|
||||
if (this.autoSize_) {
|
||||
this.registerImageListeners();
|
||||
}
|
||||
|
||||
this.setAnchorOffset_();
|
||||
};
|
||||
|
||||
ol.Popup.prototype.setAnchorOffset_ = function() {
|
||||
|
||||
if (goog.isNull(this.container_.parentNode)) {
|
||||
//this means the popup has already been closed, nothing to do here
|
||||
//which might happen while waiting for images to load
|
||||
return;
|
||||
}
|
||||
|
||||
if (!goog.isDefAndNotNull(this.anchor_)) {
|
||||
//must have an anchor when trying to set the position
|
||||
ol.error("ol.Popup must have an anchor to set the position");
|
||||
return;
|
||||
}
|
||||
|
||||
//position the element
|
||||
if (this.anchor_ instanceof ol.Feature) {
|
||||
this.pos_ = this.anchor_.getGeometry().getCentroid();
|
||||
} else {
|
||||
this.pos_ = new ol.geom.Point(this.anchor_.getX(), this.anchor_.getY());
|
||||
}
|
||||
var pos = /** @type {ol.Loc} */ (this.pos_);
|
||||
var popupPosPx = this.map_.getPixelForLoc(pos);
|
||||
var popupSize = goog.style.getSize(this.container_);
|
||||
|
||||
switch(this.placement_) {
|
||||
default:
|
||||
case 'auto':
|
||||
//TODO: switch based on map quadrant
|
||||
break;
|
||||
case 'top':
|
||||
case 'bottom':
|
||||
popupPosPx[0] -= popupSize.width / 2.0;
|
||||
|
||||
if (this.placement_ == "bottom") {
|
||||
popupPosPx[1] -= popupSize.height + this.arrowOffset_;
|
||||
} else {
|
||||
popupPosPx[1] += this.arrowOffset_;
|
||||
}
|
||||
break;
|
||||
case 'left':
|
||||
case 'right':
|
||||
popupPosPx[1] -= popupSize.height / 2.0;
|
||||
|
||||
if (this.placement_ == "right") {
|
||||
popupPosPx[0] -= popupSize.width + this.arrowOffset_;
|
||||
} else {
|
||||
popupPosPx[0] += this.arrowOffset_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.moveTo_(popupPosPx);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* registerImageListeners
|
||||
* Called when an image contained by the popup loaded. this function
|
||||
* updates the popup size, then unregisters the image load listener.
|
||||
*/
|
||||
ol.Popup.prototype.registerImageListeners = function() {
|
||||
|
||||
// As the images load, this function will call setAnchorOffset_() to
|
||||
// resize the popup to fit the content div (which presumably is now
|
||||
// bigger than when the image was not loaded).
|
||||
//
|
||||
//cycle through the images and if their size is 0x0, that means that
|
||||
// they haven't been loaded yet, so we attach the listener, which
|
||||
// will fire when the images finish loading and will resize the
|
||||
// popup accordingly to its new size.
|
||||
var images = this.container_.getElementsByTagName("img");
|
||||
for (var i = 0, len = images.length; i < len; i++) {
|
||||
var img = images[i];
|
||||
if (img.width == 0 || img.height == 0) {
|
||||
goog.events.listenOnce(img, 'load',
|
||||
goog.bind(this.setAnchorOffset_, this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param px - {goog.} the top and left position of the popup div.
|
||||
*/
|
||||
ol.Popup.prototype.moveTo_ = function(px) {
|
||||
if (goog.isDefAndNotNull(px)) {
|
||||
goog.style.setPosition(this.container_, px[0], px[1]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Click handler
|
||||
* @param {Event} evt the event generated by a click
|
||||
*/
|
||||
ol.Popup.prototype.clickHandler = function(evt) {
|
||||
var target = /** @type {Node} */ evt.target;
|
||||
if (goog.dom.classes.has(target,ol.Popup.CLASS_NAME+'-close')) {
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @export
|
||||
*/
|
||||
ol.Popup.prototype.close = function() {
|
||||
goog.dom.removeChildren(this.container_);
|
||||
goog.dom.removeNode(this.container_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @export
|
||||
*/
|
||||
ol.Popup.prototype.destroy = function() {
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
@@ -1,46 +0,0 @@
|
||||
goog.provide('ol.base');
|
||||
goog.provide('ol.error');
|
||||
|
||||
/**
|
||||
* @param {string} message Message.
|
||||
*/
|
||||
ol.error = function(message) {
|
||||
if (ol.error.VERBOSE_ERRORS) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
throw null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compilation with public API, let's accept options from external world
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.API = true;
|
||||
|
||||
/**
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.error.VERBOSE_ERRORS = true;
|
||||
|
||||
/**
|
||||
* Options passed in the API from external world are checked for wrong keys
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.CHECK_KEYS = true;
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object.
|
||||
* @param {!Array.<string>} allowedKeys Allowed keys.
|
||||
*/
|
||||
ol.base.checkKeys = function(obj, allowedKeys) {
|
||||
if (ol.CHECK_KEYS) {
|
||||
var keys = goog.object.getKeys(obj);
|
||||
goog.array.forEach(allowedKeys, function(allowedKey) {
|
||||
goog.array.remove(keys, allowedKey);
|
||||
});
|
||||
if (!goog.array.isEmpty(keys)) {
|
||||
ol.error('object contains invalid keys: ' + keys.join(', '));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,83 +0,0 @@
|
||||
goog.provide('ol.event.Drag');
|
||||
|
||||
goog.require('ol.event');
|
||||
goog.require('ol.event.ISequence');
|
||||
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.fx.Dragger');
|
||||
goog.require('goog.fx.DragEvent');
|
||||
goog.require('goog.fx.Dragger.EventType');
|
||||
|
||||
|
||||
/**
|
||||
* Event sequence that provides a 'dragstart', 'drag' and 'dragend' events.
|
||||
* Event objects of the 'drag' events have 'deltaX' and 'deltaY' values with
|
||||
* the relative pixel movement since the previous 'drag' or 'dragstart' event.
|
||||
*
|
||||
* @constructor
|
||||
* @param {ol.event.Events} target The Events instance that handles events.
|
||||
* @implements {ol.event.ISequence}
|
||||
* @export
|
||||
*/
|
||||
ol.event.Drag = function(target) {
|
||||
var previousX = 0, previousY = 0,
|
||||
element = target.getElement(),
|
||||
dragger = new goog.fx.Dragger(element);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.fx.Dragger}
|
||||
*/
|
||||
this.dragger_ = dragger;
|
||||
|
||||
// We want to swallow the click event that gets fired after dragging.
|
||||
var newSequence;
|
||||
function unregisterClickStopper() {
|
||||
target.unregister('click', goog.functions.FALSE, undefined, true);
|
||||
}
|
||||
|
||||
dragger.defaultAction = function(x, y) {};
|
||||
dragger.addEventListener(goog.fx.Dragger.EventType.START, function(evt) {
|
||||
evt.target = element;
|
||||
evt.type = 'dragstart';
|
||||
previousX = evt.clientX;
|
||||
previousY = evt.clientY;
|
||||
newSequence = true;
|
||||
target.triggerEvent(evt.type, evt);
|
||||
});
|
||||
dragger.addEventListener(goog.fx.Dragger.EventType.DRAG, function(evt) {
|
||||
evt.target = element;
|
||||
evt.deltaX = evt.clientX - previousX;
|
||||
evt.deltaY = evt.clientY - previousY;
|
||||
previousX = evt.clientX;
|
||||
previousY = evt.clientY;
|
||||
if (newSequence) {
|
||||
// Once we are in the drag sequence, we know that we need to
|
||||
// get rid of the click event that gets fired when we are done
|
||||
// dragging.
|
||||
target.register('click', goog.functions.FALSE, undefined, true);
|
||||
newSequence = false;
|
||||
}
|
||||
target.triggerEvent(evt.type, evt);
|
||||
});
|
||||
dragger.addEventListener(goog.fx.Dragger.EventType.END, function(evt) {
|
||||
evt.target = element;
|
||||
evt.type = 'dragend';
|
||||
target.triggerEvent(evt.type, evt);
|
||||
// Unregister the click stopper in the next cycle
|
||||
window.setTimeout(unregisterClickStopper, 0);
|
||||
});
|
||||
// Don't swallow the click event if our sequence cancels early.
|
||||
dragger.addEventListener(
|
||||
goog.fx.Dragger.EventType.EARLY_CANCEL, unregisterClickStopper
|
||||
);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Drag.prototype.destroy = function() {
|
||||
this.dragger_.dispose();
|
||||
delete this.dragger_;
|
||||
};
|
||||
|
||||
|
||||
ol.event.addSequenceProvider('drag', ol.event.Drag);
|
||||
@@ -1,322 +0,0 @@
|
||||
goog.provide('ol.event');
|
||||
goog.provide('ol.event.Events');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.style');
|
||||
|
||||
/**
|
||||
* @enum {Object}
|
||||
*/
|
||||
ol.event.SEQUENCE_PROVIDER_MAP = {};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Function} Sequence
|
||||
*/
|
||||
ol.event.addSequenceProvider = function(name, Sequence) {
|
||||
ol.event.SEQUENCE_PROVIDER_MAP[name] = Sequence;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine whether event was caused by a single touch
|
||||
*
|
||||
* @param {!Event} evt
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.event.isSingleTouch = function(evt) {
|
||||
return !!(evt.touches && evt.touches.length == 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine whether event was caused by a multi touch
|
||||
*
|
||||
* @param {!Event} evt
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.event.isMultiTouch = function(evt) {
|
||||
return !!(evt.touches && evt.touches.length > 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the event a keyboard event with Enter or Space pressed?
|
||||
*
|
||||
* @param {!Event} evt
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.event.isEnterOrSpace = function(evt) {
|
||||
return evt.type === "keypress" &&
|
||||
(evt.keyCode === goog.events.KeyCodes.ENTER ||
|
||||
evt.keyCode === goog.events.KeyCodes.SPACE ||
|
||||
evt.keyCode === goog.events.KeyCodes.MAC_ENTER);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Construct an ol.event.Events instance.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {goog.events.EventTarget}
|
||||
* @param {Object} object The object we are creating this instance for.
|
||||
* @param {!Element=} opt_element An optional element that we want to
|
||||
* listen to browser events on.
|
||||
* @param {boolean=} opt_includeXY Should the 'xy' property automatically be
|
||||
* created for browser pointer events? In general, this should be false. If
|
||||
* it is true, then pointer events will automatically generate an 'xy'
|
||||
* property on the event object that is passed, which represents the
|
||||
* relative position of the pointer to the {@code element}. Default is
|
||||
* false.
|
||||
* @param {Array.<String>=} opt_sequences Event sequences to register with
|
||||
* this Events instance.
|
||||
*/
|
||||
ol.event.Events = function(object, opt_element, opt_includeXY, opt_sequences) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
* The object that this instance is bound to.
|
||||
*/
|
||||
this.object_ = object;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
* The element that this instance listens to mouse events on.
|
||||
*/
|
||||
this.element_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<String>}
|
||||
*/
|
||||
this.sequenceProviders_ = goog.isDef(opt_sequences) ? opt_sequences : [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.event.ISequence>}
|
||||
*/
|
||||
this.sequences_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.listenerCount_ = {};
|
||||
|
||||
if (goog.isDef(opt_element)) {
|
||||
this.setElement(opt_element);
|
||||
}
|
||||
};
|
||||
goog.inherits(ol.event.Events, goog.events.EventTarget);
|
||||
|
||||
/**
|
||||
* @return {Object} The object that this instance is bound to.
|
||||
*/
|
||||
ol.event.Events.prototype.getObject = function() {
|
||||
return this.object_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean} includeXY
|
||||
*/
|
||||
ol.event.Events.prototype.setIncludeXY = function(includeXY) {
|
||||
this.includeXY_ = includeXY;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Element} The element that this instance currently
|
||||
* listens to browser events on.
|
||||
*/
|
||||
ol.event.Events.prototype.getElement = function() {
|
||||
return this.element_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach this instance to a DOM element. When called, all browser events fired
|
||||
* on the provided element will be relayed by this instance.
|
||||
*
|
||||
* @param {Element|Node} element A DOM element to attach
|
||||
* browser events to. If called without this argument, all browser events
|
||||
* will be detached from the element they are currently attached to.
|
||||
*/
|
||||
ol.event.Events.prototype.setElement = function(element) {
|
||||
var types = goog.events.EventType, t;
|
||||
if (this.element_) {
|
||||
for (t in types) {
|
||||
goog.events.unlisten(
|
||||
this.element_, types[t], this.handleBrowserEvent, true, this
|
||||
);
|
||||
}
|
||||
this.destroySequences();
|
||||
delete this.element_;
|
||||
}
|
||||
this.element_ = /** @type {Element} */ (element) || null;
|
||||
if (goog.isDefAndNotNull(element)) {
|
||||
this.createSequences();
|
||||
for (t in types) {
|
||||
goog.events.listen(
|
||||
element, types[t], this.handleBrowserEvent, true, this
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ol.event.Events.prototype.createSequences = function() {
|
||||
for (var i=0, ii=this.sequenceProviders_.length; i<ii; ++i) {
|
||||
this.sequences_.push(
|
||||
new ol.event.SEQUENCE_PROVIDER_MAP[this.sequenceProviders_[i]](
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
ol.event.Events.prototype.destroySequences = function() {
|
||||
for (var i=this.sequences_.length-1; i>=0; --i) {
|
||||
this.sequences_[i].destroy();
|
||||
}
|
||||
this.sequences_ = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a listener for an event.
|
||||
*
|
||||
* When the event is triggered, the 'listener' function will be called, in the
|
||||
* context of 'scope'. Imagine we were to register an event, specifying an
|
||||
* ol.Bounds instance as 'scope'. When the event is triggered, the context in
|
||||
* the listener function will be our Bounds instance. This means that within
|
||||
* our listener function, we can access the properties and methods of the
|
||||
* Bounds instance through the 'this' keyword. So our listener could execute
|
||||
* something like:
|
||||
*
|
||||
* var leftStr = "Left: " + this.minX();
|
||||
*
|
||||
* @param {string} type Name of the event to register.
|
||||
* @param {Function} listener The callback function.
|
||||
* @param {Object=} opt_scope The object to bind the context to for the
|
||||
* listener. If no scope is specified, default is this intance's 'object'
|
||||
* property.
|
||||
* @param {boolean=} opt_priority Register the listener as priority listener,
|
||||
* so it gets executed before other listeners? Default is false.
|
||||
*/
|
||||
ol.event.Events.prototype.register = function(type, listener, opt_scope,
|
||||
opt_priority) {
|
||||
goog.events.listen(
|
||||
this, type, listener, opt_priority, opt_scope || this.object_
|
||||
);
|
||||
this.listenerCount_[type] = (this.listenerCount_[type] || 0) + 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unregister a listener for an event
|
||||
*
|
||||
* @param {string} type Name of the event to unregister
|
||||
* @param {Function} listener The callback function.
|
||||
* @param {Object=} opt_scope The object to bind the context to for the
|
||||
* listener. If no scope is specified, default is the event's default
|
||||
* scope.
|
||||
* @param {boolean=} opt_priority Listener was registered as priority listener,
|
||||
* so it gets executed before other listeners. Default is false.
|
||||
*/
|
||||
ol.event.Events.prototype.unregister = function(type, listener, opt_scope,
|
||||
opt_priority) {
|
||||
var removed = goog.events.unlisten(
|
||||
this, type, listener, opt_priority, opt_scope || this.object_
|
||||
);
|
||||
if (removed) {
|
||||
this.listenerCount_[type] = (this.listenerCount_[type] || 1) - 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger a specified registered event.
|
||||
*
|
||||
* @param {string} type The type of the event to trigger.
|
||||
* @param {Object=} opt_evt The event object that will be passed to listeners.
|
||||
* This object will always have a 'type' property with the event type and
|
||||
* an 'object' property referencing this Events instance.
|
||||
*
|
||||
* @return {boolean} The last listener return. If a listener returns false,
|
||||
* the chain of listeners will stop getting called. Returns undefined if
|
||||
* called for an event type that has no listeners.
|
||||
*/
|
||||
ol.event.Events.prototype.triggerEvent = function(type, opt_evt) {
|
||||
var returnValue;
|
||||
if (this.listenerCount_[type] > 0) {
|
||||
var listeners = goog.events.getListeners(this, type, true)
|
||||
.concat(goog.events.getListeners(this, type, false));
|
||||
if (arguments.length === 1) {
|
||||
opt_evt = {'type': type};
|
||||
}
|
||||
opt_evt['object'] = this.object_;
|
||||
for (var i=0, ii=listeners.length; i<ii; ++i) {
|
||||
returnValue = listeners[i].handleEvent(opt_evt);
|
||||
if (returnValue === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepares browser events before they are dispatched. This takes care to set a
|
||||
* property 'xy' on the event with the current pointer position (if
|
||||
* {@code includeXY} is set to true), and normalizes clientX and clientY for
|
||||
* multi-touch events.
|
||||
*
|
||||
* @param {Event} evt Event object.
|
||||
*/
|
||||
ol.event.Events.prototype.handleBrowserEvent = function(evt) {
|
||||
var type = evt.type;
|
||||
if (this.listenerCount_[type] > 0) {
|
||||
// add clientX & clientY to all events - corresponds to average x, y
|
||||
var touches = evt.touches;
|
||||
if (touches && touches[0]) {
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var num = touches.length;
|
||||
var touch;
|
||||
for (var i=0; i<num; ++i) {
|
||||
touch = touches[i];
|
||||
x += touch.clientX;
|
||||
y += touch.clientY;
|
||||
}
|
||||
evt.clientX = x / num;
|
||||
evt.clientY = y / num;
|
||||
}
|
||||
if (this.includeXY_) {
|
||||
evt.xy = this.getPointerPosition(evt);
|
||||
}
|
||||
this.triggerEvent(evt.type, evt);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the mouse position relative to this Event instance's target element for
|
||||
* the provided event.
|
||||
*
|
||||
* @param {Event} evt Event object
|
||||
*/
|
||||
ol.event.Events.prototype.getPointerPosition = function(evt) {
|
||||
return goog.style.getRelativePosition(evt, this.element_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy this Events instance.
|
||||
*/
|
||||
ol.event.Events.prototype.destroy = function() {
|
||||
this.setElement(null);
|
||||
goog.object.clear(this);
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
goog.provide('ol.event.ISequence');
|
||||
|
||||
/**
|
||||
* Interface for event sequences. Event sequences map sequences of native
|
||||
* browser events to high level events that the sequence provides.
|
||||
*
|
||||
* Implementations are expected to call {@code triggerEvent} on the
|
||||
* {@code target} to to fire their high level events.
|
||||
*
|
||||
* Implementations can expect the {@code target}'s {@code getElement} method
|
||||
* to return an {Element} at construction time.
|
||||
*
|
||||
* @interface
|
||||
* @param {ol.event.Events} target The Events instance that receives the
|
||||
* sequence's events.
|
||||
*/
|
||||
ol.event.ISequence = function(target) {};
|
||||
|
||||
/**
|
||||
* Destroys the sequence
|
||||
*/
|
||||
ol.event.ISequence.prototype.destroy = function() {};
|
||||
@@ -1,45 +0,0 @@
|
||||
goog.provide('ol.event.Scroll');
|
||||
|
||||
goog.require('ol.event.ISequence');
|
||||
goog.require('ol.event');
|
||||
|
||||
goog.require('goog.events.MouseWheelHandler');
|
||||
|
||||
|
||||
/**
|
||||
* Event sequence that provides a 'scroll' event. Event objects have 'deltaX'
|
||||
* and 'deltaY' values with the scroll delta since the previous 'scroll' event.
|
||||
*
|
||||
* @constructor
|
||||
* @param {ol.event.Events} target The Events instance that handles events.
|
||||
* @implements {ol.event.ISequence}
|
||||
* @export
|
||||
*/
|
||||
ol.event.Scroll = function(target) {
|
||||
var element = target.getElement(),
|
||||
handler = new goog.events.MouseWheelHandler(element);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.events.MouseWheelHandler}
|
||||
*/
|
||||
this.handler_ = handler;
|
||||
|
||||
handler.addEventListener(
|
||||
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL,
|
||||
function(evt) {
|
||||
evt.type = 'scroll';
|
||||
evt.target = element;
|
||||
target.triggerEvent(evt.type, evt);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.event.Scroll.prototype.destroy = function() {
|
||||
this.handler_.dispose();
|
||||
delete this.handler_;
|
||||
};
|
||||
|
||||
|
||||
ol.event.addSequenceProvider('scroll', ol.event.Scroll);
|
||||
@@ -1,198 +0,0 @@
|
||||
goog.provide('ol.geom.Collection');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Collection objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Collection = function(components) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeBlacklist_ = [
|
||||
ol.geom.Collection
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeWhitelist_ = [
|
||||
ol.geom.MultiPoint,
|
||||
ol.geom.MultiLineString
|
||||
// TODO uncomment when implemented
|
||||
// ,ol.geom.MultiPolygon
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
*/
|
||||
this.components_ = [];
|
||||
|
||||
if (arguments.length === 1 && goog.isDef(components)) {
|
||||
this.setComponents(components);
|
||||
}
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.Collection, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the list of disallowed types for the collection.
|
||||
* @param {Array.<Function>} typeBlacklist Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeBlacklist = function(typeBlacklist){
|
||||
this.typeBlacklist_ = typeBlacklist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of disallowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeBlacklist = function(){
|
||||
return this.typeBlacklist_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the list of always allowed types for the collection.
|
||||
* @param {Array.<Function>} typeWhitelist Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeWhitelist = function(typeWhitelist){
|
||||
this.typeWhitelist_ = typeWhitelist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of always allowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeWhitelist = function(){
|
||||
return this.typeWhitelist_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Collection's components.
|
||||
*
|
||||
* @return {Array.<ol.geom.Geometry>} An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getComponents = function() {
|
||||
return this.components_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the Collection's components.
|
||||
*
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setComponents = function(components) {
|
||||
var allValidTypes = goog.array.every(
|
||||
components,
|
||||
this.isAllowedComponent,
|
||||
this
|
||||
);
|
||||
if (allValidTypes) {
|
||||
this.components_ = components;
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: at least one component passed to '
|
||||
+ 'setComponents is not allowed.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given component to the list of components at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.Collection.prototype.addComponent = function(component, index) {
|
||||
if (this.isAllowedComponent(component)) {
|
||||
goog.array.insertAt(this.components_, component, index);
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: component is not allowed to be added.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the passed component is an instance of any of the constructors
|
||||
* listed in the passed list.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @param {Array.<Function>} list The List of constructors to check the
|
||||
* component against.
|
||||
*
|
||||
* @return {boolean} Whether the passed component is an instance of any of the
|
||||
* constructors listed in the passed list.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Collection.prototype.isOnList = function(component, list) {
|
||||
var isOnList = !goog.array.every(list, function(listedConstr){
|
||||
if (component instanceof listedConstr) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return isOnList;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the passed component is allowed according to the black and
|
||||
* whitelists.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @return {boolean} Whether the passed component is allowed as part of this
|
||||
* collection according to black- and whitelist.
|
||||
*/
|
||||
ol.geom.Collection.prototype.isAllowedComponent = function(component){
|
||||
var whitelist = this.getTypeWhitelist(),
|
||||
blacklist = this.getTypeBlacklist(),
|
||||
isOnWhitelist = this.isOnList(component, whitelist),
|
||||
isOnBlacklist = this.isOnList(component, blacklist);
|
||||
return (isOnWhitelist || !isOnBlacklist);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given component from the list of components.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be removed.
|
||||
*/
|
||||
ol.geom.Collection.prototype.removeComponent = function(component) {
|
||||
goog.array.remove(this.components_, component);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute the centroid for this geometry collection.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the collection.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getCentroid = function() {
|
||||
var components = this.getComponents(),
|
||||
len = components.length,
|
||||
sum_x = 0, sum_y = 0,
|
||||
centroid = null;
|
||||
if (len > 0) {
|
||||
goog.array.forEach(components, function(component){
|
||||
var singleCentroid = component.getCentroid();
|
||||
if (goog.isDefAndNotNull(singleCentroid)) {
|
||||
sum_x += singleCentroid.getX();
|
||||
sum_y += singleCentroid.getX();
|
||||
} else {
|
||||
len--;
|
||||
}
|
||||
});
|
||||
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
|
||||
}
|
||||
return centroid;
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.geom.IGeometry');
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
/**
|
||||
* Creates ol.Geometry objects.
|
||||
*
|
||||
* @export
|
||||
* @implements {ol.geom.IGeometry}
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Geometry = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds|undefined}
|
||||
*/
|
||||
this.bounds_ = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds|undefined} The ol.Bounds.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getBounds = function() {
|
||||
return this.bounds_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Bounds} bounds The new ol.Bounds.
|
||||
* @return {ol.geom.Geometry} This.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.setBounds = function(bounds) {
|
||||
this.bounds_ = bounds;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the centroid of the geometry.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getCentroid = function() {
|
||||
// throw an error to enforce subclasses to implement it properly
|
||||
ol.error('ol.geom.Geometry: getCentroid must be implemented by subclasses');
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the area of the geometry.
|
||||
*
|
||||
* @returns {number} The area of the geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getArea = function() {
|
||||
// throw an error to enforce subclasses to implement it properly
|
||||
ol.error('ol.geom.Geometry: getArea must be implemented by subclasses');
|
||||
return 0;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
goog.provide('ol.geom.IGeometry');
|
||||
|
||||
//goog.require('ol.geom.Point');
|
||||
//goog.require('ol.Bounds');
|
||||
|
||||
/**
|
||||
* Interface for geometry classes forcing ol.geom.* classes to implement
|
||||
* expected functionality.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
ol.geom.IGeometry = function(){};
|
||||
|
||||
/**
|
||||
* @return {ol.geom.Point} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getCentroid = function(){};
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds|undefined} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getBounds = function(){};
|
||||
|
||||
/**
|
||||
* @return {number} The area of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getArea = function(){};
|
||||
@@ -1,76 +0,0 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Collection');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.LineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points building the
|
||||
* linestrings vertices.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.LineString = function(vertices) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
*/
|
||||
this.vertices_ = vertices;
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the LineString's points.
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getVertices = function() {
|
||||
return this.vertices_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the LineString's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setVertices = function(vertices) {
|
||||
this.vertices_ = vertices;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given vertex to the list of vertices at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.LineString.prototype.addVertex = function(vertex, index) {
|
||||
goog.array.insertAt(this.vertices_,vertex,index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given vertex from the list of vertices.
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be removed.
|
||||
*/
|
||||
ol.geom.LineString.prototype.removeVertex = function(vertex) {
|
||||
goog.array.remove(this.vertices_, vertex);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute the centroid for this linestring.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the linestring.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCentroid = function() {
|
||||
var vertices = this.getVertices(),
|
||||
collection = new ol.geom.Collection(vertices);
|
||||
return collection.getCentroid();
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiLineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiLineString = function(linestrings) {
|
||||
this.setTypeWhitelist([ol.geom.LineString]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
if (arguments.length === 1 && goog.isDef(linestrings)) {
|
||||
this.setLineStrings(linestrings);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Gets the MultiLineString's linestrings.
|
||||
*
|
||||
* @return {Array.<ol.geom.LineString>} An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getLineStrings = function() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the MultiLineString's linestrings.
|
||||
*
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setLineStrings = function(linestrings) {
|
||||
this.setComponents(linestrings);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given linestring to the list of linestrings at the specified index.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.addLineString = function(linestring, index) {
|
||||
this.addComponent(linestring, index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given linestring from the list of linestrings.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be removed.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.removeLineString = function(linestring) {
|
||||
this.removeComponent(linestring);
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiPoint objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiPoint = function(points) {
|
||||
this.setTypeWhitelist([ol.geom.Point]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
if (arguments.length === 1 && goog.isDef(points)) {
|
||||
this.setPoints(points);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Sets the MultiPoint's points.
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the MultiPoint's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
this.setComponents(points);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given point to the list of points at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
|
||||
this.addComponent(point, index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given point from the list of points.
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be removed.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.removePoint = function(point) {
|
||||
this.removeComponent(point);
|
||||
};
|
||||
@@ -1,163 +0,0 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.coord.AccessorInterface');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Point objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number=} opt_z Z.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
*
|
||||
* @implements {ol.coord.AccessorInterface}
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Point = function(x, y, opt_z, opt_projection) {
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.x_ = x;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.y_ = y;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.z_ = opt_z;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* @return {number} X.
|
||||
*/
|
||||
ol.geom.Point.prototype.getX = function() {
|
||||
return this.x_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Y.
|
||||
*/
|
||||
ol.geom.Point.prototype.getY = function() {
|
||||
return this.y_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Z.
|
||||
*/
|
||||
ol.geom.Point.prototype.getZ = function() {
|
||||
return this.z_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Projection|undefined} Projection.
|
||||
*/
|
||||
ol.geom.Point.prototype.getProjection = function() {
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.geom.Point.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
*/
|
||||
ol.geom.Point.prototype.setX = function(x) {
|
||||
this.x_ = x;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} y Y.
|
||||
*/
|
||||
ol.geom.Point.prototype.setY = function(y) {
|
||||
this.y_ = y;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} z Z.
|
||||
*/
|
||||
ol.geom.Point.prototype.setZ = function(z) {
|
||||
this.z_ = z;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to another coordinate reference system. This
|
||||
* requires that this point has a projection set already (if not, an error
|
||||
* will be thrown). Returns a new point object and does not modify this
|
||||
* point.
|
||||
*
|
||||
* @param {string|!ol.Projection} proj The destination projection. Can be
|
||||
* supplied as a projection instance of a string identifier.
|
||||
* @returns {!ol.geom.Point} A new location.
|
||||
*/
|
||||
ol.geom.Point.prototype.transform = function(proj) {
|
||||
if (goog.isString(proj)) {
|
||||
proj = new ol.Projection(proj);
|
||||
}
|
||||
return this._transform(proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to a new location given a projection object.
|
||||
*
|
||||
* @param {!ol.Projection} proj The destination projection.
|
||||
* @returns {!ol.geom.Point}
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Point.prototype._transform = function(proj) {
|
||||
var point = {'x': this.x_, 'y': this.y_};
|
||||
var sourceProj = this.projection_;
|
||||
if (!goog.isDefAndNotNull(sourceProj)) {
|
||||
var msg = 'Cannot transform a point without a source projection.';
|
||||
ol.error(msg);
|
||||
}
|
||||
ol.Projection.transform(point, sourceProj, proj);
|
||||
|
||||
return new ol.geom.Point(point['x'], point['y'], this.z_, proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the centroid of the point.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the point.
|
||||
*/
|
||||
ol.geom.Point.prototype.getCentroid = function() {
|
||||
return new ol.geom.Point(this.x_, this.y_, this.z_, this.projection_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the area of the geometry whcih is always 0.
|
||||
*
|
||||
* @returns {number} The area of the point (always 0).
|
||||
*/
|
||||
ol.geom.Point.prototype.getArea = function() {
|
||||
return 0;
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
goog.provide('ol.layer.WMS');
|
||||
|
||||
goog.require('goog.Uri');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
|
||||
/**
|
||||
* Class for WMS layers.
|
||||
*
|
||||
* @export
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {string} url The WMS URL.
|
||||
* @param {Array.<string>} layers List of layers.
|
||||
* @param {string|undefined} format Image format (e.g. "image/jpeg")
|
||||
*/
|
||||
ol.layer.WMS = function(url, layers, format) {
|
||||
goog.base(this);
|
||||
this.setUrl(url);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = layers;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.format_ = format;
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.WMS, ol.layer.TileLayer);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.layer.WMS.prototype.DEFAULT_PARAMS = {
|
||||
"SERVICE": "WMS",
|
||||
"VERSION": "1.1.1",
|
||||
"REQUEST": "GetMap",
|
||||
"STYLES": "",
|
||||
"FORMAT": "image/png"
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.layer.WMS.prototype.getTileUrl = function(x, y, z) {
|
||||
var tileOrigin = this.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1];
|
||||
var resolution = this.getResolutions()[z];
|
||||
var tileWidth = this.tileWidth_ * resolution,
|
||||
tileHeight = this.tileHeight_ * resolution;
|
||||
var minX = tileOriginX + (x * tileWidth),
|
||||
maxY = tileOriginY - (y * tileHeight),
|
||||
maxX = minX + tileWidth,
|
||||
minY = maxY - tileHeight;
|
||||
|
||||
var qd = new goog.Uri.QueryData();
|
||||
qd.extend(this.DEFAULT_PARAMS);
|
||||
qd.set('WIDTH', this.tileWidth_);
|
||||
qd.set('HEIGHT', this.tileHeight_);
|
||||
qd.set('BBOX', [minX, minY, maxX, maxY].join(','));
|
||||
qd.set('LAYERS', [this.layers_].join(','));
|
||||
// FIXME this requires a projection in the layer, which should
|
||||
// not be required
|
||||
qd.set('SRS', this.projection_.getCode());
|
||||
var uri = new goog.Uri(this.getUrl());
|
||||
uri.setQueryData(qd);
|
||||
return uri.toString();
|
||||
};
|
||||
@@ -1,160 +0,0 @@
|
||||
goog.provide('ol.renderer.Composite');
|
||||
|
||||
goog.require('ol.renderer.MapRenderer');
|
||||
goog.require('ol.renderer.LayerRenderer');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.Loc');
|
||||
goog.require('goog.array');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @extends {ol.renderer.MapRenderer}
|
||||
*/
|
||||
ol.renderer.Composite = function(container) {
|
||||
|
||||
goog.base(this, container);
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.renderer.LayerRenderer>}
|
||||
* @private
|
||||
*/
|
||||
this.renderers_ = [];
|
||||
|
||||
var target = document.createElement("div");
|
||||
target.className = "ol-renderer-composite";
|
||||
target.style.position = "absolute";
|
||||
target.style.height = "100%";
|
||||
target.style.width = "100%";
|
||||
container.appendChild(target);
|
||||
|
||||
/**
|
||||
* @type Element
|
||||
* @private
|
||||
*/
|
||||
this.target_ = target;
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.renderer.Composite, ol.renderer.MapRenderer);
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.layer.Layer>} layers
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @param {boolean} animate
|
||||
*/
|
||||
ol.renderer.Composite.prototype.draw = function(layers, center, resolution, animate) {
|
||||
// TODO: deal with layer order and removal
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
this.getOrCreateRenderer(layers[i], i).draw(center, resolution);
|
||||
}
|
||||
this.renderedCenter_ = center;
|
||||
this.renderedResolution_ = resolution;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @param {number} index
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getOrCreateRenderer = function(layer, index) {
|
||||
var renderer = this.getRenderer(layer);
|
||||
if (goog.isNull(renderer)) {
|
||||
renderer = this.createRenderer(layer);
|
||||
goog.array.insertAt(this.renderers_, renderer, index);
|
||||
}
|
||||
return renderer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getRenderer = function(layer) {
|
||||
function finder(candidate) {
|
||||
return candidate.getLayer() === layer;
|
||||
}
|
||||
return goog.array.find(this.renderers_, finder);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
*/
|
||||
ol.renderer.Composite.prototype.createRenderer = function(layer) {
|
||||
var Renderer = this.pickRendererType(layer);
|
||||
goog.asserts.assert(Renderer, "No supported renderer for layer: " + layer);
|
||||
return new Renderer(this.target_, layer);
|
||||
};
|
||||
|
||||
/**
|
||||
* List of preferred renderer types. Layer renderers have a getType method
|
||||
* that returns a string describing their type. This list determines the
|
||||
* preferences for picking a layer renderer.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.renderer.Composite.preferredRenderers = ["svg", "canvas", "vml"];
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @returns {Function}
|
||||
*/
|
||||
ol.renderer.Composite.prototype.pickRendererType = function(layer) {
|
||||
// maps candidate renderer types to candidate renderers
|
||||
var types = {};
|
||||
|
||||
function picker(Candidate) {
|
||||
var supports = Candidate['isSupported']() && Candidate['canRender'](layer);
|
||||
if (supports) {
|
||||
types[Candidate['getType']()] = Candidate;
|
||||
}
|
||||
return supports;
|
||||
}
|
||||
var Candidates = goog.array.filter(ol.renderer.Composite.registry_, picker);
|
||||
|
||||
// check to see if any preferred renderers are available
|
||||
var preferences = ol.renderer.Composite.preferredRenderers;
|
||||
|
||||
var Renderer;
|
||||
for (var i=0, ii=preferences.length; i<ii; ++i) {
|
||||
Renderer = types[preferences[i]];
|
||||
if (Renderer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we didn't find any of the preferred renderers, use the first
|
||||
return Renderer || Candidates[0] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {Array.<Function>}
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.Composite.registry_ = [];
|
||||
|
||||
/**
|
||||
* @param {Function} Renderer
|
||||
*/
|
||||
ol.renderer.Composite.register = function(Renderer) {
|
||||
ol.renderer.Composite.registry_.push(Renderer);
|
||||
};
|
||||
|
||||
/**
|
||||
* return {string}
|
||||
*/
|
||||
ol.renderer.Composite.getType = function() {
|
||||
// TODO: revisit
|
||||
return "composite";
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: determine if there is a better way to register these renderers
|
||||
*
|
||||
* @export
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.renderer.Composite.isSupported = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
ol.renderer.MapRenderer.register(ol.renderer.Composite);
|
||||
@@ -1,71 +0,0 @@
|
||||
goog.provide('ol.renderer.LayerRenderer');
|
||||
|
||||
/**
|
||||
* A single layer renderer that will be created by the composite map renderer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @param {!ol.layer.Layer} layer
|
||||
*/
|
||||
ol.renderer.LayerRenderer = function(container, layer) {
|
||||
|
||||
/**
|
||||
* @type {!Element}
|
||||
* @protected
|
||||
*/
|
||||
this.container_ = container;
|
||||
|
||||
/**
|
||||
* @type {!ol.layer.Layer}
|
||||
* @protected
|
||||
*/
|
||||
this.layer_ = layer;
|
||||
|
||||
var target = goog.dom.createDom('div', {
|
||||
'class': 'ol-renderer-layer',
|
||||
'style': 'position:absolute;height:1px:width:1px'
|
||||
});
|
||||
goog.dom.appendChild(container, target);
|
||||
|
||||
/**
|
||||
* @type Element
|
||||
* @protected
|
||||
*/
|
||||
this.target_ = target;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get layer being rendered.
|
||||
*
|
||||
* @returns {!ol.layer.Layer}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.getLayer = function() {
|
||||
return this.layer_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an identifying string for this renderer.
|
||||
*
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.getType = function() {};
|
||||
|
||||
/**
|
||||
* Determine if this renderer is supported in the given environment.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.isSupported = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer is capable of renderering the given layer.
|
||||
*
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @returns {boolean}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.canRender = function(layer) {
|
||||
return false;
|
||||
};
|
||||
@@ -1,117 +0,0 @@
|
||||
goog.provide('ol.renderer.MapRenderer');
|
||||
|
||||
goog.require('goog.style');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
*/
|
||||
ol.renderer.MapRenderer = function(container) {
|
||||
|
||||
/**
|
||||
* @type !Element
|
||||
* @protected
|
||||
*/
|
||||
this.container_ = container;
|
||||
|
||||
/**
|
||||
* @type {ol.Loc}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedCenter_;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedResolution_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.layer.Layer>} layers
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @param {boolean} animate
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.draw = function(layers, center, resolution, animate) {
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: determine a closure friendly way to register map renderers.
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.MapRenderer.registry_ = [];
|
||||
|
||||
/**
|
||||
* @param {Function} Renderer
|
||||
*/
|
||||
ol.renderer.MapRenderer.register = function(Renderer) {
|
||||
ol.renderer.MapRenderer.registry_.push(Renderer);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} preferences List of preferred renderer types.
|
||||
* @returns {Function} A renderer constructor.
|
||||
*/
|
||||
ol.renderer.MapRenderer.pickRendererType = function(preferences) {
|
||||
// map of candidate renderer types to candidate renderers
|
||||
var types = {};
|
||||
|
||||
function picker(Candidate) {
|
||||
var supports = Candidate.isSupported();
|
||||
if (supports) {
|
||||
types[Candidate.getType()] = Candidate;
|
||||
}
|
||||
return supports;
|
||||
}
|
||||
var Candidates = goog.array.filter(ol.renderer.MapRenderer.registry_, picker);
|
||||
|
||||
// check to see if any preferred renderers are available
|
||||
var Renderer;
|
||||
for (var i=0, ii=preferences.length; i<ii; ++i) {
|
||||
Renderer = types[preferences[i]];
|
||||
if (Renderer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we didn't find any of the preferred renderers, use the first
|
||||
return Renderer || Candidates[0] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
|
||||
* @return {ol.Loc}
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getLocForPixel = function(pixel) {
|
||||
var center = this.renderedCenter_,
|
||||
resolution = this.renderedResolution_,
|
||||
size = goog.style.getSize(this.container_);
|
||||
return center.add(
|
||||
(pixel.x - size.width/2) * resolution,
|
||||
(size.height/2 - pixel.y) * resolution
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} loc
|
||||
* @return {{x: number, y: number}}
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getPixelForLoc = function(loc) {
|
||||
var center = this.renderedCenter_,
|
||||
resolution = this.renderedResolution_,
|
||||
size = this.getSize();
|
||||
return {
|
||||
x: (size.width*resolution/2 + loc.getX() - center.getX())/resolution,
|
||||
y: (size.height*resolution/2 - loc.getY() + center.getY())/resolution
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size} The currently rendered map size in pixels.
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getSize = function() {
|
||||
return goog.style.getSize(this.container_);
|
||||
};
|
||||
@@ -1,338 +0,0 @@
|
||||
goog.provide('ol.renderer.TileLayerRenderer');
|
||||
|
||||
goog.require('ol.renderer.LayerRenderer');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.renderer.Composite');
|
||||
goog.require('ol.TileSet');
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
goog.require('goog.style');
|
||||
|
||||
|
||||
/**
|
||||
* A single layer renderer that will be created by the composite map renderer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @param {!ol.layer.Layer} layer
|
||||
* @extends {ol.renderer.LayerRenderer}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer = function(container, layer) {
|
||||
|
||||
goog.base(this, container, layer);
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.layerResolutions_ = layer.getResolutions();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.tileOrigin_ = layer.getTileOrigin();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.tileSize_ = layer.getTileSize();
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.xRight_ = layer.getXRight() ? 1 : -1;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.yDown_ = layer.getYDown() ? 1 : -1;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedResolution_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedTop_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedRight_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedBottom_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedLeft_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedZ_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {goog.math.Size}
|
||||
* @private
|
||||
*/
|
||||
this.containerSize_ = null;
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
|
||||
|
||||
/**
|
||||
* @param {number} resolution
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getPreferredResAndZ_ = function(resolution) {
|
||||
var minDiff = Number.POSITIVE_INFINITY;
|
||||
var candidate, diff, z, r;
|
||||
for (var i=0, ii=this.layerResolutions_.length; i<ii; ++i) {
|
||||
// assumes sorted resolutions
|
||||
candidate = this.layerResolutions_[i];
|
||||
diff = Math.abs(resolution - candidate);
|
||||
if (diff < minDiff) {
|
||||
z = i;
|
||||
r = candidate;
|
||||
minDiff = diff;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [r, z];
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getContainerSize_ = function() {
|
||||
// TODO: listen for resize and set this.constainerSize_ null
|
||||
// https://github.com/openlayers/ol3/issues/2
|
||||
if (goog.isNull(this.containerSize_)) {
|
||||
this.containerSize_ = goog.style.getSize(this.container_);
|
||||
}
|
||||
return this.containerSize_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tiles rendered at the current resolution;
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.renderedTiles_ = {};
|
||||
|
||||
/**
|
||||
* Render the layer.
|
||||
*
|
||||
* @param {!ol.Loc} center
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.draw = function(center, resolution) {
|
||||
if (resolution !== this.renderedResolution_) {
|
||||
this.changeResolution_(center, resolution);
|
||||
}
|
||||
var pair = this.getPreferredResAndZ_(resolution);
|
||||
var tileResolution = pair[0];
|
||||
var tileZ = pair[1];
|
||||
var scale = resolution / tileResolution;
|
||||
|
||||
var pxMapSize = this.getContainerSize_();
|
||||
var xRight = this.xRight_;
|
||||
var yDown = this.yDown_;
|
||||
|
||||
var halfMapWidth = (resolution * pxMapSize.width) / 2;
|
||||
var halfMapHeight = (resolution * pxMapSize.height) / 2;
|
||||
var centerX = center.getX();
|
||||
var centerY = center.getY();
|
||||
var mapMinX = centerX - halfMapWidth;
|
||||
var mapMaxY = centerY + halfMapHeight;
|
||||
var pxOffsetX = Math.round((mapMinX - this.tileOrigin_[0]) / resolution);
|
||||
var pxOffsetY = Math.round((this.tileOrigin_[1] - mapMaxY) / resolution);
|
||||
|
||||
// this gives us the desired size in fractional pixels
|
||||
var pxTileWidth = this.tileSize_[0] / scale;
|
||||
var pxTileHeight = this.tileSize_[1] / scale;
|
||||
|
||||
// this is the index of the top left tile
|
||||
var leftTileX = Math.floor(xRight * pxOffsetX / pxTileWidth);
|
||||
var topTileY = Math.floor(yDown * pxOffsetY / pxTileHeight);
|
||||
|
||||
var pxMinX;
|
||||
if (xRight > 0) {
|
||||
pxMinX = Math.round(leftTileX * pxTileWidth) - pxOffsetX;
|
||||
} else {
|
||||
pxMinX = Math.round((-leftTileX-1) * pxTileWidth) - pxOffsetX;
|
||||
}
|
||||
var pxMinY;
|
||||
if (yDown > 0) {
|
||||
pxMinY = Math.round(topTileY * pxTileHeight) - pxOffsetY;
|
||||
} else {
|
||||
pxMinY = Math.round((-topTileY-1) * pxTileHeight) - pxOffsetY;
|
||||
}
|
||||
|
||||
var pxTileLeft = pxMinX;
|
||||
var pxTileTop = pxMinY;
|
||||
|
||||
var numTilesWide = Math.ceil(pxMapSize.width / pxTileWidth);
|
||||
var numTilesHigh = Math.ceil(pxMapSize.height / pxTileHeight);
|
||||
|
||||
// assume a buffer of zero for now
|
||||
if (pxMinX < 0) {
|
||||
numTilesWide += 1;
|
||||
}
|
||||
if (pxMinY < 0) {
|
||||
numTilesHigh += 1;
|
||||
}
|
||||
|
||||
var tileX, tileY, tile, img, pxTileRight, pxTileBottom, xyz, append;
|
||||
var fragment = document.createDocumentFragment();
|
||||
var newTiles = false;
|
||||
for (var i=0; i<numTilesWide; ++i) {
|
||||
pxTileTop = pxMinY;
|
||||
tileX = leftTileX + (i * xRight);
|
||||
if (scale !== 1) {
|
||||
pxTileRight = Math.round(pxMinX + ((i+1) * pxTileWidth));
|
||||
} else {
|
||||
pxTileRight = pxTileLeft + pxTileWidth;
|
||||
}
|
||||
for (var j=0; j<numTilesHigh; ++j) {
|
||||
append = false;
|
||||
tileY = topTileY + (j * yDown);
|
||||
xyz = tileX + "," + tileY + "," + tileZ;
|
||||
if (scale !== 1) {
|
||||
pxTileBottom = Math.round(pxMinY + ((j+1) * pxTileHeight));
|
||||
} else {
|
||||
pxTileBottom = pxTileTop + pxTileHeight;
|
||||
}
|
||||
img = null;
|
||||
tile = this.renderedTiles_[xyz];
|
||||
if (!tile) {
|
||||
tile = this.layer_.getTileForXYZ(tileX, tileY, tileZ);
|
||||
if (tile) {
|
||||
if (!tile.isLoaded() && !tile.isLoading()) {
|
||||
tile.load();
|
||||
}
|
||||
this.renderedTiles_[xyz] = tile;
|
||||
img = tile.getImg();
|
||||
goog.dom.appendChild(fragment, img);
|
||||
newTiles = true;
|
||||
}
|
||||
} else {
|
||||
img = tile.getImg();
|
||||
}
|
||||
if (img) {
|
||||
img.style.top = pxTileTop + "px";
|
||||
img.style.left = pxTileLeft + "px";
|
||||
if (scale !== 1) {
|
||||
img.style.height = (pxTileRight - pxTileLeft) + "px";
|
||||
img.style.width = (pxTileBottom - pxTileTop) + "px";
|
||||
}
|
||||
}
|
||||
pxTileTop = pxTileBottom;
|
||||
}
|
||||
pxTileLeft = pxTileRight;
|
||||
}
|
||||
if (newTiles) {
|
||||
this.target_.appendChild(fragment);
|
||||
}
|
||||
this.renderedResolution_ = resolution;
|
||||
this.renderedTop_ = topTileY;
|
||||
this.renderedRight_ = tileX;
|
||||
this.renderedBottom_ = tileY;
|
||||
this.renderedLeft_ = leftTileX;
|
||||
this.renderedZ_ = tileZ;
|
||||
this.removeInvisibleTiles_();
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get rid of tiles outside the rendered extent.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.removeInvisibleTiles_ = function() {
|
||||
var index, prune, x, y, z, tile;
|
||||
var xRight = (this.xRight_ > 0);
|
||||
var yDown = (this.yDown_ > 0);
|
||||
var top = this.renderedTop_;
|
||||
var right = this.renderedRight_;
|
||||
var bottom = this.renderedBottom_;
|
||||
var left = this.renderedLeft_;
|
||||
for (var xyz in this.renderedTiles_) {
|
||||
index = xyz.split(",");
|
||||
x = +index[0];
|
||||
y = +index[1];
|
||||
z = +index[2];
|
||||
prune = this.renderedZ_ !== z ||
|
||||
// beyond on the left side
|
||||
(xRight ? x < left : x > left) ||
|
||||
// beyond on the right side
|
||||
(xRight ? x > right : x < right) ||
|
||||
// above
|
||||
(yDown ? y < top : y > top) ||
|
||||
// below
|
||||
(yDown ? y > bottom : y < bottom);
|
||||
if (prune) {
|
||||
tile = this.renderedTiles_[xyz];
|
||||
delete this.renderedTiles_[xyz];
|
||||
this.target_.removeChild(tile.getImg());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Deal with changes in resolution.
|
||||
* TODO: implement the animation
|
||||
*
|
||||
* @param {ol.Loc} center New center.
|
||||
* @param {number} resolution New resolution.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.changeResolution_ = function(center, resolution) {
|
||||
this.renderedTiles_ = {};
|
||||
goog.dom.removeChildren(this.target_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an identifying string for this renderer.
|
||||
*
|
||||
* @export
|
||||
* @returns {string}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.getType = function() {
|
||||
// TODO: revisit
|
||||
return "tile";
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer type is supported in this environment.
|
||||
*
|
||||
* @export
|
||||
* @return {boolean} This renderer is supported.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.isSupported = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer can render the given layer.
|
||||
*
|
||||
* @export
|
||||
* @param {ol.layer.Layer} layer The candidate layer.
|
||||
* @return {boolean} This renderer is capable of rendering the layer.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.canRender = function(layer) {
|
||||
return layer instanceof ol.layer.TileLayer;
|
||||
};
|
||||
|
||||
ol.renderer.Composite.register(ol.renderer.TileLayerRenderer);
|
||||
Reference in New Issue
Block a user