Cette fonction permet d'ajouter la couche kml sur une carte Google Maps
addKmlLayer
- Paramètres spécifiques :
- url <chaîne> : URL du fichier kml
- Nom de stockage : kmllayer
- Résultat du Callback : google.maps.KmlLayer
$("#maCarte").gmap3(
{
action:"init",
mapTypeId:google.maps.MapTypeId.TERRAIN,
center:[51.859667,7.350874],
zoom:5,
disableDefaultUI:true
},
{
action:"addKmlLayer",
url:"http://maps.google.de/maps/ms?oe=UTF8&client=firefox-a&ie=UTF8&hl=de&vps=1&jsv=327b&msa=0&msid=204641735089812811439.00049fc240d6b5cd876b2&output=kml",
options:{
suppressInfoWindows:true,
preserveViewport:false
}
}
)
Premier exemple
Dans ce premier exemple GMap3 utilisant addKmlLayer on affiche dans une carte les informations contenues dans un fichier KML.
Carte avec addKmlLayer
Code complet avec addKmlLayer
<!DOCTYPE html>
<html lang="fr">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="UTF-8"/>
<title>Votre titre de page</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#maCarte{
height: 350px;
width: 100%;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://www.votredomaine.fr/js/gmap3.js"></script>
<script type="text/javascript">
$(function(){
$("#maCarte").gmap3(
{
action:"init",
mapTypeId:google.maps.MapTypeId.TERRAIN,
center:[51.859667,7.350874],
zoom:5,
disableDefaultUI:true
},
{
action:"addKmlLayer",
url:"http://maps.google.de/maps/ms?oe=UTF8&client=firefox-a&ie=UTF8&hl=de&vps=1&jsv=327b&msa=0&msid=204641735089812811439.00049fc240d6b5cd876b2&output=kml",
options:{
suppressInfoWindows:true,
preserveViewport:false
}
}
)
});
</script>
</head>
<body>
<div id="maCarte"></div>
</body>
</html>
Deuxième exemple
Dans ce second exemple les informations contenues dans deux fichiers KML sont affichées sur la carte. Deux cases à cocher permettent des les afficher/masquer.
KML 1
KML 2
Carte avec addKmlLayer
Code complet avec addKmlLayer
<!DOCTYPE html>
<html lang="fr">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="UTF-8"/>
<title>Votre titre de page</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#maCarte{
height: 350px;
width: 100%;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://www.votredomaine.fr/js/gmap3.js"></script>
<script type="text/javascript">
$(function(){
$('#maCarte').gmap3(
{
action: 'addKmlLayer',
url: 'http://www.touraineverte.com/gmap3/kml/rungis.kml',
options:{
suppressInfoWindows: true
},
tag:'chk1'
},
{
action: 'addKmlLayer',
url: 'http://www.touraineverte.com/gmap3/kml/sogaris.kml',
options:{
suppressInfoWindows: true
},
tag:'chk2'
}
);
$('.tools input[type=checkbox]').change(function(){
var map = $('#maCarte').gmap3('get'),
kml = $('#maCarte').gmap3({
action:'get',
name:'kmllayer',
tag: $(this).attr('id')
});
kml.setMap( $(this).is(':checked') ? map : null );
});
});
</script>
</head>
<body>
<div class="tools">
<input type="checkbox" id="chk1" checked>KML 1
<input type="checkbox" id="chk2" checked>KML 2
</div>
<div id="maCarte"></div>
</body>
</html>
