[OpenLayers-Users] KML icons [workaround / monkeypatch included]

Egil Möller egil at skytruth.org
Tue Feb 12 06:59:29 PST 2013


It seems to be a pure bug. Here is workaround code:

      MapServer.Format.KML = OpenLayers.Class(OpenLayers.Format.KML, {
        CLASS_NAME: "MapServer.Format.KML",
        parseStyle: function(node) {
          var baseURI = node.baseURI.split("?")[0]; // remove query, if any
          if (baseURI.lastIndexOf("/") != baseURI.length - 1) {
            baseURI = baseURI.substr(0, baseURI.lastIndexOf("/") + 1);
          }
          var style = 
OpenLayers.Format.KML.prototype.parseStyle.call(this, node);
          if (typeof style.externalGraphic != "undefined" &&
style.externalGraphic.match(new RegExp("(^/)|(://)")) == null) {
            style.externalGraphic = baseURI + style.externalGraphic;
          }
          return style;
        }
      });

Best reards,
Egil


On 02/12/2013 11:30 PM, Egil Möller wrote:
> Hi!
>
> I'm trying to load KML into a vector layer. The KML contains styles with
> relative paths to icons:
>
>             <IconStyle>
>                 <color>ff0099ff</color>
>                 <scale>0.5</scale>
>                 <heading>496.77</heading>
>                 <Icon>
>                     <href>files/vd.png</href>
>                 </Icon>
>             </IconStyle>
>
> This results in a 404 on http://myserver.com/files/vd.png (the kml file
> is not located in the root of my server...). I've tried to solve this
> using new
>
>                 OpenLayers.Format.KML({
>                   styleBaseUrl: "http://myserver.com/static/kml-files",
>                   extractStyles: true,
>                   extractAttributes: true,
>                   maxDepth: 2
>                 })
>
> That makes any errors go away, but no icon markers show up, and when I
> check the network tab in the chrome debugger I don't see vd.png loaded
> at all.
>
> I actually don't get any errors regardless of what I set styleBaseUrl
> to, as long as it is set.
>
> Any ideas,
> Egil

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130213/d397b4aa/attachment.html>


More information about the Users mailing list