Hello. I'm trying to display markers on map using leaflet, but unfortunatelly markers doesn't display :( Markers are downloaded from "mapframe-markers.xml". My suggestion is, that I try to insert only one marker into initialize() function: for example: L.marker([51, 0.09]).addTo(map); - marker is visible on map. But when i try to insert this same marker: L.marker([51, 0.09]).addTo(map); - into timeout() function or addMarker() function - it display error in Firebug:
TypeError: t is undefined. Can anyone help me, please:) Thanks for helping. Below is my code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="
http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="
http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style type="text/css">
#map-canvas {position:fixed !important; position:absolute; top:0; left:200px; right:0; bottom:0; }
</style>
<script>
var map;
var markers = [];
function initialize() {
var map = L.map('map-canvas').setView([51,25], 10);
L.tileLayer('http://{s}.
tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="
http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="
http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="
http://mapbox.com">Mapbox</a>',
id: 'examples.map-i86knfo3'
}).addTo(map);
timeout();
}
function timeout() {
downloadUrl("mapframe-markers.xml", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var Lat = parseFloat(markers[i].getAttribute("lat"));
var Lng = parseFloat(markers[i].getAttribute("lng"));
var point = new L.LatLng(Lat, Lng);
addMarker(point, i);
}
});
}
function addMarker(location, i) {
var marker = L.marker([location]).addTo(map);
markers.push(marker);
}
L.DomEvent.addListener(window, 'load', initialize);
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {
}
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>