简体   繁体   中英

How to convert geojson object to KML in angular

I need to convert my geojson object to kml file in my angular project. Over some reearch I found this npm library 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'.

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.

Is there any way I can use this library in my angular project. Or is there any other way which will help me to convert geojson object to kml file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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