开发者

Referring to a Placemark in KML

Is there a way to refer to a placemark (probably by using the Placemark ID attribute) ?

Use case:

Suppose you have a list of bus stops in a city. Some stops will be common to many bus lines. If Placemark referencing was possible, there could be a master list of all stops and each line (set in a separate Folder) could just refer to one of the above Placemarks. Selecting more than one Folder would display the other Placemarks for those lines,开发者_C百科 but the Placemarks already displayed would not show multiple times.

That would produce a lot less clutter, especially with the names displayed only once.


Unfortunately not as the Kml Schema does not support One-to-Many Relationships or symbolic links (apart from styles, but that is not really of any use to you.)

However, one way you could emulate this is by using links in folder descriptions.

To use your example, say you have a single file that has your master list of 'bus stop' place-marks defined in it. You could then define all your routes in folders with description links to the relevant stops.

Obviously all the place-marks are always shown, but each 'route folder' would at least allow you to move between the stops for that route without having to duplicate the stop data.

e.g.

<kml>
  <Folder id="stops">
    <Placemark id="p1">
      <name>stop 1</name>
    </Placemark>
    <Placemark id="p2">
      <name>stop 2</name>
    </Placemark>
    <Placemark id="p3">
      <name>stop 3</name>
    </Placemark>
    <Placemark id="p4">
      <name>stop 4</name>
    </Placemark>
    </Folder>
    <Folder id="r1">
      <name>route 1</name>
      <description>
        <![CDATA[
        <a href="#p1;balloonFlyto">stop 1</a>
        <a href="#p3;balloonFlyto">stop 3</a>
        ]]>
      </description>
    </Folder>
    <Folder id="r2">
      <name>route 2</name>
      <description>
        <![CDATA[
        <a href="#p1;balloonFlyto">stop 1</a>
        <a href="#p2;balloonFlyto">stop 2</a>
        <a href="#p4;balloonFlyto">stop 4</a>
        ]]>
      </description>
    </Folder>
</kml>

EDIT

You could also simply keep your data in something that does support one-to-many, like a mysql database. You could then query it however you liked to produce the KML as required based on the request made. Take a look at this Database Driven Earth App Using PHP & MySQL with the Earth API it goes through how you might set up a database to hold your data, how to query it and output KML from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