Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 链接列表;请看「;KML地标_Html_Kml_Google Earth Plugin - Fatal编程技术网

Html 链接列表;请看「;KML地标

Html 链接列表;请看「;KML地标,html,kml,google-earth-plugin,Html,Kml,Google Earth Plugin,我试图在GE旁边添加一列,列中包含所有位置标记的列表,如链接或按钮,当您单击这些链接时,它将退出巡演并跳转到(或飞到)该位置,并弹出气球 KML在巡演中有一个FlyTo和LookAt的列表,在文档中有一个Placemarks:) 以下是我的KML placemark的一个示例: <Placemark id="Mussorie"> <name>Karen Snyder</name> <description> Karen Snyder is

我试图在GE旁边添加一列,列中包含所有位置标记的列表,如链接或按钮,当您单击这些链接时,它将退出巡演并跳转到(或飞到)该位置,并弹出气球

KML在巡演中有一个FlyTo和LookAt的列表,在文档中有一个Placemarks:)

以下是我的KML placemark的一个示例:

<Placemark id="Mussorie">
 <name>Karen Snyder</name>
  <description>
  Karen Snyder is an Arts Specialist learning language and culture through the arts in     Mussorie, India
    </description>
    <styleUrl>#Icon</styleUrl>
    <Point>
     <coordinates>79.134521,30.040566,0</coordinates>
    </Point>
   </Placemark>

卡伦·斯奈德
卡伦·斯奈德(Karen Snyder)是一位艺术专家,在印度墨索里通过艺术学习语言和文化
#图标
79.134521,30.040566,0
以下是我的JavaScript和HTML:

<html>
    <head>
      <title>Shepherd Global Outreach Partners</title>
      <script src="https://www.google.com/jsapi"> </script>
      <script src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js" type="text/javascript"> </script>
      <script type="text/javascript">
        var ge;
        var tour;
        var curr_pm;
        var obj_pm;
        var linksit='';
        var linksitcount=1;
        var links = [];
        google.load("earth", "1");

        function init() {
          var urlquery = location.href.split("?");
          if(urlquery[1]) {
            var urlterms = urlquery[1].split(",");
            curr_pm = urlterms[0];
          }

          google.earth.createInstance('map3d', initCB, failureCB);
        }

        function initCB(instance) {
          ge = instance;
          ge.getWindow().setVisibility(true);
          ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);

          var href = 'http://www.shepnet.org/GO.kml?ID='+Math.floor((Math.random()*100000)+1) ;
          google.earth.fetchKml(ge, href, fetchCallback);

          function fetchCallback(fetchedKml) {
             // Alert if no KML was found at the specified URL.
             if (!fetchedKml) {
                setTimeout(function() {
                    alert('Bad or null KML');
                 }, 0);
                 return;
             }

             // Add the fetched KML into this Earth instance.
             ge.getFeatures().appendChild(fetchedKml);

             // Walk through the KML to find the tour object; assign to variable 'tour.'
             walkKmlDom(fetchedKml, function() {
                if (this.getType() == 'KmlTour') {
                   tour = this;
                   return false;
                 }
             });

            if (tour) {
              ge.getTourPlayer().setTour(tour);
              ge.getTourPlayer().play();
              ge.getTourPlayer().setLoop(true) 
            }

            if (!fetchedKml) {
              // wrap alerts in API callbacks and event handlers
              // in a setTimeout to prevent deadlock in some browsers
              setTimeout(function() {
                alert('Bad or null KML');
              }, 0);
              return;
            }

            // Show the entire KML file in the plugin.
            currentKmlObject = fetchedKml;
            ge.getFeatures().appendChild(currentKmlObject);

            //Walk the DOM looking for a KmlLineString - the Race Path
            var links = [];
            walkKmlDom(fetchedKml, function() {
            if (this.getType() == 'KmlPlacemark') {
              // create a link to the placemark
              links.push('<a href="javascript:void(0);" onclick="flyto(\'' + this.getUrl() + '\')"> ' + this.getName() + ' </a><br>');
            }});

            for (index = 0; index < links.length; ++index) {
              console.log(links[index]);
            }

          }
        }

        var flyto = function(url) {
          // close any currently open balloon.
          ge.setBalloon(null); 

          // find the placemark from the url parameter
          var placemark = ge.getElementByUrl(url);
          if(placemark == null) {
            console.log("Placemark is null: " + url);
            return;
          }

          // create a lookat based on that feature's geometry 
          var lookAt = ge.createLookAt('');
          lookAt.setLatitude(placemark.getGeometry().getLatitude());
          lookAt.setLongitude(placemark.getGeometry().getLatitude())

          // Update the view in Google Earth using the lookat
          ge.getView().setAbstractView(lookAt);

          // open the feature's balloon
          ge.setBalloon(placemark.getBalloon());
        }

        function failureCB(errorCode) {
        }

        function UCLA() {
          ge.getTourPlayer().reset();
          var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
          camera.setLatitude(34.0688272174651);
          camera.setLongitude(-118.445067424559);
          camera.setAltitude(10000);
          ge.getView().setAbstractView(camera);   
        }

        function pauseTour() {
          window.open(href = 'http://www.shepnet.org/GO.kml#UCLA');  
        }

        function resetTour() {
          ge.getTourPlayer().reset();
        }
        function exitTour() {
          ge.getTourPlayer().setTour(null);
        }

        google.setOnLoadCallback(init);

      </script>
    </head>
      <body>
      <div id="map3d" style="height: 768px; width: 1280px;"></div>
      <div id ="controls">
        <input type="button" onClick="flyto('http://www.shepnet.org/GO.kml#UCLA')" value="UCLA"/>
        <input type="button" onClick="resetTour()" value="Stop/Reset Tour"/>
        <input type="button" onClick="exitTour()" value="Exit Tour"/>
        <a href="javascript:void(0);" onClick="flyto('http://www.shepnet.org/GO.kml#Mussorie')"> 'Mussorie' </a>
      </div>
      </body>
  </html>

