Stay organized with collections
Save and categorize content based on your preferences.
Josh Livni, Google Geo APIs Team
December, 2010
Objective
This tutorial introduces you to a few new KML elements introduced with Google Earth 6.0, and how they can be used to create complex cartography for your LineStyles. The elements you will learn about are <gx:physicalWidth>, <gx:outerColor>, <gx:outerWidth>, and <gx:drawOrder>.
Introduction
Prior to the release of Google Earth 6.0, you were limited in their ability to define complex cartographic styles for LineStrings. For example, if you wanted to create a style for a road, where the center of the LineString had a different color than the edges, you would have to draw two separate LineStrings with different widths, and even then you could not guarantee the order they would draw in.
The following examples walk through creating a road. First, the road will have a simple style. Then you will add a sidewalk. Finally, you'll add a highway overpass.
A Basic Road
The first element of interest is <gx:physicalWidth>, which allows you to set the width of a LineString to be in meters, rather than pixels. In the case of our road example, this means you can set the width of our road to match the underlying imagery no matter what altitude the end user views the road from. As you gain altitude, the road diminishes in pixels, creating an effect where you can only see the LineString when zoomed in closely. This may be useful if you don't want to emphasize small roads from a distance, or you want to ensure your cartography matches the satellite imagery at all times.
As you change the camera altitude in Google Earth, note how it closely matches the width of the underlying imagery at all times.
Adding Sidewalks
Now you can add in the <gx:outerColor> and <gx:outerWidth> elements by adding a light green to the edges of our road to signify sidewalks. Set 25% of the total pixels of the road to be light grey.
Because the width of the road was set to be 12 meters, the value of .25 for the outerWidth means 3 meters of that width will be set to a lighter green (about 1.5 meters on each side of the road).
A Highway Overpass
Now that you have a basic road, it's time to tackle a highway overpass. This one will be colored a light orange with a darker orange median line. The key addition here is to include a <gx:drawOrder> of 1 (the default is 0) in the <LineSring> to ensure the highway will be rendered on top of the road. If you were building a more complex highway interchange (or any cartography that required more than two overlapping LineStrings) you can simply add a higher value to the <gx:drawOrder> for whichever one you want rendered on the top.
The ability to describe a single LineString with multiple colors, combined with control over the rendering order allows you to create complex line cartography that was not previously possible. Whether you're building a highway overpass or a an abstract art project, have fun with these styling rules!
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-11-03 UTC."],[[["\u003cp\u003eThis tutorial explains how to use new KML elements like \u003ccode\u003e<gx:physicalWidth>\u003c/code\u003e, \u003ccode\u003e<gx:outerColor>\u003c/code\u003e, \u003ccode\u003e<gx:outerWidth>\u003c/code\u003e, and \u003ccode\u003e<gx:drawOrder>\u003c/code\u003e in Google Earth 6.0.\u003c/p\u003e\n"],["\u003cp\u003eThese elements enable creating complex cartographic styles for LineStrings, like roads with sidewalks or highway overpasses with multiple colors and layers.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003e<gx:physicalWidth>\u003c/code\u003e sets the LineString width in meters for consistent visualization at different altitudes, while \u003ccode\u003e<gx:outerColor>\u003c/code\u003e and \u003ccode\u003e<gx:outerWidth>\u003c/code\u003e add outer styling like sidewalks.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003e<gx:drawOrder>\u003c/code\u003e controls the rendering order of overlapping LineStrings, ensuring elements like highway overpasses appear on top of other roads.\u003c/p\u003e\n"],["\u003cp\u003eBy combining these elements, users can create detailed and realistic cartographic representations previously not possible in Google Earth.\u003c/p\u003e\n"]]],[],null,["# Complex Styling for LineStrings with DrawOrder\n\n*Josh Livni, Google Geo APIs Team\nDecember, 2010*\n\nObjective\n=========\n\n\nThis tutorial introduces you to a few new KML elements introduced with Google Earth 6.0, and how they can be used to create complex cartography for your LineStyles. The elements you will learn about are `\u003cgx:physicalWidth\u003e`, `\u003cgx:outerColor\u003e`, `\u003cgx:outerWidth\u003e`, and `\u003cgx:drawOrder\u003e`.\n\nIntroduction\n============\n\n\nPrior to the release of Google Earth 6.0, you were limited in their ability to define complex cartographic styles for LineStrings. For example, if you wanted to create a style for a road, where the center of the LineString had a different color than the edges, you would have to draw two separate LineStrings with different widths, and even then you could not guarantee the order they would draw in.\n\n\nThe following examples walk through creating a road. First, the road will have a simple style. Then you will add a sidewalk. Finally, you'll add a highway overpass.\n\nA Basic Road\n============\n\n\nThe first element of interest is `\u003cgx:physicalWidth\u003e`, which allows you to set the width of a LineString to be in meters, rather than pixels. In the case of our road example, this means you can set the width of our road to match the underlying imagery no matter what altitude the end user views the road from. As you gain altitude, the road diminishes in pixels, creating an effect where you can only see the LineString when zoomed in closely. This may be useful if you don't want to emphasize small roads from a distance, or you want to ensure your cartography matches the satellite imagery at all times. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\"\u003e\n\u003cDocument\u003e\n \u003cname\u003eRoad Styling\u003c/name\u003e\n \u003cStyle id=\"street\"\u003e\n \u003cLineStyle\u003e\n \u003ccolor\u003eff235523\u003c/color\u003e\n \u003cgx:physicalWidth\u003e12\u003c/gx:physicalWidth\u003e\n \u003c/LineStyle\u003e\n \u003c/Style\u003e\n \u003cPlacemark\u003e\n \u003cstyleUrl\u003e#street\u003c/styleUrl\u003e\n \u003cLineString\u003e\n \u003ccoordinates\u003e\n -122.2442883478408,37.4347536724074,0\n -122.2417741446485,37.43594997501623,0\n -122.2414951359056,37.43611878445952,0\n \u003c/coordinates\u003e\n \u003c/LineString\u003e\n \u003c/Placemark\u003e\n\u003c/Document\u003e\n\u003c/kml\u003e\n```\n\n\u003cbr /\u003e\n\nAs you change the camera altitude in Google Earth, note how it closely matches the width of the underlying imagery at all times.\n\n\nAdding Sidewalks\n================\n\n\nNow you can add in the `\u003cgx:outerColor\u003e` and `\u003cgx:outerWidth\u003e` elements by adding a light green to the edges of our road to signify sidewalks. Set 25% of the total pixels of the road to be light grey. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\"\u003e\n\u003cDocument\u003e\n \u003cname\u003eRoad Styling\u003c/name\u003e\n \u003cStyle id=\"street_sidewalk\"\u003e\n \u003cLineStyle\u003e\n \u003ccolor\u003eff235523\u003c/color\u003e\n \u003cgx:physicalWidth\u003e12\u003c/gx:physicalWidth\u003e\n \u003cgx:outerColor\u003eff55ff55\u003c/gx:outerColor\u003e\n \u003cgx:outerWidth\u003e0.25\u003c/gx:outerWidth\u003e\n \u003c/LineStyle\u003e\n \u003c/Style\u003e\n \u003cPlacemark\u003e\n \u003cstyleUrl\u003e#street_sidewalk\u003c/styleUrl\u003e\n \u003cLineString\u003e\n \u003ccoordinates\u003e\n -122.2442883478408,37.4347536724074,0\n -122.2417741446485,37.43594997501623,0\n -122.2414951359056,37.43611878445952,0\n \u003c/coordinates\u003e\n \u003c/LineString\u003e\n \u003c/Placemark\u003e\n\u003c/Document\u003e\n\u003c/kml\u003e\n```\n\n\u003cbr /\u003e\n\nBecause the width of the road was set to be 12 meters, the value of .25 for the outerWidth means 3 meters of that width will be set to a lighter green (about 1.5 meters on each side of the road).\n\n\nA Highway Overpass\n==================\n\n\nNow that you have a basic road, it's time to tackle a highway overpass. This one will be colored a light orange with a darker orange median line. The key addition here is to include a `\u003cgx:drawOrder\u003e` of 1 (the default is 0) in the `\u003cLineSring\u003e` to ensure the highway will be rendered on top of the road. If you were building a more complex highway interchange (or any cartography that required more than two overlapping LineStrings) you can simply add a higher value to the `\u003cgx:drawOrder\u003e` for whichever one you want rendered on the top. \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\"\u003e\n\u003cDocument\u003e\n \u003cname\u003eRoad Styling\u003c/name\u003e\n \u003cStyle id=\"street_sidewalk\"\u003e\n \u003cLineStyle\u003e\n \u003ccolor\u003eff235523\u003c/color\u003e\n \u003cgx:physicalWidth\u003e10\u003c/gx:physicalWidth\u003e\n \u003cgx:outerColor\u003eff55ff55\u003c/gx:outerColor\u003e\n \u003cgx:outerWidth\u003e0.25\u003c/gx:outerWidth\u003e\n \u003c/LineStyle\u003e\n \u003c/Style\u003e\n \u003cStyle id=\"highway\"\u003e\n \u003cLineStyle\u003e\n \u003ccolor\u003ecc1447ff\u003c/color\u003e\n \u003cgx:physicalWidth\u003e20\u003c/gx:physicalWidth\u003e\n \u003cgx:outerColor\u003ecc1473ff\u003c/gx:outerColor\u003e\n \u003cgx:outerWidth\u003e0.75\u003c/gx:outerWidth\u003e\n \u003c/LineStyle\u003e\n \u003c/Style\u003e\n \u003cPlacemark\u003e\n \u003cstyleUrl\u003e#street_sidewalk\u003c/styleUrl\u003e\n \u003cLineString\u003e\n \u003ccoordinates\u003e\n -122.2442883478408,37.4347536724074,0\n -122.2417741446485,37.43594997501623,0\n -122.2414951359056,37.43611878445952,0\n \u003c/coordinates\u003e\n \u003c/LineString\u003e\n \u003c/Placemark\u003e\n \u003cPlacemark\u003e\n \u003cstyleUrl\u003e#highway\u003c/styleUrl\u003e\n \u003cLineString\u003e\n \u003cgx:drawOrder\u003e1\u003c/gx:drawOrder\u003e\n \u003ccoordinates\u003e\n -122.2442692500139,37.43634904345254,0\n -122.2415928723012,37.43416417520744,0\n \u003c/coordinates\u003e\n \u003c/LineString\u003e\n \u003c/Placemark\u003e\n\u003c/Document\u003e\n\u003c/kml\u003e\n```\n\nWhat's next?\n============\n\n\nThe ability to describe a single LineString with multiple colors, combined with control over the rendering order allows you to create complex line cartography that was not previously possible. Whether you're building a highway overpass or a an abstract art project, have fun with these styling rules!"]]