【发布时间】:2021-03-26 08:55:58
【问题描述】:
我正在关注一个在线研讨会和示例,您可以在这里找到它:
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);
});
}
【问题讨论】:
-
“这意味着不存在这样的属性” - 不完全是。这意味着 VS Code 的 Linter 找不到任何对它的引用。您可以通过使用正确类型转换对象来启用它。
-
你不能只是 console.log(event) 并在浏览器控制台中查看你的输出吗?在那里你可以看到你可以访问哪些变量。这可能不是独立于浏览器的,但可以为您提供一个好的起点?
标签: javascript node.js angular openlayers angular-openlayers