How to draw custome text inside polygon in KML? - kml

I want to draw custome text inside polygon using KML file.
My Kml file for Polygon-
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="White"><PolyStyle><color>64FFFFFF</color></PolyStyle></Style><Placemark><styleUrl>#white</styleUrl><Polygon><outerBoundaryIs><LinearRing><coordinates>-95.27999999999997,30.0175 -95.27166999999997,30.0175 -95.27166999999997,30.01083 -95.27999999999997,30.01083 -95.27999999999997,30.0175</coordinates></LinearRing></outerBoundaryIs></Polygon><ExtendedData><Data name="isColorful">true</Data><Data name="color">white</Data></ExtendedData></Placemark></Document></kml>
am i missing any tag or property to show text in the center of polygon.
Please help.
Actually , I want to show some data inside polygon, I created KML using with Point and polygon.
-I made icon scale 0 to hide icon .
it shows name label inside polygon in "Google Earth", but it does not show label in "Google map".
Please see my sample KML file
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="White"><IconStyle> <color>ff00ff00</color> <colorMode>random</colorMode><scale>0</scale></IconStyle><LabelStyle><scale>0.6</scale></LabelStyle><PolyStyle><color>64FFFFFF</color></PolyStyle></Style><Placemark><name>64,100</name><styleUrl>#White</styleUrl><MultiGeometry><Point><coordinates>-95.27899999999997,30.0172</coordinates></Point><Polygon><outerBoundaryIs><LinearRing><coordinates>-95.27999999999997,30.0175 -95.27166999999997,30.0175 -95.27166999999997,30.01083 -95.27999999999997,30.01083 -95.27999999999997,30.0175</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry></Placemark><Placemark><name>65,93</name><styleUrl>#White</styleUrl><MultiGeometry><Point><coordinates>-95.27066999999997,29.97053</coordinates></Point><Polygon><outerBoundaryIs><LinearRing><coordinates>-95.27166999999997,29.97083 -95.26333999999997,29.97083 -95.26333999999997,29.96417 -95.27166999999997,29.96417 -95.27166999999997,29.97083</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry></Placemark></Document></kml>

Some of the elements in the KML are out of order making it invalid KML with respect to the KML 2.2 specification. The KML should first be validated. Some tips to validate KML are discussed here.
The ExtendedData element is incorrect. Missing required value element.
<ExtendedData>
<Data name="isColorful">true</Data>
<Data name="color">white</Data>
</ExtendedData>
This need to be restructued:
<ExtendedData>
<Data name="isColorful">
<value>true</value>
</Data>
<Data name="color">
<value>white</value>
</Data>
</ExtendedData>
If KML placemark has ExtendedData then these data fields are formatted in a human readable HTML table in the description balloon popup when clicked.
If you want to override the HTML table then add a <description> to your KML placemark which can contain HTML markup. See description section in KML reference docs.
UPDATE:
If want text to appear on the polygon then need to include Point and Polygon in MultiGeometry as you describe but also need a <name> element added to the Placemark. The text of the name element will be the label that is displayed at the position of the point. This works in Google Earth but not in Google Maps. KML has some limitations in Google Maps. If want to add text to center of your polygon, then add a label marker via Google Maps API.
https://developers.google.com/maps/documentation/javascript/examples/marker-labels

Related

Create kml file to display al bitmap vertically in Google Earth

