|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { Feature as OlFeature, format, geom } from 'openlayers'; |
| 3 | + |
| 4 | +@Component({ |
| 5 | + selector: 'app-display-overlay', |
| 6 | + template: ` |
| 7 | + <aol-map #map width="100%" height="100%"> |
| 8 | + <aol-interaction-default></aol-interaction-default> |
| 9 | + <aol-control-defaults></aol-control-defaults> |
| 10 | +
|
| 11 | + <aol-view [zoom]="11"> |
| 12 | + <aol-coordinate [x]="-2.269282" [y]="46.987247" [srid]="'EPSG:4326'"></aol-coordinate> |
| 13 | + </aol-view> |
| 14 | +
|
| 15 | + <aol-layer-tile [opacity]="1"> |
| 16 | + <aol-source-osm></aol-source-osm> |
| 17 | + </aol-layer-tile> |
| 18 | +
|
| 19 | + <aol-layer-vector> |
| 20 | + <aol-source-vector> |
| 21 | + <aol-feature> |
| 22 | + <aol-geometry-polygon> |
| 23 | + <aol-collection-coordinates [coordinates]="feature.geometry.coordinates[0]" [srid]="'EPSG:4326'"></aol-collection-coordinates> |
| 24 | + </aol-geometry-polygon> |
| 25 | + </aol-feature> |
| 26 | + </aol-source-vector> |
| 27 | + </aol-layer-vector> |
| 28 | +
|
| 29 | + <aol-overlay [positioning]="'center-center'" [stopEvent]="false"> |
| 30 | + <aol-coordinate |
| 31 | + [x]="tooltip.lon" |
| 32 | + [y]="tooltip.lat" |
| 33 | + [srid]="'EPSG:4326'" |
| 34 | + > |
| 35 | + </aol-coordinate> |
| 36 | + <aol-content> |
| 37 | + <div class="tooltip tooltip-static"> |
| 38 | + {{tooltip.text}} |
| 39 | + </div> |
| 40 | + </aol-content> |
| 41 | + </aol-overlay> |
| 42 | + </aol-map> |
| 43 | + `, |
| 44 | + styles: [ |
| 45 | + ` |
| 46 | + .tooltip { |
| 47 | + margin-top: 35%; |
| 48 | + right: 50%; |
| 49 | + position: relative; |
| 50 | + border-radius: 4px; |
| 51 | + color: white; |
| 52 | + padding: 4px 8px; |
| 53 | + white-space: nowrap; |
| 54 | + } |
| 55 | +
|
| 56 | + .tooltip-static { |
| 57 | + background-color: #000000; |
| 58 | + color: white; |
| 59 | + border: 1px solid white; |
| 60 | + } |
| 61 | + `, |
| 62 | + ], |
| 63 | +}) |
| 64 | +export class OverlayComponent implements OnInit { |
| 65 | + constructor() {} |
| 66 | + |
| 67 | + geoJsonFormat = new format.GeoJSON(); |
| 68 | + |
| 69 | + feature = { |
| 70 | + type: 'Feature', |
| 71 | + properties: {}, |
| 72 | + geometry: { |
| 73 | + type: 'Polygon', |
| 74 | + coordinates: [ |
| 75 | + [ |
| 76 | + [-2.3565673828124996, 46.92588289494367], |
| 77 | + [-2.1148681640624996, 46.92588289494367], |
| 78 | + [-2.1148681640624996, 47.04954010021555], |
| 79 | + [-2.3565673828124996, 47.04954010021555], |
| 80 | + [-2.3565673828124996, 46.92588289494367], |
| 81 | + ], |
| 82 | + ], |
| 83 | + }, |
| 84 | + }; |
| 85 | + |
| 86 | + tooltip = { |
| 87 | + lon: 0, |
| 88 | + lat: 0, |
| 89 | + text: 'Lorem ipsum dolor sit amet', |
| 90 | + }; |
| 91 | + |
| 92 | + ngOnInit() { |
| 93 | + const olFeature: OlFeature = this.geoJsonFormat.readFeature(this.feature); |
| 94 | + const olGeomPolygon = geom.Polygon.fromExtent(olFeature.getGeometry().getExtent()); |
| 95 | + [, this.tooltip.lat, this.tooltip.lon] = olGeomPolygon.getExtent(); |
| 96 | + } |
| 97 | +} |
0 commit comments