How update KMLStyle?

99 views
Skip to first unread message

Nejia Ben Nasr

unread,
Feb 27, 2014, 9:46:30 AM2/27/14
to kml-support-g...@googlegroups.com
Hi,
I load feature using KML :

kml= '<?xml version="1.0" encoding="utf-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="Style1"> <LineStyle> <color>#ffff55ff</color> <width>3</width> </LineStyle> <PolyStyle> <color>#ffffaaaa</color> <fill>1</fill> <outline>1</outline> </PolyStyle></Style><Placemark id="0"> <styleUrl>#Style1</styleUrl> <Polygon> <extrude>0</extrude> <tessellate>0</tessellate> <altitudeMode>clampToGround</altitudeMode> <outerBoundaryIs> <LinearRing><coordinates> 10.17412778,36.84672090 10.17424823,36.84674061 10.17427628,36.84663085 10.17415582,36.84661114 10.17412778,36.84672090</coordinates></LinearRing> </outerBoundaryIs> </Polygon> </Placemark> </Document></kml>'

var oKmlObject = ge.parseKml( Kml ) ;
if( oKmlObject ) {
ge.getFeatures().appendChild( this.oKmlObject ) ;
}

I want to repalce the KMLStyle by this :

kml= '<Style id="Style1"> <LineStyle> <color>#ff00ffff</color> <width>1</width> </LineStyle> <PolyStyle> <color>#ffffaaaa</color> <fill>0</fill> <outline>1</outline> </PolyStyle></Style>'

the code below does not work :(
var oOldStyle = this.oKmlObject.getElementById( sID ) ;
var oNewStyle = ge.parseKml( Kml ) ;
ge.getFeatures().replaceChild( oNewStyle, oOldStyle );

please any one can help me!

Jason M

unread,
Feb 27, 2014, 11:42:39 AM2/27/14
to kml-support-g...@googlegroups.com
Hi.

One problem is your using '#' prefix to the color values in your style as typically used for HTML pages.
Color in KML does not have the '#' prefix. Remove the '#'.

      <Style id="Style1">
            <LineStyle>
                <color>ff00ffff</color>
                <width>1</width>
            </LineStyle>
            ...
        </Style>

Nejia

unread,
Feb 28, 2014, 2:26:40 AM2/28/14
to kml-support-g...@googlegroups.com
Hi Jason,

I modify color (without # prefix), but this doesn't resolve my problem.

the line below it generate an exception (Error: Error calling method on NPObject!)
ge.getFeatures().replaceChild( oNewStyle, oOldStyle );

Jason M

unread,
Feb 28, 2014, 11:21:45 AM2/28/14
to kml-support-g...@googlegroups.com
kml= '<Style id="Style1"> <LineStyle> <color>#ff00ffff</color> <width>1</width> </LineStyle> <PolyStyle> <color>#ffffaaaa</color> <fill>0</fill> <outline>1</outline> </PolyStyle></Style>'
var oNewStyle = ge.parseKml( Kml ) ....

oNewStyle is probably not a Style object since a KML style must be contained within a Document container.

Instead of trying to parse a Style from KML string suggest you just create Style object directly using API:

var oNewStyle = ge.createStyle('');
var lineStyle = oNewStyle.getLineStyle();
lineStyle.setWidth(1);
lineStyle.getColor().set('ff00ffff');
var polyStyle = oNewStyle.getPolyStyle();
polyStyle.getColor().set('ffffaaaa');
etc.

Nejia

unread,
Mar 3, 2014, 3:44:25 AM3/3/14
to kml-support-g...@googlegroups.com
Thank you Jason :), your last post solve my problem.
Reply all
Reply to author
Forward
0 new messages