Unable to Display Elevation Chart in Angular Project with leaflet-elevation
pritam-das-26 opened this issue · comments
Subject of the issue
Unable to display elevation chart using leaflet-elevation in Angular project
Your environment
- leaflet-elevation version: ^2.5.1
- leaflet version: ^1.9.3
- browser: Chrome
- operating system: Microsoft Windows 10 Pro, version 10.0.19045 Build 19045
- Angular version: ^15.1.0
Steps to reproduce
- Copy the leaflet elevation code from the leaflet elevation repository and paste it into the TypeScript file.
- Define a div element with a map in the HTML file.
- After installing the package managers, execute the following steps:
- Step 1: Copy the provided leaflet elevation code into a TypeScript file.
- Step 2: Define a div element with a map in the HTML file.
- The map is displayed successfully, but the elevation chart is missing.
- Attempted to import the elevation file in different ways, but it's not getting configured.
- Console errors are attached in the screenshot. Although I was able to reproduce the same through CDN in Angular version 17.
Expected behaviour
An elevation chart should appear on the map.
Actual behaviour
I can see the map layer, but the elevation chart is missing. The following error is observed in the console:
[webpack-dev-server] WARNING in ./node_modules/@raruto/leaflet-elevation/dist/leaflet-elevation.min.js 469:24-60
Critical dependency: the request of a dependency is an expression
these are the image of my angular.json, component.ts
Please check FAQ section and old issues:
- How can I import this library as ES module?
- https://github.com/Raruto/leaflet-elevation/issues?q=angular
Critical dependency: the request of a dependency is an expression
Ref: #280 (comment)
👋 Raruto
Thanks for the solution, I tried above hack it worked.
Solution:
-
copy the lefllet elvation module to assets in angular.
-
import the src folder and the elevation code as shown in the demo of github.
import { SessionService } from '@/controller/session.service';
import { UserRoles } from '@/interfaces/users';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr';
import { environment } from '../../../environments/environment';
import { RawImageComponent } from './raw-image/raw-image.component';
import { HttpService } from './services-map/http.service';
// @ts-ignore
import * as L from 'leaflet';
import '@/../assets/leaflet-elevation/src/index.js';
// provide the assets folder path
var elevation_options = {
theme: "green-theme",
detached: true,
elevationDiv: "#elevation-div",
autohide: false,
collapsed: false,
position: "topright",
closeBtn: true,
followMarker: true,
autofitBounds: true,
imperial: false,
reverseCoords: false,
acceleration: false,
slope: true,
speed: false,
altitude: true,
time: true,
distance: true,
summary: 'multiline',
downloadLink: false,
ruler: true,
legend: true,
almostOver: true,
distanceMarkers: false,
edgeScale: false,
hotline: true,
timestamps: false,
waypoints: true,
wptIcons: {
'': L.divIcon({
className: 'elevation-waypoint-marker',
html: '<i class="elevation-waypoint-icon"></i>',
iconSize: [30, 30],
iconAnchor: [8, 30],
}),
},
wptLabels: true,
preferCanvas: true,
srcFolder: 'http://localhost:4200/assets/leaflet-elevation/src/',
clear:true,
}
To facilitate the dynamic switching of graphs among multiple JSON datasets, the ability to update and replace the current graph with a new dataset is essential.
However, it has been observed that the controlElevation.clear()
function is not functioning as expected, yielding an "undefined"
result.
On console logging I find the following functions are exported as attached in the image.
Clear is never exported.
Please tell any solution that works with angular.
![9](https://private-user-images.githubusercontent.com/137450437/298400095-00b51792-c289-4795-bc65-405dfc3e5dee.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyNzUyMDcsIm5iZiI6MTcyMjI3NDkwNywicGF0aCI6Ii8xMzc0NTA0MzcvMjk4NDAwMDk1LTAwYjUxNzkyLWMyODktNDc5NS1iYzY1LTQwNWRmYzNlNWRlZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyOVQxNzQxNDdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05M2JkMjA5ZjA3YTA5MGRlMDI0NDg1YjEzNWZmMTcwMGIyOWFlNjA5NGY3MTg0OWQzN2U2NjllOTc3MjQxODAzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.hUOfpltP1jQMznWNV7o5HmWFpICx2cvM5IpcFDCRHYA)
the
controlElevation.clear()
function is not functioning as expected, yielding an"undefined"
result.
Without a public working demo (from your code) no one can verify this statement.
🤷 Raruto
@Raruto
Here is the link to my project you can check.
https://stackblitz.com/~/github.com/pritam-das-26/map
@Raruto
The problem got resolved.This issue can be closed.