我正在尝试使用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我按照教程method2进行了同样的操作,并在文件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/上的所有示例。