question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How can I use custom html elements inside <agm-circle> directive?

See original GitHub issue

I have a requirement where I need to draw a circle (with lat/long and radius of the circle) with four equal quadrants, dividing the circle into four equal halves.

Is it possible to use custom HTML elements inside <agm-circle> so using CSS, I can draw vertical and horizontal lines defining quadrants? Something like below image:

Screenshot from 2019-05-28 15-04-30

Can I do something like this:

<agm-circle *ngFor="let circle of circles" [latitude]="circle.lat" [longitude]="circle.lng" [radius]="circle.radius"
    [fillColor]="circle.color" [circleDraggable]="true" [editable]="true">
    <div class="quadrants">
      <div class="vertical"></div>
      <div class="horizontal"></div>
    </div>
  </agm-circle>

Using Angular CLI 7 and AGM@1.0.0-beta.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 3, 2019

Ok, this time I tested and it works.

Basically two mistakes were that Math.cos accepts radians, not degrees, and the entire radius length should be the start of the line, and not half.

  meterToLng(radius: number, lat: number): number {
    return radius /( 111111 * Math.cos(lat * Math.PI / 180));
  }
  meterToLat(radius: number): number {
    return radius / 111111;
  }
<ng-container *ngFor="let circle of circles" >
  <agm-circle [latitude]="circle.lat" [longitude]="circle.lng" [radius]="circle.radius" [fillColor]="circle.color" [circleDraggable]="true" [editable]="true">
  </agm-circle>
  <agm-polyline>
    <agm-polyline-point [latitude]="circle.lat" [longitude]="circle.lng - meterToLng(circle.radius, circle.lat)"> 
    </agm-polyline-point>
    <agm-polyline-point [latitude]="circle.lat" [longitude]="circle.lng + meterToLng(circle.radius, circle.lat)"> 
    </agm-polyline-point>
  </agm-polyline>
  <agm-polyline>
    <agm-polyline-point [latitude]="circle.lat - meterToLat(circle.radius, circle.lng)" [longitude]="circle.lng"> 
    </agm-polyline-point>
    <agm-polyline-point [latitude]="circle.lat + meterToLat(circle.radius, circle.lng)" [longitude]="circle.lng"> 
    </agm-polyline-point>
  </agm-polyline>
</ng-container>

image

0reactions
faizansaiyedcommented, Jun 4, 2019

Thanks a lot, savior! One more little help? My circle is editable, so if I change the radius of the circle, it should update the polylines. How can I do that? Currently, polylines do not update if I update radius, but if I change the center point, it works well.

I did this:

<agm-circle [latitude]="circle.lat" [longitude]="circle.lng" [radius]="circle.radius" [fillColor]="circle.color" circleDraggable]="false" [editable]="true" (radiusChange)="updateCircle($event, i)" (centerChange)="updateQuadrants($event, i)"></agm-circle>

and

updateQuadrants(event, index) {
  this.circles[index].lat = event.lat;
  this.circles[index].lng = event.lng;
}

updateCircle(event, index) {
  this.circles[index].radius = event;
}

With centerChange event, lines are getting updated, but not with radiusChange event: screen-capture

Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question] How can I use custom html elements inside <agm ...
[Question] How can I use custom html elements inside <agm-circle> directive? #1638. Closed. faizansaiyed opened this issue on May 28, ...
Read more >
Using custom elements - Web Components | MDN
Customized built-in elements inherit from basic HTML elements. To create one of these, you have to specify which element they extend (as ...
Read more >
How to add html to a agm-marker in angular 2? - Stack Overflow
I don't know agm and angular, but with the standard tools Html/js you can do it relative simple. 1.) Get 2 coordinates from...
Read more >
Custom Elements (V1) | Can I use... Support tables for HTML5 ...
Custom Elements (V1). - LS. One of the key features of the Web Components system, custom elements allow new HTML tags to be...
Read more >
Creating a Custom Directive • Angular - codecraft.tv
We use Dependency Injection (DI) to inject the renderer into our directives constructor. 2, Instead of setting the background color directly via the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found