Make auto-labeling of placemark names configurable
This commit is contained in:
@@ -1744,7 +1744,8 @@ olx.format.IGCOptions.prototype.altitudeMode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{extractStyles: (boolean|undefined),
|
* @typedef {{extractStyles: (boolean|undefined),
|
||||||
* defaultStyle: (Array.<ol.style.Style>|undefined)}}
|
* defaultStyle: (Array.<ol.style.Style>|undefined),
|
||||||
|
* showPointNames: (boolean|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.format.KMLOptions;
|
olx.format.KMLOptions;
|
||||||
@@ -1758,6 +1759,14 @@ olx.format.KMLOptions;
|
|||||||
olx.format.KMLOptions.prototype.extractStyles;
|
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.
|
* Default style. The default default style is the same as Google Earth.
|
||||||
* @type {Array.<ol.style.Style>|undefined}
|
* @type {Array.<ol.style.Style>|undefined}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ goog.require('goog.array');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.dom.NodeType');
|
goog.require('goog.dom.NodeType');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('goog.string');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.FeatureStyleFunction');
|
goog.require('ol.FeatureStyleFunction');
|
||||||
@@ -99,6 +98,13 @@ ol.format.KML = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.sharedStyles_ = {};
|
this.sharedStyles_ = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.showPointNames_ = options.showPointNames !== undefined ?
|
||||||
|
options.showPointNames : true;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.format.KML, ol.format.XMLFeature);
|
goog.inherits(ol.format.KML, ol.format.XMLFeature);
|
||||||
|
|
||||||
@@ -312,7 +318,7 @@ ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) {
|
|||||||
var textAlign = 'start';
|
var textAlign = 'start';
|
||||||
if (foundStyle.getImage()) {
|
if (foundStyle.getImage()) {
|
||||||
var imageSize = foundStyle.getImage().getImageSize();
|
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
|
// Offset the label to be centered to the right of the icon, if there is
|
||||||
// one.
|
// one.
|
||||||
textOffset[0] = foundStyle.getImage().getScale() * imageSize[0] / 2;
|
textOffset[0] = foundStyle.getImage().getScale() * imageSize[0] / 2;
|
||||||
@@ -352,32 +358,35 @@ ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) {
|
|||||||
* @param {Array.<ol.style.Style>} defaultStyle Default style.
|
* @param {Array.<ol.style.Style>} defaultStyle Default style.
|
||||||
* @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles Shared
|
* @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles Shared
|
||||||
* styles.
|
* styles.
|
||||||
|
* @param {boolean|undefined} showPointNames true to show names for point placemarks.
|
||||||
* @return {ol.FeatureStyleFunction} Feature style function.
|
* @return {ol.FeatureStyleFunction} Feature style function.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.KML.createFeatureStyleFunction_ = function(style, styleUrl,
|
ol.format.KML.createFeatureStyleFunction_ = function(style, styleUrl,
|
||||||
defaultStyle, sharedStyles) {
|
defaultStyle, sharedStyles, showPointNames) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
/**
|
/**
|
||||||
* @param {number}
|
* @param {number} resolution Resolution.
|
||||||
* resolution Resolution.
|
|
||||||
* @return {Array.<ol.style.Style>} Style.
|
* @return {Array.<ol.style.Style>} Style.
|
||||||
* @this {ol.Feature}
|
* @this {ol.Feature}
|
||||||
*/
|
*/
|
||||||
function(resolution) {
|
function(resolution) {
|
||||||
var drawName = false;
|
var drawName = showPointNames;
|
||||||
/** @type {ol.style.Style|undefined} */
|
/** @type {ol.style.Style|undefined} */
|
||||||
var nameStyle;
|
var nameStyle;
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
var name = '';
|
var name = '';
|
||||||
|
if (drawName){
|
||||||
if (this.getGeometry()) {
|
if (this.getGeometry()) {
|
||||||
drawName = (this.getGeometry().getType() ===
|
drawName = (this.getGeometry().getType() ===
|
||||||
ol.geom.GeometryType.POINT);
|
ol.geom.GeometryType.POINT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (drawName) {
|
if (drawName) {
|
||||||
name = /** @type {string} */ (this.getProperties()['name']);
|
name = /** @type {string} */ (this.getProperties()['name']);
|
||||||
drawName = drawName && !goog.string.isEmptySafe(name);
|
drawName = drawName && name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style) {
|
if (style) {
|
||||||
@@ -1795,7 +1804,7 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
|
|||||||
var style = object['Style'];
|
var style = object['Style'];
|
||||||
var styleUrl = object['styleUrl'];
|
var styleUrl = object['styleUrl'];
|
||||||
var styleFunction = ol.format.KML.createFeatureStyleFunction_(
|
var styleFunction = ol.format.KML.createFeatureStyleFunction_(
|
||||||
style, styleUrl, this.defaultStyle_, this.sharedStyles_);
|
style, styleUrl, this.defaultStyle_, this.sharedStyles_, this.showPointNames_);
|
||||||
feature.setStyle(styleFunction);
|
feature.setStyle(styleFunction);
|
||||||
}
|
}
|
||||||
delete object['Style'];
|
delete object['Style'];
|
||||||
|
|||||||
Reference in New Issue
Block a user