2008-10-08 7 views
2

Un de mes amis a intégré un plugin google earth dans un contrôle utilisateur C#. Tout fonctionne bien, mais quand vous fermez la fenêtre, nous recevons "Erreur non spécifiée" avec l'option de continuer à exécuter les scripts ou non. De notre suivi, il semble que ce soit causé par un script que google tombe sur la page. Des idées?C# Google Earth Erreur

Répondre

2

est un exemple ici, par moi, de C#/intégration de Google API Terre qui couvre le problème que vous rencontrez (voir les commentaires) http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html

En outre, voici un autre de mes projets qui utilise la bibliothèque de types de plugins COM Google Earth (plugin_ax.dll) convertie dans les définitions équivalentes dans un ensemble d'exécution de langage commun. Cela peut être utile. http://fraserchapman.blogspot.com/2008/12/google-earth-plugin-control-library.html

0

Nous avons maintenant essayé cela à la fois IE et FF. Fonctionne bien. Des idées pour lesquelles l'erreur ne vient que de près? pouvons-nous en quelque sorte le désactiver? voici notre code.

<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<html> 
<head> 
    <script src="http://www.google.com/jsapi?key=ABQIAAAAzghEPRV_D0MDzTELJ4nkXBT2AlVLQD8Rz4_aVbiXesLoyhRIMBRo399nnxv9aY-fqnkVGgTgR-pTsg"> 
    </script> 
    <script> 
     google.load("earth", "1"); 
     var ge = null; 
     var placemark; 
     function init(){ 
      google.earth.createInstance("map3d", initCallback, failureCallback); 
     } 

     function initCallback(object){ 
      ge = object; 
      ge.getWindow().setVisibility(true); 
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW); 
      ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false); 

      placemark = ge.createPlacemark(''); 
      placemark.setName("Current Position"); 
      // Create style map for placemark 
      var normal = ge.createIcon(''); 
      normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png'); 
      var iconNormal = ge.createStyle(''); 
      iconNormal.getIconStyle().setIcon(normal); 
      var highlight = ge.createIcon(''); 
      highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png'); 
      var iconHighlight = ge.createStyle(''); 
      iconHighlight.getIconStyle().setIcon(highlight); 
      var styleMap = ge.createStyleMap(''); 
      styleMap.setNormalStyle(iconNormal); 
      styleMap.setHighlightStyle(iconHighlight); 
      placemark.setStyleSelector(styleMap); 

      var options = ge.getOptions(); 

      options.setStatusBarVisibility(true); 
      options.setScaleLegendVisibility(true); 
     } 

     function failureCallback(object){ 
      // Gracefully handle failure. 
      alert("Error"); 
     } 

     function changeViewAngle(angle){ 
      var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE); 
      lookAt.setTilt(angle); 
      ge.getView().setAbstractView(lookAt); 
     } 

     function ShowMarker(){ 
      ge.getFeatures().appendChild(placemark); 
     } 

     function MoveMarker(lon, lat){ 
      // Create point 
      var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND); 
      var point = ge.createPoint(''); 
      point.setLatitude(lat); 
      point.setLongitude(lon); 
      placemark.setGeometry(point); 
     } 

     function HideMarker(){ 
      ge.getFeatures().removeChild(placemark); 
     } 

     function SetPosition(lon, lat, heading){ 
      var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND); 
      lookAt.setLatitude(lat); 
      lookAt.setLongitude(lon); 
      lookAt.setHeading(heading); 
      ge.getView().setAbstractView(lookAt); 
     } 

     function SetAltitude(alt){ 
      var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND); 
      lookAt.set(lookAt.getLatitude(), lookAt.getLongitude(), 0, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, lookAt.getTilt(), alt); 
      ge.getView().setAbstractView(lookAt); 
     } 

     function ResizeMap(w, h){ 
      var map = document.getElementById('map3d_container'); 
      map.style.height = h; 
      map.style.width = w; 
     } 

     function AddKML(kml){ 
      var parseKML = ge.parseKml(kml); 
      ge.getFeatures().appendChild(parseKML); 
      return ge.getFeatures().getLastChild().getName(); 
     } 

     function RemoveKML(kmlName){ 
      if (ge.getFeatures().hasChildNodes()) { 
       var nodes = ge.getFeatures().getChildNodes(); 
       for (var i = 0; i < nodes.getLength(); i++) { 
        var child = nodes.item(i); 
        if (child.getName() == kmlName) { 
         ge.getFeatures().removeChild(child); 
        } 
       } 
      } 
     } 

     function OptionsChanged(nav, status, scale, grid, map, terrain, road, border, building){ 
      var options = ge.getOptions(); 
      var form = document.options; 

      if (nav) { 
       ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW); 
      } 
      else { 
       ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE); 
      } 

      options.setStatusBarVisibility(status); 
      options.setScaleLegendVisibility(scale); 
      options.setGridVisibility(grid); 
      options.setOverviewMapVisibility(map); 
      ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, terrain); 
      ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, road); 
      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, border); 
      ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, building); 
     } 



    </script> 
</head> 
<body onload='init()'> 
    <center> 
     <div id='map3d_container' style='border: 1px solid silver; height: 510px; width: 767px;'> 
      <DIV id=map3d style="HEIGHT: 100%"> 
      </DIV> 
     </div> 
    </center> 
</body> 
</html> 
0

J'ai exécuté l'échantillon et n'ai obtenu aucune erreur lors de la fermeture de l'onglet.

0

essayer cette

yourWebBrowser1.Document.Write (String.Empty);

lorsque vous fermez l'application.

ma question: pouvez-vous me montrer comment utiliser AddKML (kml) dans C# app? par chaîne ou chemin de fichier, j'ai essayé les deux. Je suis à la recherche d'un moyen pour analyser les fichiers kml ...

+0

Je ne sais pas, c'était un code d'amis. Pardon! –

Questions connexes