I have seen examples where it is possible to display a bitmap as a vertical profile in Google Earth. Like this:
However, I have not been able to find any kml/kmz examples of this. Does anyone have a simple example of how to do this?
Does it include using the dae (collada) file format too?
One method to do this would be to use a KML "Photo Overlay". They are designed to place landscape photographs vertically in the world, so that they can be viewed with the Earth terrain & imagery as matching background. You could use that technique to place images like these on vertical planes. There is a basic tool in Earth Pro to create Photo Overlays (Add menu >> Photo). Or you can create them manually or programmatically by writing the appropriate KML (reference links below), though it can get pretty complex with all the placement and field of view parameters. Also note that Photo Overlays work in Earth Pro (Earth v7.x), but do not currently work in Earth for web & mobile (Earth v9.x).
You could also do this using 3D models (yes, collada based) where you have a model representing your vertical plane(s), and the images as textures on the models. 3D models also only work in Earth Pro at this time. Which technique is easier will depend on the tools and skills you have available.
https://developers.google.com/kml/documentation/photos
https://developers.google.com/kml/documentation/kmlreference#photooverlay
My PhotoOverlay example is just here.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="7">
<visibility>0</visibility>
<PhotoOverlay id="8">
<name>PhotoOverlay Test</name>
<visibility>0</visibility>
<Camera>
<longitude>-122.3599987260313</longitude>
<latitude>47.62949781133496</latitude>
<altitude>100</altitude>
<heading>-90</heading>
<tilt>90</tilt>
<roll>0</roll>
</Camera>
<Icon id="10">
<href>foo.png</href>
</Icon>
<ViewVolume>
<leftFov>-45</leftFov>
<rightFov>45</rightFov>
<bottomFov>-45</bottomFov>
<topFov>45</topFov>
<near>20000</near>
</ViewVolume>
</PhotoOverlay>
</Document>
</kml>
My kml example using collada is here.
You have to prepare your_prepared_square.dae and your_prepared.png in same folder. The square size is 1m x 1m. This model is scaling base.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="1">
<Placemark id="2">
<name>My billboard</name>
<Model id="3">
<altitudeMode>absolute</altitudeMode>
<Location>
<longitude>140.037</longitude>
<latitude>36.84895</latitude>
<altitude>500</altitude>
</Location>
<Orientation>
<heading>90</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>10000</y>
<z>3500</z>
</Scale>
<Link id="4">
<href>your_prepared_square.dae</href>
</Link>
<ResourceMap>
<Alias>
<targetHref>your_prepared.png</targetHref>
<sourceHref>mapping.png</sourceHref>
</Alias>
</ResourceMap>
</Model>
</Placemark>
</Document>
</kml>
And mapping.png is texture filename in the collada model. This has
to be defined in the model. following fragment is a part of your_prepared_square.dae. But you don't need to prepare mapping.png. KML replaces it to your_prepared.png.
:
:
<library_images>
<image id="texture" name="texture">
<init_from>mapping.png</init_from>
</image>
</library_images>
:
:
folllowing image is applied this method.

Don't want to show LINK used on IFRAME KML

I know that is possible to display a URL link inside a kml using IFRAME.
But I need that my link used on IFRAME does not display if I do right-click -> Properties in the placemark or in the right list of placemarks.
There's a way to do so?
Thx a lot,
Cya!
Yes you can
You need to look into using ExtendedData
It requires you to hand edit the KML file with a text editor.
Step 1 - Within the <Placemark> you wish to embed to iframe
<ExtendedData>
<Data name="iframe">
<value><![CDATA[<iframe width="350" height="197" src="http://www.google.com"></iframe>]]></value>
</Data>
</ExtendedData>
Step 2 - Within the associated <Style> assigned to the Placemark
<BalloonStyle>
<text>$[description]$[iframe]</text>
</BalloonStyle>
That will work so long as you place everything in the correct place
HOWEVER anyone who really wants to see the source of your iframe - all they have to do is open the KML in a text editor..... so it is kind of a useless process......

control of label visibility on placemarks

I have a kml file with many simple point placemarks each with a name that cover the USA. I am trying to find a way to control their label display so that the view is not cluttered at higher altitudes. I've seen mention the use of Regions but it appears this would have to be applied on each placemark. I know something must be available for this since GE is doing this very thing on the default layers, i.e. Populated Places. Further, there seems to be some default at work when I zoom far enough out the labels disappear without any input on my kml.
Any comments are appreciated!!
To control the display of labels in your KML you can either use Regions as you mentioned and/or a StyleMap with a normal and highlighted LabelStyle.
If you capture the HTTP traffic to Google Earth you'll notice the Borders and Labels default layer (among others) are implemented as KML files using Regions and nested NetworkLinks.
Regions
If you don't want to create a Region on every placemark then you could group your placemarks into folders and have a Region on the folder to control when placemarks are visible. Creating the regions correctly takes some trial and error. You may not even need to specify the min/max altitude -- an appropriate minLodPixels value to the region dimensions may be enough.
A tutorial on Regions can be found here.
https://developers.google.com/kml/documentation/regions
StyleMap
You may want to create a StyleMap where the normal Style has a LabelStyle with a scale of 0 to suppress the labels entirely or a smaller value to simply reduce the clutter.
<Style id="sn_style">
<LabelStyle>
<scale>0</scale>
</LabelStyle>
</Style>
<Style id="sh_style">
<LabelStyle>
<scale>1.1</scale>
</LabelStyle>
</Style>
<StyleMap id="msn_style">
<Pair>
<key>normal</key>
<styleUrl>#sn_style</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_style</styleUrl>
</Pair>
</StyleMap>
Had the Same Problem and I couldn't find any quick solution for the as my .kml contained almost 10k POI's. So what I did was adding the code offered by the FAQ, so my header would look like this:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>name</name><Style id="hideLabel"><LabelStyle><scale>0</scale></LabelStyle></Style>
And I changed the first placemark to this:
Placemark>
<name>name</name>
<styleUrl>#hideLabel</styleUrl>
<ExtendedData><SchemaData schemaUrl="#name">
<SimpleData name="Name">name</SimpleData>
<SimpleData name="Latitude">xxxx</SimpleData>
<SimpleData name="Longitude">yyyy</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>xxxx,yyyy</coordinates></Point>
</Placemark>
After that I loaded the .kml into Google Earth and right-clicked onto it to select Properties. Select "Style, Color" tab and it should state the following:
The descendant(s) of this folder do not share the same Style. Click
the button below if you want to force all descendants to share the
same Style
Click the button below "Share Style" and it will temporarily hide all the labels.
Kind regards,
Thomas