Shepherd全球外联伙伴
var-ge;
旅游;
var curr_pm;
var obj_pm;
var linksit='';
var-linksitcount=1;
var-links=[];
谷歌加载(“地球”,“1”);
函数init(){
var urlquery=location.href.split(“?”);
if(urlquery[1]){
var urlterms=urlquery[1]。拆分(“,”);
curr_pm=urlterms[0];
}
createInstance('map3d',initCB,failureCB);
}
函数initCB(实例){
ge=实例;
ge.getWindow().setVisibility(true);
ge.getLayerRoot().enableLayerById(ge.LAYER\u BORDERS,true);
var href=http://www.shepnet.org/GO.kml?ID=“+Math.floor((Math.random()*100000)+1);
fetchKml(ge,href,fetchCallback);
函数fetchCallback(fetchedKml){
//如果在指定的URL上未找到KML,则发出警报。
如果(!fetchedKml){
setTimeout(函数(){
警报(“错误或空KML”);
}, 0);
返回;
}
//将获取的KML添加到此Earth实例中。
ge.getFeatures().appendChild(fetchedKml);
//遍历KML以查找巡更对象;分配给变量“tour”
walkKmlDom(fetchedKml,function(){
if(this.getType()=='KmlTour'){
旅游=这个;
返回false;
}
});
国际单项体育联合会(巡回赛){
ge.getTourPlayer().setTour(tour);
ge.getTourPlayer().play();
ge.getTourPlayer().setLoop(true)
}
如果(!fetchedKml){
//在API回调和事件处理程序中包装警报
//设置超时以防止某些浏览器中出现死锁
setTimeout(函数(){
警报(“错误或空KML”);
}, 0);
返回;
}
//在插件中显示整个KML文件。
currentKmlObject=fetchedKml;
ge.getFeatures().appendChild(currentKmlObject);
//在DOM中行走,寻找一条公里长的赛道
var-links=[];
walkKmlDom(fetchedKml,function(){
if(this.getType()=='KmlPlacemark'){
//创建指向placemark的链接
links.push(“
”); }}); 对于(索引=0;索引
您可以修改当前的
walkKmlDom
实现,因为它已经在遍历kml dom并检查位置标记。i、 e

walkKmlDom(fetchedKml, function() {
            if (this.getType() == 'KmlPlacemark' && this.getID().toLowerCase() == curr_pm.toLowerCase()) {
                obj_pm = this;
                    return false; // stop the DOM walk here.
            } 
只需使用它来构建指向placemarks的链接列表。您可以在placemark对象上使用
getUrl
。看


嘿,非常感谢你的回答:)但我似乎仍然有问题,我确信当涉及到这个问题时,我是个十足的傻瓜。就像我说的im new:(.但是当我创建一个指向flyto函数TypeError的链接时,我遇到了这个错误:placemark为null[Break On this error]var point=placemark.getGeometry();我非常感谢您在这方面的帮助。它似乎正在通过您给我的脚本添加所需的URL,但似乎URL#placemark实际上并没有从KML文件中提取placemark数据。每个placemark返回空。我添加了一个placemark KML格式示例以及更新的HTML w感谢你给我的改变。我理解如果你不想再帮我了,谢谢你迄今为止对我的帮助:)我会的
var links = [];
walkKmlDom(fetchedKml, function() {
  if (this.getType() == 'KmlPlacemark') {
    // create a link to the placemark
    links.push('<a href="javascript:void(0);" onclick="flyto(' + this.getUrl() + ')"> ' + this.getName() + ' </a>');
    // rest of your current conditional logic here
    // if(this.getID().toLowerCase()) etc..
  } 
}

// do something with links...
for (index = 0; index < links.length; ++index) {
  console.log(links[index]);
}
var flyto = function(url) {
  // close any currently open balloon.
  ge.setBalloon(null); 

  // find the placemark from the url parameter
  var placemark = ge.getElementByUrl(url); 
  if(placemark == null) {
    console.log("Placemark is null: " + url);
    return;
  }

  // create a lookat based on that feature's geometry 
  var lookAt = ge.createLookAt('');
  lookAt.setLatitude(placemark.getGeometry().getLatitude());
  lookAt.setLongitude(placemark.getGeometry().getLatitude())

  // Update the view in Google Earth using the lookat
  ge.getView().setAbstractView(lookAt);

  // open the feature's balloon
  ge.setBalloon(placemark.getBalloon());
}