如何解决Angular项目中的OpenLayers自定义控件
我想在Angular项目中使用OpenLayers Control
基类创建自己的自定义控件。
我有一个看起来像这样的组件:
control.component.ts
import { Component,OnInit,Host } from '@angular/core';
import { MapService } from '../map.service';
import { MapidService } from '../mapid.service';
import { Map } from 'ol';
import MyCustomControl from '../somewhere/my-custom-control';
@Component({
selector: 'app-control',templateUrl: './control.component.html',styleUrls: ['./control.component.css']
})
export class ControlComponent implements OnInit {
constructor(
private mapService: MapService,@Host()
private mapidService: MapidService) { }
ngOnInit(): void {
// Get the current map
const map: Map = this.mapService.getMap(this.mapidService.getId());
const control = new MyCustomControl({});
map.addControl(control);
}
}
我想为自定义组件创建一个类,但是,这是我第一次在Angular项目中执行此操作(这意味着,使用ng g class mycustomclass
创建一个不是组件的类) ,我真的不知道哪种方法是最好的方法。
我的疑问尤其是:
- 该新课程应该放在哪个文件夹中?
- 如果我用类似的内容声明新类,就可以了
export class MyCustomControl extends Control {
constructor() {
super({});
...
}
}
在Angular中(我曾经在“普通的” TypeScript项目中这样做),还是有更好的方法(另一个组件)?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。