Keyhole Markup Language (KML) is an XML notation for expressing geographic annotation and visualization within Internet-based, two-dimensional maps and three-dimensional Earth browsers. KML became an international standard of the Open Geospatial Consortium in 2008. Google Earth was the first program able to view and graphically edit KML files. Other projects such as Marble have also started to develop KML support.
You can create KML files with the Google Earth user interface, or you can use an XML or simple text editor to enter "raw" KML from scratch.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<!--
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ModulePrefs
title="Embedded KML Viewer"
title_url="http://www.gmodules.com/ig/creator?synd=open&url=http://www.nearby.org.uk/google/embedkmlgadget-v3-ll.xml"
directory_title="Embedded KML Viewer"
thumbnail="http://code.google.com/apis/kml/embed/res/embedkmlgadget-thumb.png"
screenshot="http://code.google.com/apis/kml/embed/res/embedkmlgadget-screen.png"
author="Roman Nurik"
author_email="api.roman.public+embedkmlgadget@gmail.com"
author_affiliation="Google"
width="500"
height="400"
description="Embed a KML file in your page using Google Earth or Google Maps!">
<Locale lang="en" country="us"/>
</ModulePrefs>
<UserPref name="kml_url" display_name="KML or My Maps URL"/>
<UserPref name="view_mode" display_name="View mode" default_value="earth" datatype="enum">
<EnumValue value="maps" display_value="2D (Google Maps)"/>
<EnumValue value="earth" display_value="3D (Google Earth Plugin)"/>
</UserPref>
<UserPref name="lat" display_name="Optional - Center Latitude (leave blank to center on KML file)"/>
<UserPref name="lng" display_name="Optional - Center Longitude (leave blank to center on KML file)"/>
<UserPref name="zoom" display_name="Maps zoom level - Optional"/>
<UserPref name="earth_2d_fallback" display_name="3D - Fall back to 2D on error" datatype="bool"/>
<UserPref name="earth_fly_from_space" display_name="3D - Fly in from space" default_value="true" datatype="bool"/>
<UserPref name="earth_show_nav_controls" display_name="3D - Show navigation controls" default_value="1" datatype="bool"/>
<UserPref name="earth_show_buildings" display_name="3D - Show buildings" default_value="1" datatype="bool"/>
<UserPref name="earth_show_terrain" display_name="3D - Show 3D terrain" default_value="1" datatype="bool"/>
<UserPref name="earth_show_roads" display_name="3D - Show roads" default_value="1" datatype="bool"/>
<UserPref name="earth_show_borders" display_name="3D - Show borders and labels" default_value="1" datatype="bool"/>
<UserPref name="earth_sphere" display_name="3D - Sphere" default_value="earth" datatype="enum">
<EnumValue value="earth" display_value="Earth"/>
<EnumValue value="sky" display_value="Sky"/>
<EnumValue value="moon" display_value="Moon"/>
<EnumValue value="mars" display_value="Mars"/>
</UserPref>
<UserPref name="maps_streetview" display_name="2D - Enable Streetview" datatype="bool"/>
<UserPref name="maps_zoom_out" display_name="2D - Zoom out on load" datatype="bool"/>
<UserPref name="maps_default_type" display_name="2D - Default Map Type" default_value="map" datatype="enum">
<EnumValue value="map" display_value="Map"/>
<EnumValue value="satellite" display_value="Satellite"/>
<EnumValue value="hybrid" display_value="Hybrid"/>
<EnumValue value="terrain" display_value="Terrain"/>
</UserPref>
<Content type="html"><![CDATA[
<script type="text/javascript" src="http://www.google.com/jsapi?hl=en&key=ABQIAAAAKkfkHb2nXsD0o1OX2TbdkRTZdFmpiU8vv3PBIA-hr88t-5BzzxQjEeEmKaZUy66ADwTlY8x2M14hHg"></script>
<script type="text/javascript">
google.load('earth', '1');
google.load('maps', '3', {"other_params":"sensor=false"});
var ge = null;
var map = null;
var prefs = new _IG_Prefs();
var appPath = 'http://code.google.com/apis/kml/embed/';
/**
* Prepare to create the gadget UI.
*/
function initGadget(viewMode) {
// Bugfix for IE6.
var c = document.getElementById('mapcontainer');
while (c && c.offsetParent != c) {
c.style.height = '100%';
c = c.offsetParent;
}
createGadgetUI(prefs.getString('view_mode'));
}
/**
* Create the gadget UI, which consists of either a Google Map or a
* Google Earth Plugin instance.
*/
function createGadgetUI(viewMode) {
var kmlUrl = prefs.getString('kml_url');
// Clean kmlUrl to accept My Maps URLs.
myMapsMatch = kmlUrl.match(/maps\.google\.[a-z]+.*msid=([0-9a-f.]+)/);
if (myMapsMatch) {
kmlUrl = 'http://maps.google.com/maps/ms?msa=0&output=kml&msid=' +
myMapsMatch[1];
}
if (viewMode == 'maps') {
// Create a V3 Google Map.
if (prefs.getString('lat') && prefs.getString('lng')) {
var myLatlng = new google.maps.LatLng(parseFloat(prefs.getString('lat')),parseFloat(prefs.getString('lng')));
} else {
var myLatlng = new google.maps.LatLng(0,0);
}
var myMapType = google.maps.MapTypeId.ROADMAP
var defaultMapType = prefs.getString('maps_default_type');
if (defaultMapType == 'satellite')
myMapType = google.maps.MapTypeId.SATELLITE
else if (defaultMapType == 'hybrid')
myMapType = google.maps.MapTypeId.HYBRID
else if (defaultMapType == 'terrain')
myMapType = google.maps.MapTypeId.TERRAIN;
var myOptions = {
zoom: 1,
center: myLatlng,
mapTypeId: myMapType
}
if ( prefs.getString('zoom') )
myOptions['zoom'] = parseInt(prefs.getString('zoom'));
if ( prefs.getBool("maps_streetview"))
myOptions['streetViewControl'] = true;
map = new google.maps.Map(document.getElementById('mapcontainer'),myOptions);
if (kmlUrl) {
// Apply a cachebuster.
kmlUrl += (kmlUrl.indexOf('?') >= 0 ? '&' : '?') +
Number(new Date()).toString();
var myKmlOptions = {
map: map
}
if (prefs.getBool('maps_zoom_out'))
myKmlOptions['preserveViewport'] = true;
var kmlLayer = new google.maps.KmlLayer(kmlUrl,myKmlOptions);
}
} else if (viewMode == 'earth') {
if (!google.earth.isInstalled() &&
prefs.getBool('earth_2d_fallback')) {
// Fall back to Maps if the Google Earth Plugin isn't installed.
createGadgetUI('maps');
return;
}
// Determine which sphere to create (earth/sky/moon/mars).
var createOptions = {};
var sphere = prefs.getString('earth_sphere') || 'earth';
if (sphere == 'mars' || sphere == 'moon')
createOptions = { database: 'http://khmdb.google.com/?db=' + sphere };
google.earth.createInstance('mapcontainer', function(pluginInstance) {
ge = pluginInstance;
if (sphere == 'sky')
ge.getOptions().setMapType(ge.MAP_TYPE_SKY);
ge.getWindow().setVisibility(true);
// Set options.
ge.getNavigationControl().setVisibility(
prefs.getBool('earth_show_nav_controls') ? ge.VISIBILITY_AUTO : ge.VISIBILITY_HIDE);
if (sphere == 'earth') {
ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS,
prefs.getBool('earth_show_buildings'));
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN,
prefs.getBool('earth_show_terrain'));
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS,
prefs.getBool('earth_show_roads'));
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS,
prefs.getBool('earth_show_borders'));
}
if (kmlUrl) {
// If loading KML, create a KmlNetworkLink with a flyToView=1.
var link = ge.createLink('');
link.setHref(kmlUrl);
var nl = ge.createNetworkLink('');
nl.setLink(link);
if (prefs.getString('lat') && prefs.getString('lng')) {
// Get the current view
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Set new latitude and longitude values
lookAt.setLatitude(parseFloat(prefs.getString('lat')));
lookAt.setLongitude(parseFloat(prefs.getString('lng')));
if ( prefs.getString('zoom') ) {
// $zoom = (-1.4956 * log($range/1000)) + 16.529;
var zoom = parseInt(prefs.getString('zoom'),10);
var range = 1000*Math.pow(Math.E,(zoom-16.529)/-1.4956);
lookAt.setRange(Math.round( range ));
}
// Update the view in Google Earth
ge.getView().setAbstractView(lookAt);
} else {
nl.setFlyToView(true);
}
var originalFlyToSpeed = ge.getOptions().getFlyToSpeed();
if (!prefs.getBool('earth_fly_from_space'))
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
ge.getFeatures().appendChild(nl);
window.setTimeout(function() {
ge.getOptions().setFlyToSpeed(originalFlyToSpeed);
}, 500);
}
}, function(error) {
if (prefs.getBool('earth_2d_fallback')) {
// Upon plugin creation failure, use Maps as a fallback.
createGadgetUI('maps');
}
}, createOptions);
}
}
google.setOnLoadCallback(initGadget);
</script>
<div id="mapcontainer" style="width: 100%; height: 100%;"></div>
]]></Content>
</Module>