-1

我正在尝试使用 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
4

1 回答 1

0

您尝试在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/上的所有示例。

于 2020-03-09T14:44:00.687 回答