我正在关注一个在线研讨会和示例,您可以在此处找到它:
https://openlayers.org/en/latest/examples/mouse-position.html
在上述链接中发布的示例中,在两个函数中
var projectionSelect = document.getElementById('projection');
projectionSelect.addEventListener('change', function (event) {
mousePositionControl.setProjection(event.target.value);//<------HERE
});
和
var precisionInput = document.getElementById('precision');
precisionInput.addEventListener('change', function (event) {
var format = createStringXY(event.target.valueAsNumber);//<------HERE
mousePositionControl.setCoordinateFormat(format);
});
分别使用了以下属性
event.target.value , event.target.valueAsNumber
但是,当我尝试在 Visual Studio 代码中运行代码时,它强调了两者
.value and .valueAsNumber
红色,表示不存在此类属性。请让我知道哪些属性可以使用,以便我可以访问包含在
event.target
代码:
ngOnInit(){
this.todaydate2 = this.myservice.showTodayDate();
this.value = this.myservice.observablesTest();
var mousePositionControl = new MousePosition({
className: 'custom-mouse-position',
coordinateFormat: createStringXY(7),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
target: document.getElementById('mouse-position'),
undefinedHTML: '',//for what to be rendered when the mouse leaves map scope: values https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition-MousePosition.html
});
this.map = new Map({
controls: defaultControls().extend([mousePositionControl]),
target: 'map-container',
layers: [
new TileLayer({
source: new XYZSource({
url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
})
})
],
view: new View({
center: fromLonLat([13.2232,52.4059]),
zoom: 6
})
});
var projectionSelect = document.getElementById('projection');
projectionSelect.addEventListener('change', function (event) {
mousePositionControl.setProjection(event.target);
});
var precisionInput = document.getElementById('precision');
precisionInput.addEventListener('change', function (event) {
var format = createStringXY(event.target);
mousePositionControl.setCoordinateFormat(format);
});
}