FME Version
Files
Introduction
By default a KML balloon will contain links "Directions to Here" and "Directions from Here" (driving directions). This demo shows how to remove these links from the balloon, as well as use HTML to set KML Balloon content, in this case, URL links and images, such as pngs, jpegs, and tiffs.
Requirements
Google Earth (for viewing output)
Source Data
KML after being reprojected to demonstrate the "Directions" links viewed in Google Earth
Step-by-step Instructions
1. Read in FireHalls.gml
Open FME Workbench and start a blank workspace. Add an OGC GML reader and select the FireHalls.gml dataset.
2. Reproject to LL84
Next, add a CsmapReprojector transformer to the canvas and connect it to the FireHalls reader feature type. In the parameters, set the Destination Coordinate System to LL84. The coordinate system needs to be changed because KML only supports a latitude/longitude coordinate system.
3. Remove “Directions” from KML Balloons
To remove the direction links from the balloons, a KML attribute needs to be created. To do that, add an AttributeCreator to the canvas and connect it to the CsmapReprojector. In the parameters, create a New Attribute called kml_balloonstyle_text. This is a KML specific style element, for more information on KML elements see the documentation.
For the Attribute Value, set the value to $[description], which tells Google Earth to only use the description for the feature balloon rather than the default which contains the links for "Directions to Here" and "Directions from Here".
4. Write to OGC/Google KML
To test that the directions were removed successfully, we need to write out to Google KML and then view the KML file in Google Earth. Add an OGC/Google KML Writer to the canvas, and then name the Dataset FireHallsOutput.kml, ensure this file is saved in the same folder as the jpeg images.
5. Run the translation
Connect the FireHalls writer feature type to the AttributeCreator. Run the translation and then open up the folder containing the new FireHalls.kml file. Open the file in Google Earth to view the results.
KML viewed in Google Earth with the "Directions" links removed
6. Set Description Balloon HTML Content
Now that we know that the directions have been removed, we can make the description balloon a bit more useful by adding images.
Add a KMLPropertySetter to the canvas and connect it between the AttributeCreator and the FireHalls writer feature type. The KMLPropertySetter will set the HTML content for the balloon by specifying a link to the Firehall location in Google Maps as well as a photo of the Firehall if it is available. In the KMLPropertySetter parameters set the Name to the attribute Name, and the Summary to the attribute Address, this information is already contained within the FireHalls.gml dataset.
Next set the Content Type to HTML and then for the Content, copy and paste the following html code:
<h4>@Value(Name)</h4> This facility is located at <a href="http://maps.google.com/maps?q=@YValue(),@XValue()">@Value(Address), Vancouver, BC</a> <img src="@Value(HallNumber).jpg">
This HTML uses the X and Y values as well as the address and then embeds them into a Google Maps URL. It will also use the images that are saved in the same folder as the workspace that corresponds the Hall Number with the appropriate image. Finally set the Include Attribute Table to No, then click OK.
Note that the image name can be given without a path, only because the output is being written to the same folder in which the image files exist. Otherwise, this would need to be given the full path. Specifying the name or full path only works with local drives. If you are using a network drive, you will need to specify the images under the Additional Files section. Please see the documentation for further information on using additional files in FME.
7. Rerun the Workspace
Rerun the workspace and view the updated KML in Google Earth to view the new balloon description with images.
KML viewed in Google Earth with the "Directions" links removed and data updated in the content ballon.
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
Comments
1 comment
Anyone trying to customize their KMZ’s needs to read this immediately! It solved all my problems (other than having to revive my HTML skills).
Please sign in to leave a comment.