0

I am using an external API built with javascript, and I need to call some functions on js file.

My main file are in src/asssets/openlayers/scripts/main.js

I imported them all on index.html, like

<script src="/assets/openlayers/scripts/libs/jquery-1.10.2.min.js"></script>
<script src="/assets/openlayers/scripts/libs/jquery-ui-1.10.3.custom/jquery-ui-1.10.3.custom.min.js"></script>
<script src="/assets/openlayers/scripts/libs/proj4js-1.1.0/proj4js-compressed.js"></script>
<script src="/assets/openlayers/scripts/libs/OpenLayers-2.13.1/OpenLayers.js"></script>

<script src="/assets/openlayers/scripts/main.js"></script>
<script src="/assets/openlayers/scripts/classes/event.js"></script>
<script src="/assets/openlayers/scripts/classes/drawing.js"></script>
<script src="/assets/openlayers/scripts/classes/culturesDrawing.js"></script>
<script src="/assets/openlayers/scripts/classes/cultureMarkerDrawing.js"></script>
<script src="/assets/openlayers/scripts/map/map.initialize.js"></script>
<script src="/assets/openlayers/scripts/map/map.js"></script>
<script src="/assets/openlayers/scripts/map/map.tool.js"></script>
<script src="/assets/openlayers/scripts/map/map.tools.js"></script>
<script src="/assets/openlayers/scripts/map/map.cookies.js"></script>
<script src="/assets/openlayers/scripts/map/map.custom.controls.js"></script>
<script src="/assets/openlayers/scripts/map/map.contextmenu.js"></script>
<script src="/assets/openlayers/scripts/map/map.info.js"></script>
<script src="/assets/openlayers/scripts/map/map.drawingLayer.js"></script>
<script src="/assets/openlayers/scripts/map/map.layerStyle.js"></script>
<script src="/assets/openlayers/scripts/map/map.spatialLayer.js"></script>
<script src="/assets/openlayers/scripts/map/map.rasterLayer.js"></script>
<script src="/assets/openlayers/scripts/map/map.Legend.js"></script>
<script src="/assets/openlayers/scripts/map/map.rasterLegend.js"></script>
<script src="/assets/openlayers/scripts/map/map.layerSwitcher.js"></script>
<script src="/assets/openlayers/scripts/map/map.tooltip.js"></script>
<script src="/assets/openlayers/scripts/map/map.obsolete.js"></script>

But now I need to call some fucntions that I have on main.js. How can I achieve this on my .ts file. I dont want to declare each function on the ts file like

declare var drawGauge: any;


import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'app-geospacial-map',
  templateUrl: './geospatial-map.component.html',
  styleUrls: ['./geospatial-map.component.scss'],
})
export class GeospacialMapComponent implements OnInit {

  constructor() {}

  ngOnInit(): void {

  }
}

It's possible to access everything from file globaly? Sry for my bad expression, it's a lot of stuff, just ask me if you need more explanation

Gonçalo Bastos
  • 376
  • 3
  • 16
  • @RameshRajendran No, because there the guy has an export variable and declare his method on .ts file. Imagine that I have 200 functions on main.js and need to use them all. I don want to declare each one on .ts – Gonçalo Bastos Dec 19 '22 at 13:22
  • @Justinas I tried, but says Property 'initializeOpenLayer' does not exist on type 'Window & typeof globalThis'. I dont want to edit the main.js to export it to window interface or something. I saw that on Vue I can use window only, and thought here could to – Gonçalo Bastos Dec 19 '22 at 13:22
  • @GonçaloBastos Ensure your function is added to global scope and not wrapped inside inner scope – Justinas Dec 19 '22 at 13:33

0 Answers0