-
-
Save pranay414/84f5fe4ed1b704c1ff34409a957c37d7 to your computer and use it in GitHub Desktop.
HERE maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/DisplayMapClass.js | |
import * as React from 'react'; | |
export class DisplayMapClass extends React.Component { | |
mapRef = React.createRef(); | |
state = { | |
// The map instance to use during cleanup | |
map: null | |
}; | |
componentDidMount() { | |
const H = window.H; | |
const platform = new H.service.Platform({ | |
apikey: "e-Tuzu0QOkZ12AgFa_8XXmUYCbl5sxM0b20S1gx8918" | |
}); | |
const defaultLayers = platform.createDefaultLayers(); | |
// Create an instance of the map | |
const map = new H.Map( | |
this.mapRef.current, | |
defaultLayers.vector.normal.map, | |
{ | |
// This map is centered over Europe | |
center: { lat: 50, lng: 5 }, | |
zoom: 4, | |
pixelRatio: window.devicePixelRatio || 1 | |
} | |
); | |
// MapEvents enables the event system | |
// Behavior implements default interactions for pan/zoom (also on mobile touch environments) | |
// This variable is unused and is present for explanatory purposes | |
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map)); | |
// Create the default UI components to allow the user to interact with them | |
// This variable is unused | |
const ui = H.ui.UI.createDefault(map, defaultLayers); | |
// Add map controls | |
H.ui.ZoomControl(); | |
this.setState({ map }); | |
} | |
componentWillUnmount() { | |
// Cleanup after the map to avoid memory leaks when this component exits the page | |
this.state.map.dispose(); | |
} | |
render() { | |
return ( | |
// Set a height on the map so it will display | |
<div ref={this.mapRef} style={{ height: "500px" }} /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment