Fix Polystyle outline 0 conflict with Linestyle
Return separate style objects for polygon geometries (including multipolygon and polygons in geometry collections) and other geometries if Polystyle outline is defined as 0 Rearrange code to reduce cloning of styles in createNameStyleFunction Update Polystyle outline 0 tests Check for separate style objects applying to LineString and Polygon geometries Test LineString and Polygon geometries in a collection
This commit is contained in:
@@ -882,32 +882,32 @@ class KML extends XMLFeature {
|
||||
* @return {Style} style Style.
|
||||
*/
|
||||
function createNameStyleFunction(foundStyle, name) {
|
||||
let textStyle = null;
|
||||
const textOffset = [0, 0];
|
||||
let textAlign = 'start';
|
||||
if (foundStyle.getImage()) {
|
||||
let imageSize = foundStyle.getImage().getImageSize();
|
||||
const imageStyle = foundStyle.getImage();
|
||||
if (imageStyle) {
|
||||
let imageSize = imageStyle.getImageSize();
|
||||
if (imageSize === null) {
|
||||
imageSize = DEFAULT_IMAGE_STYLE_SIZE;
|
||||
}
|
||||
if (imageSize.length == 2) {
|
||||
const imageScale = foundStyle.getImage().getScale();
|
||||
// Offset the label to be centered to the right of the icon, if there is
|
||||
// one.
|
||||
const imageScale = imageStyle.getScale();
|
||||
// Offset the label to be centered to the right of the icon,
|
||||
// if there is one.
|
||||
textOffset[0] = imageScale * imageSize[0] / 2;
|
||||
textOffset[1] = -imageScale * imageSize[1] / 2;
|
||||
textAlign = 'left';
|
||||
}
|
||||
}
|
||||
if (foundStyle.getText() !== null) {
|
||||
let textStyle = foundStyle.getText();
|
||||
if (textStyle) {
|
||||
// clone the text style, customizing it with name, alignments and offset.
|
||||
// Note that kml does not support many text options that OpenLayers does (rotation, textBaseline).
|
||||
const foundText = foundStyle.getText();
|
||||
textStyle = foundText.clone();
|
||||
textStyle.setFont(foundText.getFont() || DEFAULT_TEXT_STYLE.getFont());
|
||||
textStyle.setScale(foundText.getScale() || DEFAULT_TEXT_STYLE.getScale());
|
||||
textStyle.setFill(foundText.getFill() || DEFAULT_TEXT_STYLE.getFill());
|
||||
textStyle.setStroke(foundText.getStroke() || DEFAULT_TEXT_STROKE_STYLE);
|
||||
textStyle = textStyle.clone();
|
||||
textStyle.setFont(textStyle.getFont() || DEFAULT_TEXT_STYLE.getFont());
|
||||
textStyle.setScale(textStyle.getScale() || DEFAULT_TEXT_STYLE.getScale());
|
||||
textStyle.setFill(textStyle.getFill() || DEFAULT_TEXT_STYLE.getFill());
|
||||
textStyle.setStroke(textStyle.getStroke() || DEFAULT_TEXT_STROKE_STYLE);
|
||||
} else {
|
||||
textStyle = DEFAULT_TEXT_STYLE.clone();
|
||||
}
|
||||
@@ -916,8 +916,10 @@ function createNameStyleFunction(foundStyle, name) {
|
||||
textStyle.setOffsetY(textOffset[1]);
|
||||
textStyle.setTextAlign(textAlign);
|
||||
|
||||
const nameStyle = foundStyle.clone();
|
||||
nameStyle.setText(textStyle);
|
||||
const nameStyle = new Style({
|
||||
image: imageStyle,
|
||||
text: textStyle
|
||||
});
|
||||
return nameStyle;
|
||||
}
|
||||
|
||||
@@ -1766,13 +1768,57 @@ function readStyle(node, objectStack) {
|
||||
const textStyle = /** @type {Text} */
|
||||
('textStyle' in styleObject ?
|
||||
styleObject['textStyle'] : DEFAULT_TEXT_STYLE);
|
||||
let strokeStyle = /** @type {Stroke} */
|
||||
const strokeStyle = /** @type {Stroke} */
|
||||
('strokeStyle' in styleObject ?
|
||||
styleObject['strokeStyle'] : DEFAULT_STROKE_STYLE);
|
||||
const outline = /** @type {boolean|undefined} */
|
||||
(styleObject['outline']);
|
||||
if (outline !== undefined && !outline) {
|
||||
strokeStyle = null;
|
||||
// if the polystyle specifies no outline two styles are needed,
|
||||
// one for non-polygon geometries where linestrings require a stroke
|
||||
// and one for polygons where there should be no stroke
|
||||
return [
|
||||
new Style({
|
||||
geometry: function(feature) {
|
||||
const geometry = feature.getGeometry();
|
||||
const type = geometry.getType();
|
||||
if (type === GeometryType.GEOMETRY_COLLECTION) {
|
||||
return new GeometryCollection(
|
||||
geometry.getGeometriesArray().filter(function(geometry) {
|
||||
const type = geometry.getType();
|
||||
return type !== GeometryType.POLYGON && type !== GeometryType.MULTI_POLYGON;
|
||||
})
|
||||
);
|
||||
} else if (type !== GeometryType.POLYGON && type !== GeometryType.MULTI_POLYGON) {
|
||||
return geometry;
|
||||
}
|
||||
},
|
||||
fill: fillStyle,
|
||||
image: imageStyle,
|
||||
stroke: strokeStyle,
|
||||
text: textStyle,
|
||||
zIndex: undefined // FIXME
|
||||
}),
|
||||
new Style({
|
||||
geometry: function(feature) {
|
||||
const geometry = feature.getGeometry();
|
||||
const type = geometry.getType();
|
||||
if (type === GeometryType.GEOMETRY_COLLECTION) {
|
||||
return new GeometryCollection(
|
||||
geometry.getGeometriesArray().filter(function(geometry) {
|
||||
const type = geometry.getType();
|
||||
return type === GeometryType.POLYGON || type === GeometryType.MULTI_POLYGON;
|
||||
})
|
||||
);
|
||||
} else if (type === GeometryType.POLYGON || type === GeometryType.MULTI_POLYGON) {
|
||||
return geometry;
|
||||
}
|
||||
},
|
||||
fill: fillStyle,
|
||||
stroke: null,
|
||||
zIndex: undefined // FIXME
|
||||
})
|
||||
];
|
||||
}
|
||||
return [new Style({
|
||||
fill: fillStyle,
|
||||
|
||||
Reference in New Issue
Block a user