You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
}
and the function where the error is which is the last part of this code
initLocations(map) {
console.log("initLocations");
let numdevices = 0;
let numcoffee = 0;
let numbattery = 0;
let numO2 = 0;
let numCapt = 0;
let numPOB = 0;
var init_popup_text = "";
var coffee_markers = new this.mapService.L.markerClusterGroup( {
iconCreateFunction: function(cluster){
var markers = cluster.getChildCount();
var c = 'coffee-marker-cluster';
return this.mapService.L.divIcon({ html: '
' +' Coffee: '+ markers + '
', className: c, iconSize: this.mapService.L.Point(40, 40) });
}} );
There is no leaflet.js inside the HTML file. The leaflet plugin is injected into Angular, Marker Cluster Groups work fine without the iconCreate function. This issue only occurs within the scope of iconCreate.
I could really use your help with a fix or work around.
using the latest stable versions from npm for leaflet and related plugins.
During runtime I get the following error:
"TypeError: Cannot read properties of undefined (reading 'L')"
The line of code it points to is:
return this.mapService.L.divIcon({ html: '
Here is the structure of the code:
MapService.ts
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
@Injectable()
export class MapService {
public L = null;
public geocoder = null;
public draw = null;
public AwesomeMarkers = null;
public markerClusterGroup = null;
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
if (isPlatformBrowser(platformId)) {
this.L = require('leaflet');
this.geocoder = require('leaflet-control-geocoder');
this.draw = require('leaflet-draw');
this.AwesomeMarkers = require('leaflet.awesome-markers');
this.markerClusterGroup = require('leaflet.markercluster');
}
}
NgModule
@NgModule({
declarations: [
AppComponent,
...COMPONENTS,
...SHARED_COMPONENTS,
...PIPES,
DeviceDetailsComponent,
DeviceListComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule.withConfig({warnOnNgModelWithFormControl: 'never'}),
HttpModule,
HttpClientModule,
NgxSpinnerModule,
BrowserAnimationsModule,
NgbModule
],
providers: [
MapService,
{provide: HTTP_INTERCEPTORS, useClass: ApiInterceptor, multi: true},
SHARED_GUARDS,
SHARED_SERVICES,
],
bootstrap: [AppComponent],
})
deviceFile
constructor(
private deviceService: DeviceService,
private loadingService: NgxSpinnerService,
private usersService: UsersService,
private authService: AuthService,
private mapService: MapService
) {}
// this.loadUsers();
}
and the function where the error is which is the last part of this code
initLocations(map) {
console.log("initLocations");
let numdevices = 0;
let numcoffee = 0;
let numbattery = 0;
let numO2 = 0;
let numCapt = 0;
let numPOB = 0;
var init_popup_text = "";
var coffee_markers = new this.mapService.L.markerClusterGroup( {
iconCreateFunction: function(cluster){
var markers = cluster.getChildCount();
var c = 'coffee-marker-cluster';
return this.mapService.L.divIcon({ html: '
}} );
There is no leaflet.js inside the HTML file. The leaflet plugin is injected into Angular, Marker Cluster Groups work fine without the iconCreate function. This issue only occurs within the scope of iconCreate.
I could really use your help with a fix or work around.
using the latest stable versions from npm for leaflet and related plugins.
as seen on stackoverflow
Thank you,
Mike
The text was updated successfully, but these errors were encountered: