here-api - 从 Here.js 开始创建新的 MapView 获取 TypeError
问题描述
我正在尝试使用 harp.gl 并使用以下教程。教程:https ://developer.here.com/tutorials/harpgl/ 但我收到以下错误。
MapView.ts:919 Uncaught TypeError: Cannot read property 'addEventListener' of null
at new MapView (MapView.ts:919)
at JavaScript.js:2
解决方案
您尝试在https://developer.here.com/tutorials/harpgl/上使用教程的方法 2 我做了相同的教程方法 2 并在文件 index.ts 中实现了 mapView.addEventListener,因为您可以看到包含我的内容index.ts 如下:
/*
* Copyright (C) 2017-2019 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { GeoCoordinates } from "@here/harp-geoutils";
import { View } from "./View";
import { MapViewEventNames } from "@here/harp-mapview";
const app = new View({
canvas: document.getElementById("map") as HTMLCanvasElement
});
const mapView = app.mapView;
const options = { tilt: 45, distance: 3000 };
const coordinates = new GeoCoordinates(1.278676, 103.850216);
let azimuth = 300;
mapView.addEventListener(MapViewEventNames.Render, () => {
mapView.lookAt(coordinates, options.distance, options.tilt, (azimuth += 0.1))
});
mapView.beginAnimation();
// make map full-screen
mapView.resize(window.innerWidth, window.innerHeight);
// react on resize events from the browser.
window.addEventListener("resize", () => {
mapView.resize(window.innerWidth, window.innerHeight);
});
// center the camera to New York
mapView.lookAt(new GeoCoordinates(40.70398928, -74.01319808), 1500, 40, 0);
// make sure the map is rendered
mapView.update();
此代码和 mapView.addEventListener对我正常工作,没有任何错误。
请检查您的硬件、操作系统、浏览器版本。
请在您的设备和其他设备上测试http://harp.gl.s3-website-us-east-1.amazonaws.com/docs/master/examples/上的所有示例。
推荐阅读
- r - LpSolve R 条件约束
- .htaccess - 一个htaccess用于多个域,重定向问题
- python - 在 Python 中运行雪花查询
- python-3.x - 外星人字典 Python
- javascript - 如何向具有特定角色的每个人发送私人消息?不和谐.js
- msal - How to implement IMultipleAccountPublicClientApplication in a app requiring multiple calls to secure APIs
- javascript - 收集器出错 | 不和谐.js
- html - 引导程序 | 你应该什么时候使用
超过
- node.js - puppeteer - how to intercept requests and responses only from a certain url in nodejs
- javascript - 带有 preventDefault 的简单表单不起作用(没有任何 jquery)