Search code examples
apigoogle-mapsgoogle-earthgoogle-earth-plugin

Styling extruded lines in GE


The issue is I need to change the default color and opacity of extruded line's border. Here is an image from GE API.

So, I need to customize the grey 'wall' under the line. How can it be restyled? Thanks.


Solution

  • So, basically the 'border' of an extruded line is a Polygon object and should be styled respectively.

    Below is the sample from GE API with one additional line and one new method getPolyStyle(), which adds custom styling to the 'wall':

    // Create the placemark
    var lineStringPlacemark = ge.createPlacemark('');
    
    // Create the LineString; set it to extend down to the ground
    // and set the altitude mode
    var lineString = ge.createLineString('');
    lineStringPlacemark.setGeometry(lineString);
    lineString.setExtrude(true);
    lineString.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
    
    // Add LineString points
    lineString.getCoordinates().pushLatLngAlt(48.754, -121.835, 700);
    lineString.getCoordinates().pushLatLngAlt(48.764, -121.828, 700);
    lineString.getCoordinates().pushLatLngAlt(48.776, -121.818, 700);
    lineString.getCoordinates().pushLatLngAlt(48.787, -121.794, 700);
    lineString.getCoordinates().pushLatLngAlt(48.781, -121.778, 700);
    lineString.getCoordinates().pushLatLngAlt(48.771, -121.766, 700);
    lineString.getCoordinates().pushLatLngAlt(48.757, -121.768, 700);
    lineString.getCoordinates().pushLatLngAlt(48.747, -121.773, 700);
    
    // Create a style and set width and color of line
    lineStringPlacemark.setStyleSelector(ge.createStyle(''));
    var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
    
    /*** STYLING THE POLYGON ('WALL') UNDER THE LINE ***/
    lineStringPlacemark.getStyleSelector().getPolyStyle().getColor().set('9900ffff');
    /***************************************************/
    
    lineStyle.setWidth(5);
    lineStyle.getColor().set('9900ffff');  // aabbggrr format
    
    // Add the feature to Earth
    ge.getFeatures().appendChild(lineStringPlacemark);