在Google地图网站脚本中插入KML文件

时间:2015-03-16 18:36:24

标签: javascript google-maps joomla

我有一个javascript文件,我想在其中插入kml Map Overlay。我认为这不是要知道要添加哪些代码的问题,而是需要准确添加的更多代码。

这是模板的Javascript文件:

// Google maps function
var gkMapInitialize = function() {
  var maps = jQuery('.gk-map');
  var mapCenters = [];
  var mapAreas = [];
  
  maps.each(function(i, map) {
  	map = jQuery(map);
	mapCenters[i] = new google.maps.LatLng(0.0, 0.0);
	  
	  
	if(map.data('latitude') !== undefined && map.data('longitude') !== undefined) {
		mapCenters[i] = new google.maps.LatLng(
			  		parseFloat(map.data('latitude')), 
			  		parseFloat(map.data('longitude'))
			  	);
	}
	  
	  
	  var mapOptions = {
	    zoom: parseInt(map.data('zoom'), 10) || 12,
	    center: mapCenters[i],
	    panControl: map.data('ui') === 'yes' ? true : false,
	    zoomControl: map.data('ui') === 'yes' ? true : false,
	    scaleControl: map.data('ui') === 'yes' ? true : false,
	    disableDefaultUI: map.data('ui') === 'yes' ? false : true,
	    mapTypeControl: map.data('ui') === 'yes' ? true : false,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
            position: google.maps.ControlPosition.TOP_CENTER
        }
	  };
	
	  mapAreas[i] = new google.maps.Map(map.get(0), mapOptions);

  

	  var link = jQuery('<a>', { class: 'gk-map-close'});
	  link.insertAfter(map);
	  // custom events for the full-screen display
	  var marker = null;


	  map.on('displaybigmap', function() {
	  	marker = new google.maps.Marker({
	  	   position: mapCenters[i],
	  	   map: mapAreas[i],
	  	   animation: google.maps.Animation.DROP
	  	});
	  	
	  

	  	setTimeout(function() {
	  		google.maps.event.trigger(mapAreas[i], 'resize');
	  	}, 300);
	  	
	  	mapAreas[i].setCenter(mapCenters[i]);

	  	if(map.data('line') !== undefined) {
	  		var points = map.data('line').split(';');
	  		var polyline = [];
	  		
	  		points = points.filter(function(x) { 
	  			return x != '';
	  		});
	  		
	  		jQuery.each(points, function(i, item) {
	  			var coords = item.split(',');
	  			polyline.push(new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1])));
	  		});
	  		
	  		if(points.length) {
	  			var path = new google.maps.Polyline({
	  				path: polyline,
	  				geodesic: true,
	  				strokeColor: '#ff0000',
	  				strokeOpacity: 1.0,
	  				strokeWeight: 2
	  			});
	  			
	  			path.setMap(mapAreas[i]);
	  		}
	  	}
	  });
	  
	  if(maps[i].hasClass('static')) {
	  	marker = new google.maps.Marker({
	  	   position: mapCenters[i],
	  	   map: mapAreas[i],
	  	   animation: google.maps.Animation.DROP
	  	});
	  }
	  
	  map.on('hidebigmap', function() {
	  	if(marker) {
	  		marker.setMap(null);
	  	}
	  });
  });
  
  jQuery(window).resize(function() {
  	mapAreas.each(function(map, i) {
  		map.setCenter(mapCenters[i]);
  	});
  });
};

我尝试使用我在网络上找到的代码段:

var geoXml = new GGeoXml("http://www.mawosoft.de/datei.kml");
  map.addOverlay(geoXml);

var layer = new google.maps.KmlLayer('<url of your KML file>');

layer.setMap(地图);

在上面文件中的不同位置,但它没有在地图中显示kml叠加。

有人可以帮助我吗?

非常感谢和问候,

Elisa的

0 个答案:

没有答案