links in kml balloons not working in GE 6

My KML placemarks have the description element populated as such
<description>
<![CDATA[
some text
someTag
]]>
</description>
With Google Earth 5, when you click on the link in the balloon, the kml is downloaded and displayed as expected.
With Google Earth pro 6, when you click on the link in the balloon, nothing happens. You have to right click on the link and then select "Open in New Window". Then the KML is downloaded and displayed in Google Earth.
Does anyone know why there is the behavoir difference between GE 5 and GE6? How do I get links in kml balloons to download in GE6 without requiring the right click workaround
There were some updates to handling URLs and hrefs between GE 5 and 6. GE 5 allowed some sloppy URLs and 6.0 became stricter in a few places to better conform to the specs. There weren't a lot of details on the specifics. Check the syntax of the URL and make sure it opens in your web browser.
Note if you want to fly-to a target Placemark in another KML file you specify the id of that Placemark as an anchor in the URL with a "#" followed by the id (see example below in second link).
Here's a KML example that works in GE 6.2.2:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Test</name>
<description>
<![CDATA[
test URL#1
<P>
test URL#2 w/anchor
]]>
</description>
<Point>
<coordinates>-123.0821604290386,37.42041505714916</coordinates>
</Point>
</Placemark>
</kml>

Google Earth link PDF or image file on company server to placemark

I want to display multiple jpg(s) and/or pdf file(s) to a single placemark. The file path is in my company's directory and I would like anyone in the company that I send this google earth file to have the ability to view each placemark.
I have tried the command and neither seem to be working.
Both of these commands work with images at a "http:// address" but not with references to my hard drive nor server.
A KML Placemark can contain any number of images in its description. Most HTML will render inside the description of any given Placemark.
Option 1. Linking to a PDF or other media via URL within KML
Here's sample KML file to launch in Google Earth which will show an inline image in the popup balloon with a link to a PDF file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Placemark>
<name>Test</name>
<snippet/>
<description>
<![CDATA[<a href="http://stlab.adobe.com/wiki/images/d/d3/Test.pdf"><img
src="http://stlab.adobe.com/wiki/skins/common/images/icons/fileicon-pdf.png"></a>
]]>
</description>
<gx:balloonVisibility>1</gx:balloonVisibility>
</Placemark>
</kml>
Note the gx:balloonVisibility tag which if set to "1" will auto-display the popup. That's a useful feature.
If images are within your hard-drive then you won't be able to share the KML with others unless you either bundle the images inside a KMZ file or publish the images to web site in your company so they are accessible via a URL.
Option 2. Embed the PDF within the Placemark description balloon
One trick to directly embed the PDF within the Placemark description balloon is using the Google PDF viewer in an iframe and substitute the test URL for actual URL in link below.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Test</name>
<snippet/>
<description>
<![CDATA[
<iframe src="http://docs.google.com/gview?url=http://stlab.adobe.com/wiki/images/d/d3/Test.pdf&embedded=true"
style="width:718px; height:700px;" frameborder="0"></iframe>
]]>
</description>
</Placemark>
</kml>
This technique doesn't need a Flash player and works in Google Earth.
Note if you do this too many times and/or try for very large documents then the viewer will display the message:
You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format. Please try again later.

Resources