Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to display a label from KML if the label also has a custom style on an icon... #6436

Closed
lowzonenose opened this issue Feb 1, 2017 · 1 comment

Comments

@lowzonenose
Copy link

lowzonenose commented Feb 1, 2017

When you write a kml with a label that has 2 styles,
one for the text, and the other for the custom icon,
the 'name' tag is not written to the output kml.
So, when you want to import it to a map, the label
can not be displayed...

You can see the problem :
https://jsfiddle.net/lowzonenose/c9qqbkLz/

We can resolve it if we modify the code into the class ol.format.KML :

ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
  (...)
  var styleFunction = feature.getStyleFunction();
  if (styleFunction) {
    // FIXME the styles returned by the style function are supposed to be
    // resolution-independent here
    var styles = styleFunction.call(feature, 0);
    if (styles) {
      var style = Array.isArray(styles) ? styles[0] : styles;
      if (this.writeStyles_) {
        properties['Style'] = style;
      }
      // Unnecessary if this property is already filled !
      // So it's not necessary to overwrite it...
      if (!properties.hasOwnProperty("name")) {  // --> the fix is here !  <--
        var textStyle = style.getText();
        if (textStyle) {
          properties['name'] = textStyle.getText();
        }
      }
    }
  }
 (...)
}
@lowzonenose
Copy link
Author

This little patch does not solve everything,
the ideal would be to have a function to merge styles...
If there are several styles, they are merged to return only one style...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant