|
| 1 | +import { Directive, Input, OnInit } from '@angular/core'; |
| 2 | +import { SymbolPath } from '../services/google-maps-types'; |
| 3 | + |
| 4 | +/** |
| 5 | + * AgmPolylineIcon enables to add polyline sequences to add arrows, circle, |
| 6 | + * or custom icons either along the entire line, or in a specific part of it. |
| 7 | + * See https://developers.google.com/maps/documentation/javascript/shapes#polyline_customize |
| 8 | + * |
| 9 | + * ### Example |
| 10 | + * ```html |
| 11 | + * <agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom"> |
| 12 | + * <agm-polyline> |
| 13 | + * <agm-icon-sequence [fixedRotation]="true" [path]="'FORWARD_OPEN_ARROW'"> |
| 14 | + * </agm-icon-sequence> |
| 15 | + * </agm-polyline> |
| 16 | + * </agm-map> |
| 17 | + * ``` |
| 18 | + * |
| 19 | + * @export |
| 20 | + * @class AgmPolylineIcon |
| 21 | + */ |
| 22 | +@Directive({selector: 'agm-polyline agm-icon-sequence'}) |
| 23 | +export class AgmPolylineIcon implements OnInit{ |
| 24 | + |
| 25 | + /** |
| 26 | + * If `true`, each icon in the sequence has the same fixed rotation regardless of the |
| 27 | + * angle of the edge on which it lies. Defaults to `false`, in which case each icon |
| 28 | + * in the sequence is rotated to align with its edge. |
| 29 | + * |
| 30 | + * @type {boolean} |
| 31 | + * @memberof AgmPolylineIcon |
| 32 | + */ |
| 33 | + @Input() fixedRotation: boolean; |
| 34 | + |
| 35 | + /** |
| 36 | + * The distance from the start of the line at which an icon is to be rendered. This |
| 37 | + * distance may be expressed as a percentage of line's length (e.g. '50%') or in pixels |
| 38 | + * (e.g. '50px'). Defaults to '100%'. |
| 39 | + * |
| 40 | + * @type {string} |
| 41 | + * @memberof AgmPolylineIcon |
| 42 | + */ |
| 43 | + @Input() offset: string; |
| 44 | + |
| 45 | + /** |
| 46 | + * The distance between consecutive icons on the line. This distance may be expressed as |
| 47 | + * a percentage of the line's length (e.g. '50%') or in pixels (e.g. '50px'). To disable |
| 48 | + * repeating of the icon, specify '0'. Defaults to '0'. |
| 49 | + * |
| 50 | + * @type {string} |
| 51 | + * @memberof AgmPolylineIcon |
| 52 | + */ |
| 53 | + @Input() repeat: string; |
| 54 | + |
| 55 | + /** |
| 56 | + * The x coordinate of the position of the symbol relative to the polyline. The coordinate |
| 57 | + * of the symbol's path is translated _left_ by the anchor's x coordinate. By default, a |
| 58 | + * symbol is anchored at (0, 0). The position is expressed in the same coordinate system as the |
| 59 | + * symbol's path. |
| 60 | + * |
| 61 | + * @type {number} |
| 62 | + * @memberof AgmPolylineIcon |
| 63 | + */ |
| 64 | + @Input() anchorX: number; |
| 65 | + |
| 66 | + /** |
| 67 | + * The y coordinate of the position of the symbol relative to the polyline. The coordinate |
| 68 | + * of the symbol's path is translated _up_ by the anchor's y coordinate. By default, a |
| 69 | + * symbol is anchored at (0, 0). The position is expressed in the same coordinate system as the |
| 70 | + * symbol's path. |
| 71 | + * |
| 72 | + * @type {number} |
| 73 | + * @memberof AgmPolylineIcon |
| 74 | + */ |
| 75 | + @Input() anchorY: number; |
| 76 | + |
| 77 | + /** |
| 78 | + * The symbol's fill color. All CSS3 colors are supported except for extended named |
| 79 | + * colors. Defaults to the stroke color of the corresponding polyline. |
| 80 | + * |
| 81 | + * @type {string} |
| 82 | + * @memberof AgmPolylineIcon |
| 83 | + */ |
| 84 | + @Input() fillColor: string; |
| 85 | + |
| 86 | + /** |
| 87 | + * The symbol's fill opacity. Defaults to 0. |
| 88 | + */ |
| 89 | + @Input() fillOpacity: number; |
| 90 | + |
| 91 | + /** |
| 92 | + * The symbol's path, which is a built-in symbol path, or a custom path expressed using |
| 93 | + * SVG path notation. Required. |
| 94 | + * |
| 95 | + * @type {SymbolPath} |
| 96 | + * @memberof AgmPolylineIcon |
| 97 | + */ |
| 98 | + @Input() path: 'CIRCLE'|'BACKWARD_CLOSED_ARROW'|'BACKWARD_OPEN_ARROW'|'FORWARD_CLOSED_ARROW'| |
| 99 | + 'FORWARD_OPEN_ARROW' | string; |
| 100 | + |
| 101 | + /** |
| 102 | + * The angle by which to rotate the symbol, expressed clockwise in degrees. |
| 103 | + * Defaults to 0. A symbol where `fixedRotation` is `false` is rotated relative to |
| 104 | + * the angle of the edge on which it lies. |
| 105 | + * |
| 106 | + * @type {number} |
| 107 | + * @memberof AgmPolylineIcon |
| 108 | + */ |
| 109 | + @Input() rotation: number; |
| 110 | + |
| 111 | + /** |
| 112 | + * The amount by which the symbol is scaled in size. Defaults to the stroke weight |
| 113 | + * of the polyline; after scaling, the symbol must lie inside a square 22 pixels in |
| 114 | + * size centered at the symbol's anchor. |
| 115 | + * |
| 116 | + * @type {number} |
| 117 | + * @memberof AgmPolylineIcon |
| 118 | + */ |
| 119 | + @Input() scale: number; |
| 120 | + |
| 121 | + /** |
| 122 | + * The symbol's stroke color. All CSS3 colors are supported except for extended named |
| 123 | + * colors. Defaults to the stroke color of the polyline. |
| 124 | + * |
| 125 | + * @type {string} |
| 126 | + * @memberof AgmPolylineIcon |
| 127 | + */ |
| 128 | + @Input() strokeColor: string; |
| 129 | + |
| 130 | + /** |
| 131 | + * The symbol's stroke opacity. Defaults to the stroke opacity of the polyline. |
| 132 | + * |
| 133 | + * @type {number} |
| 134 | + * @memberof AgmPolylineIcon |
| 135 | + */ |
| 136 | + @Input() strokeOpacity: number; |
| 137 | + |
| 138 | + /** |
| 139 | + * The symbol's stroke weight. Defaults to the scale of the symbol. |
| 140 | + * |
| 141 | + * @type {number} |
| 142 | + * @memberof AgmPolylineIcon |
| 143 | + */ |
| 144 | + @Input() strokeWeight: number; |
| 145 | + |
| 146 | + ngOnInit(): void { |
| 147 | + if (this.path == null) { |
| 148 | + throw new Error('Icon Sequence path is required'); |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments