diff --git a/externs/olx.js b/externs/olx.js
index be9053b422..f6cf740ff8 100644
--- a/externs/olx.js
+++ b/externs/olx.js
@@ -1744,7 +1744,8 @@ olx.format.IGCOptions.prototype.altitudeMode;
/**
* @typedef {{extractStyles: (boolean|undefined),
- * defaultStyle: (Array.
|undefined)}}
+ * defaultStyle: (Array.|undefined),
+ * showPointNames: (boolean|undefined)}}
* @api
*/
olx.format.KMLOptions;
@@ -1758,6 +1759,14 @@ olx.format.KMLOptions;
olx.format.KMLOptions.prototype.extractStyles;
+/**
+ * Show names as labels for placemarks which contain points. Default is `true`.
+ * @type {boolean|undefined}
+ * @api stable
+ */
+olx.format.KMLOptions.prototype.showPointNames;
+
+
/**
* Default style. The default default style is the same as Google Earth.
* @type {Array.|undefined}
diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js
index 1613333fd6..7ae1194b99 100644
--- a/src/ol/format/kmlformat.js
+++ b/src/ol/format/kmlformat.js
@@ -11,7 +11,6 @@ goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('goog.object');
-goog.require('goog.string');
goog.require('ol');
goog.require('ol.Feature');
goog.require('ol.FeatureStyleFunction');
@@ -99,6 +98,13 @@ ol.format.KML = function(opt_options) {
*/
this.sharedStyles_ = {};
+ /**
+ * @private
+ * @type {boolean}
+ */
+ this.showPointNames_ = options.showPointNames !== undefined ?
+ options.showPointNames : true;
+
};
goog.inherits(ol.format.KML, ol.format.XMLFeature);
@@ -312,7 +318,7 @@ ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) {
var textAlign = 'start';
if (foundStyle.getImage()) {
var imageSize = foundStyle.getImage().getImageSize();
- if (!goog.object.isEmpty(imageSize)) {
+ if (imageSize && imageSize.length == 2) {
// Offset the label to be centered to the right of the icon, if there is
// one.
textOffset[0] = foundStyle.getImage().getScale() * imageSize[0] / 2;
@@ -352,32 +358,35 @@ ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) {
* @param {Array.} defaultStyle Default style.
* @param {Object.|string)>} sharedStyles Shared
* styles.
+ * @param {boolean|undefined} showPointNames true to show names for point placemarks.
* @return {ol.FeatureStyleFunction} Feature style function.
* @private
*/
ol.format.KML.createFeatureStyleFunction_ = function(style, styleUrl,
- defaultStyle, sharedStyles) {
+ defaultStyle, sharedStyles, showPointNames) {
+
return (
/**
- * @param {number}
- * resolution Resolution.
+ * @param {number} resolution Resolution.
* @return {Array.} Style.
* @this {ol.Feature}
*/
function(resolution) {
- var drawName = false;
+ var drawName = showPointNames;
/** @type {ol.style.Style|undefined} */
var nameStyle;
/** @type {string} */
var name = '';
- if (this.getGeometry()) {
- drawName = (this.getGeometry().getType() ===
- ol.geom.GeometryType.POINT);
+ if (drawName){
+ if (this.getGeometry()) {
+ drawName = (this.getGeometry().getType() ===
+ ol.geom.GeometryType.POINT);
+ }
}
if (drawName) {
name = /** @type {string} */ (this.getProperties()['name']);
- drawName = drawName && !goog.string.isEmptySafe(name);
+ drawName = drawName && name;
}
if (style) {
@@ -1795,7 +1804,7 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
var style = object['Style'];
var styleUrl = object['styleUrl'];
var styleFunction = ol.format.KML.createFeatureStyleFunction_(
- style, styleUrl, this.defaultStyle_, this.sharedStyles_);
+ style, styleUrl, this.defaultStyle_, this.sharedStyles_, this.showPointNames_);
feature.setStyle(styleFunction);
}
delete object['Style'];