removed dependencies on goog.clone and fixed placemark rendering
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
goog.provide('ol.format.KML');
|
goog.provide('ol.format.KML');
|
||||||
|
|
||||||
goog.require('goog.object');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
@@ -24,7 +23,6 @@ goog.require('ol.geom.MultiPolygon');
|
|||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.math');
|
goog.require('ol.math');
|
||||||
goog.require('ol.obj');
|
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.style.Fill');
|
goog.require('ol.style.Fill');
|
||||||
goog.require('ol.style.Icon');
|
goog.require('ol.style.Icon');
|
||||||
@@ -301,27 +299,47 @@ 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 (imageSize == null){
|
||||||
|
imageSize = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
||||||
|
}
|
||||||
|
var imageScale = foundStyle.getImage().getScale();
|
||||||
|
if (isNaN(imageScale)){
|
||||||
|
imageScale = ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_;
|
||||||
|
} else {
|
||||||
|
imageScale = ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_ * imageScale;
|
||||||
|
}
|
||||||
if (imageSize && imageSize.length == 2) {
|
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] = imageScale * imageSize[0] / 2;
|
||||||
textOffset[1] = -foundStyle.getImage().getScale() * imageSize[1] / 2;
|
textOffset[1] = -imageScale * imageSize[1] / 2;
|
||||||
textAlign = 'left';
|
textAlign = 'left';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ol.obj.isEmpty(foundStyle.getText())) {
|
if (foundStyle.getText() !== null) {
|
||||||
textStyle = /** @type {ol.style.Text} */
|
// clone the text style, customizing it with name, alignments and offset.
|
||||||
(goog.object.clone(foundStyle.getText()));
|
// Note that kml does not support many text options that OpenLayers does (rotation, textBaseline).
|
||||||
textStyle.setText(name);
|
var foundText = foundStyle.getText();
|
||||||
textStyle.setTextAlign(textAlign);
|
textStyle = new ol.style.Text({
|
||||||
textStyle.setOffsetX(textOffset[0]);
|
text: name,
|
||||||
textStyle.setOffsetY(textOffset[1]);
|
textAlign: textAlign,
|
||||||
|
offsetX: textOffset[0],
|
||||||
|
offsetY: textOffset[1],
|
||||||
|
font: foundText.getFont() || ol.format.KML.DEFAULT_TEXT_STYLE_.getFont(),
|
||||||
|
scale: foundText.getScale() || ol.format.KML.DEFAULT_TEXT_STYLE_.getScale(),
|
||||||
|
fill: foundText.getFill() || ol.format.KML.DEFAULT_TEXT_STYLE_.getFill(),
|
||||||
|
stroke: foundText.getStroke() || ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
textStyle = new ol.style.Text({
|
textStyle = new ol.style.Text({
|
||||||
text: name,
|
text: name,
|
||||||
offsetX: textOffset[0],
|
offsetX: textOffset[0],
|
||||||
offsetY: textOffset[1],
|
offsetY: textOffset[1],
|
||||||
textAlign: textAlign
|
textAlign: textAlign,
|
||||||
|
font: ol.format.KML.DEFAULT_TEXT_STYLE_.getFont(),
|
||||||
|
scale: ol.format.KML.DEFAULT_TEXT_STYLE_.getScale(),
|
||||||
|
fill: ol.format.KML.DEFAULT_TEXT_STYLE_.getFill(),
|
||||||
|
stroke: ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var nameStyle = new ol.style.Style({
|
var nameStyle = new ol.style.Style({
|
||||||
@@ -598,6 +616,8 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
|
|||||||
(IconObject['h']);
|
(IconObject['h']);
|
||||||
if (w !== undefined && h !== undefined) {
|
if (w !== undefined && h !== undefined) {
|
||||||
size = [w, h];
|
size = [w, h];
|
||||||
|
} else {
|
||||||
|
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rotation;
|
var rotation;
|
||||||
@@ -608,7 +628,10 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var scale = /** @type {number|undefined} */
|
var scale = /** @type {number|undefined} */
|
||||||
(object['scale']);
|
(object['scale'] * ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_);
|
||||||
|
if (isNaN(scale)) {
|
||||||
|
scale = ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_;
|
||||||
|
}
|
||||||
if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
|
if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
|
||||||
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
||||||
if (scale === undefined) {
|
if (scale === undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user