Skip to content

Commit

Permalink
emit selected feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JLSchaap committed Jan 3, 2025
1 parent dbe971a commit 2668366
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 11 additions & 4 deletions viewer/src/app/location-search/location-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { SearchOptionsComponent } from './search-options/search-options.componen
import { FeatureCollectionJsonfg, FeatureJsonfg } from '../api/models'
import { Search$Json$Params } from '../api/fn/features/search-json'
import { Observable } from 'rxjs'
import { FeatureLike } from 'ol/Feature'
import { GeoJSON } from 'ol/format'

@Component({
selector: 'app-location-search',
Expand All @@ -23,7 +25,7 @@ import { Observable } from 'rxjs'
})
export class LocationSearchComponent {
selectedResultUrl: string | undefined = undefined
@Output() activeFeature = new EventEmitter<FeatureJsonfg>()
@Output() activeFeature = new EventEmitter<FeatureLike>()

@Input() url: string | undefined = undefined
@Input() label: string = 'Search location'
Expand Down Expand Up @@ -67,9 +69,14 @@ export class LocationSearchComponent {
}

selectResult(item: FeatureJsonfg) {
this.logger.log('lookup via link to api: ')
this.logger.log(item)
this.activeFeature.emit(item)
//this.logger.log('lookup via link to api: ')
//this.logger.log(item)
const geoJsonFormat = new GeoJSON()

// Read the GeoJSON data and create an OpenLayers feature
const feature = geoJsonFormat.readFeature(item) //, { featureProjection: 'EPSG:3857'}//

this.activeFeature.emit(feature)
//if (item.links![0].href) {
// this.selectedResultUrl = item.links![0].href as string
//e.g: this.selectedResultUrl =
Expand Down
9 changes: 7 additions & 2 deletions viewer/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
<!-- Link to external JavaScript -->
</head>

<body>
<body onload="load()">
<h2>Location API sample to test <a href="https://api.pdok.nl/bzk/location-api/autocomplete/v1-preprod">location api (preprod)</a></h2>

<app-location-search
id="locationsearch"
url="https://api.pdok.nl/bzk/location-api/autocomplete/v1-preprod"
label=""
aria-label="Location Search"></app-location-search>

<div>
<app-objectinfo-view id="objectinfooutside"> </app-objectinfo-view>
</div>

</body>
<script type="text/javascript">
function load() {
locatoinsearch.addEventListener('activeFeature', e => {
locationsearch.addEventListener('activeFeature', e => {
console.log('activeFeature')
console.log(JSON.stringify(e.detail))
objectinfooutside.feature = e.detail
Expand Down

0 comments on commit 2668366

Please sign in to comment.