MapView initialization sequence enables setting all the necessary elements on a map and returns
a MapView object. Looking at the function's definition:
functioninitializeMapView(id: string): MapView{
it can be seen that it accepts a string which holds an id of a DOM element to initialize the
map canvas within.
During the initialization, canvas element with a given id is searched for first. Than a
MapView object is created and set to initial values of camera settings and map's geo center.
As a map needs controls to allow any interaction with the user (e.g. panning), a MapControls
object is created.
By default the map is looking at Berlin. For this example we want to look at New York from a
nice angle and distance.
Finally the map is being resized to fill the whole screen and a listener for a "resize" event is
added, which enables adjusting the map's size to the browser's window size changes.
At the end of the initialization a MapView object is returned. To show map tiles an exemplary
datasource is used, VectorTileDataSource:
After creating a specific datasource it needs to be added to the map in order to be seen.
MapView initialization sequence enables setting all the necessary elements on a map and returns a MapView object. Looking at the function's definition:
function initializeMapView(id: string): MapView {
it can be seen that it accepts a string which holds an
id
of a DOM element to initialize the map canvas within.During the initialization, canvas element with a given
id
is searched for first. Than a MapView object is created and set to initial values of camera settings and map's geo center.As a map needs controls to allow any interaction with the user (e.g. panning), a MapControls object is created.
By default the map is looking at Berlin. For this example we want to look at New York from a nice angle and distance.
Finally the map is being resized to fill the whole screen and a listener for a "resize" event is added, which enables adjusting the map's size to the browser's window size changes.
At the end of the initialization a MapView object is returned. To show map tiles an exemplary datasource is used, VectorTileDataSource:
After creating a specific datasource it needs to be added to the map in order to be seen.