How to add KMZ file in drupal 7?

我的梦境 提交于 2020-01-06 07:10:14

问题


I have got KMZ file and I don't know how to show it from drupal. So, I research and found those codes.

function CoverageMap() {

  var map = new google.maps.Map(document.getElementById('coverageMap'), {
    zoom: 15,
    center: {lat: 16.800915763233845, lng: 96.1567211141123}
   });

   var kmzLayer = new google.maps.KmlLayer('http://test.dev/sites/all/themes/bootstrap_business/coverage/ygn_mdy.kmz');
   kmzLayer.setMap(map);

}

I put this code and save the file Coverage.js.
But, the file location is static location and I would like to change dynamic because the location will not be like this when I upload the file in server.
Can I put this code <?php echo base_path().path_to_theme() ?>/coverage/ygn_mdy.kmz
Should KMZ file put like this as an offline or is there other ways?
Please help me to solve this problem. I've been trying to find this since 2wks ago.


回答1:


I believe having a dynamic path for your KMLs is not a problem as long as you place them in the correct file. Adding <?php echo base_path().path_to_theme() ?> into a javascript file Coverage.js will likely wont work because it will just be treated as an ordinary string.

I would suggest all the javascript codes that there's a PHP involvement should be saved in a PHP file. In your case, saving it to something like Coverage.php and the code should look something like this:

function CoverageMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 11,
      center: {lat: 16.800915763233845, lng: 96.1567211141123 }
  });
  var kmzLayer = new google.maps.KmlLayer("<?php echo $base_path().$path_to_theme().'/coverage/ygn_mdy.kmz'; ?>");
  kmzLayer.setMap(map);
}

Check Google Maps Javascript API KML Layers to learn more. You can also check Displaying KML to learn more on displaying information of a KML file.

Hope this helps!



来源:https://stackoverflow.com/questions/47405385/how-to-add-kmz-file-in-drupal-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!