Created
August 8, 2013 16:19
-
-
Save CGastrell/6186110 to your computer and use it in GitHub Desktop.
Ejemplo para cargar un XML y parsear los marcadores para meter en un mapa argenmap()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="es"> | |
<head> | |
<meta charset="utf-8" /> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script src="http://code.jquery.com/jquery-1.8.2.js"></script> | |
<script type="text/javascript" src="http://www.ign.gob.ar/argenmap/argenmap.jquery.min.js"></script> | |
<script> | |
$(function() { | |
//El div tiene id="mapa" | |
$('#mapa').argenmap(); | |
$('#mapa').centro(-30, -59) | |
var marcadores = []; | |
$.get('mapa.xml',function(data){ | |
$(data).find('marker').each(function(){ | |
var marker = $(this); | |
marcadores.push({ | |
lat: marker.attr('lat'), | |
lng: marker.attr('lng'), | |
contenido: marker.attr('html'), | |
icono: $(marker.attr('html')).find('img').first().attr('src') | |
}); | |
}); | |
$('#mapa').agregarMarcadores( marcadores ); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h3>Leer un XML con varios marcadores para posicionar sobre un mapa</h3> | |
<div id="mapa" style="height:400px"></div> | |
<p> | |
En este ejemplo se crea un mapa y se carga un XML. El XML se procesa y se genera un array de marcadores para luego llamar a <code>agregarMarcadores()</code> pasándole el array de objetos acorde a los que recibe <code>.agregarMarcador()</code>. | |
</p> | |
<p> | |
El archivo XML de ejemplo es una porción del archivo XML que usa <a href="http://www.desarrollosocial.gob.ar/mapa.aspx">el sitio del Ministerio Desarrollo Social de la República Argentina</a> para publicar sus datos. | |
<p> | |
<a href="javascript:(function(){window.location='view-source:'+window.location})()">Ver el código fuente!</a> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment