简体   繁体   English

如何在 angular 中将 geojson object 转换为 KML

[英]How to convert geojson object to KML in angular

I need to convert my geojson object to kml file in my angular project.我需要在我的 angular 项目中将我的 geojson object 转换为 kml 文件。 Over some reearch I found this npm library geojson-to-kml .在一些研究中,我发现了这个 npm 库geojson-to-kml But problem which i am facing when I am trying to use this.但是当我尝试使用它时遇到的问题。 I m getting an error我收到一个错误

Could not find a declaration file for module 'geojson-to-kml'.找不到模块“geojson-to-kml”的声明文件。

I have tried installing with npm i @types/geojson-to-kml but its of no use throwing an error ERR 404 '@types/geojson-to-kml@*' is not in this registry.我尝试使用npm i @types/geojson-to-kml安装,但抛出错误 ERR 404 '@types/geojson-to-kml@*' 不在此注册表中。

Is there any way I can use this library in my angular project.有什么方法可以在我的 angular 项目中使用这个库。 Or is there any other way which will help me to convert geojson object to kml file.或者有没有其他方法可以帮助我将geojson object 转换为 kml 文件。

Any suggestions will be of great help.任何建议都会有很大帮助。

Try the following:尝试以下操作:

import { Component, OnInit, VERSION } from '@angular/core';
import tokml = require('tokml');

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
  name = 'Angular ' + VERSION.major;
  geoObject = {
    type: 'Feature',
    geometry: {
      type: 'Point',
      coordinates: [125.6, 10.1],
    },
    properties: {
      name: 'Dinagat Islands',
    },
  };
  kmlObject = tokml(this.geoObject);

  ngOnInit() {
    console.log(this.kmlObject);
  }
}

Here's the starblitz这里是明星闪电战

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM