henrythasler / Leaflet.Geodesic

Add-on to draw geodesic lines with leaflet
GNU General Public License v3.0
155 stars 27 forks source link

local build results in inproper augmentation of 'L' #98

Closed Axolord closed 1 year ago

Axolord commented 1 year ago

Hi, I am kind of new to this whole leaflet plugin stuff, but through multiple testings I have found the following problem: If I build your project locally and install & import it inside my angular project, it does not augment the Closure's 'L' from leaflet, while it does augment the Globals 'L'. So inside the chrome dev tools, I can see the L.Geodesic Class under "Global", but not under "Closure".

If I then instead install the module from npmjs.com, it does work for both "Global" and "Closure".

How can that be?

Steps to reproduce:

git pull git@github.com:henrythasler/Leaflet.Geodesic.git
cd Leaflet.Geodesic
npm i
npm run build

cd ../angular_project
npm install ../Leaflet.Geodesic

inside my angular project I have a "map.component.ts" with the following code:

import { Component} from '@angular/core';
import { GeojsonService } from '../geojson.service';

import * as L from 'leaflet';
import 'leaflet.geodesic';
import 'leaflet-rotatedmarker';

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss'],
})
export class MapComponent {
  private track_layer!: L.GeoJSON
  private map!: L.Map; 

  constructor(private geojsonService: GeojsonService) { }

  ngOnInit(): void {
    this.map = L.map('map', {
      preferCanvas: true,
      crs: L.CRS.Simple
    });
  L.geodesic([L.latLng(0, 0)]);
  }
}

But I get the error

Error: src/app/map/map.component.ts:32:7 - error TS2339: Property 'geodesic' does not exist on type 'typeof import("C:/......./frontend_angular/node_modules/@types/leaflet/index")'.
     L.geodesic([L.latLng(0, 0)])
       ~~~~~~~~

Install from repo:

npm uninstall leaflet.geodesic
# check package.json and package-lock.json for any references
npm install leaflet.geodesic

=> and then it works again...

Axolord commented 1 year ago

Well, now I tried to publish my self built package to a verdaccio repo under a different name and tried installing that... and now it works out fine again. Seems strange to me and I dont know why it happens, maybe someone can try to reproduce it..? Otherwise I will close the issue in a few days :)

henrythasler commented 1 year ago

I'm glad you found a way that works for you as I have no idea (I have no experience with angular) as to why this happens.