egmapkmlfeed A KML Feed Generator for Google Maps v3

  1. Requirements
  2. Usage
  3. Resources

KML is a file format used to display geographic data in an Earth browser, such as Google Earth, Google Maps, and Google Maps for mobile. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is an international standard maintained by the Open Geospatial Consortium, Inc. (OGC).

The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file. Because the components within a KmlLayer are rendered on demand, the layer allows you to easily manage the rendering of thousands of markers, polylines, and polygons.

Note that you can't access these constituent objects directly, though they each provide click events which return data on those individual objects.

EGMapKMLFeed Generator will allow you to create a KML Feed for your google maps scripts. It was created in order to work in conjunction with the new KML feature of EGMap version 2.0 (Extension also found on this repository).

Handles all supported tags of KML for Google Maps v3 even though includes a set of classes to create your own and also handles the creation of Tags array based so to provide flexibility in your KML docs.

I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.

Requirements

Developed with Yii 1.1.6.r2877

Usage

Unpack the library and place it on your extensions library, then import the library through its correct path.

Example 1

The following example will create a feed to display a marker on the map.

Yii::import('ext.kml.*');

// add one Icon style to the generator
$iconStyle = new EGMapKMLIconStyle('testStyle', 'iconID', 'http://maps.google.com/mapfiles/ms/icons/purple-pushpin.png');

$kml->addTag($iconStyle);

// create one marker placemark
$placemark = new EGMapKMLPlacemark('Another Marker');
// tell which style we are going to use
$placemark->styleUrl = '#testStyle';
// the following will be displayed on its bubble info window
$placemark->description = 'This marker has <b>HTML</b>';
// add a tag child EGMapKMLPoint which will tell the
// latitude and longitude of the marker
// *Note that for KML the lat and lon are the other way around
// should be lon - lat
$placemark->addChild(new EGMapKMLPoint('39.718762871171776', '2.903637075424208'));

$kml->addTag($placemark);

// generate feed
$kml->generateFeed();
Example 2

How to create a KML feed that will display a line on the map

Yii::import('ext.kml.*');

// create a line style
$lineStyle = new EGMapKMLLineStyle('lineStyleID', 'lineID', 'FFAA00FF', '4');

$kml->addTag($lineStyle);

// create a Placemark LineString, specifying its info and style
$placemark = new EGMapKMLPlacemark('LineString','Just testing this line', '#lineStyleID');

// create the linestring and give it the coordinates
// coordinates go on LONGITUDE, LATITUDE, ELEVATION
$line = new EGMapKMLLineString(
array(
'-87.89289951324463,41.97881025520548,0',
'-87.89184808731079,41.97788506340239,0',
'-87.89150476455688,41.97762983571196,0',
'-87.8912901878357,41.97750222148314,0',
'-87.89090394973755,41.977326751500996,0',
'-87.89047479629517,41.97719913666485,0',
'-87.88987398147583,41.97707152157296,0',
'-87.88912296295166,41.97702366584759,0',
'-87.88856506347656,41.97708747347342,0',
'-87.88757801055908,41.977326751500996,0',
'-87.87487506866455,41.982574690129766,0',
'-87.87399530410767,41.9828777493635,0',
'-87.87305116653442,41.983101055244255,0',
'-87.87238597869873,41.983196757524844,0',
'-87.87172079086304,41.98327650931544,0'
));

// add Child Node to the placemark
$placemark->addChild( $line );

// add Placemark to the Feed Generator
$kml->addTag($placemark);

// generate feed
$kml->generateFeed();
Example 3

Creating a polygon

Yii::import('ext.kml.*');

// create a line style
// colors of Styles are compound like this:
// OPACITY[2]=FF - RED[2]=AA - GREEN[2]=00 - BLUE[2]=FF
// in hexadecimal code
$lineStyle = new EGMapKMLLineStyle('lineStyleID', 'lineID', 'FFAA00FF', '4');

$kml->addTag($lineStyle);

// create the Polygon Placemark
$placemark = new EGMapKMLPlacemark('Polygon','Just testing polygon', '#lineStyleID');

// Add a Polygon Child dynamically.
// Please see how the first coordinate is equal to
// the last coordinate, this is necessary to close 
// the polygon on the map
$placemark->addChild(new EGMapKMLPolygon(true, array('-122.1,37.4,0',
            '-122.0,37.4,0', '-122.0,37.5,0', '-122.1,37.5,0', '-122.1,37.4,0')));

$kml->addTag($placemark);


// generate feed
$kml->generateFeed();

Resources

5 0
6 followers
746 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags: Google, KML, rss, Yii
Developed by: Antonio Ramirez
Created on: Feb 3, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions