Bing maps in Vue Maps component
24 Jun 202417 minutes to read
Bing Maps is a online Maps provider, owned by Microsoft. As like OSM, it provide Maps tile images based on our requests and combines those images into a single one to display Maps area.
Adding Bing Maps
The Bing Maps can be rendered using the urlTemplate property, which is based on the URL generated by the getBingUrlTemplate method in the Maps. The format of the required URL of Bing Maps varies from other online map providers. As a result, a built-in getBingUrlTemplate method has been included that returns the URL in a generic format. In the meantime, a subscription key is required for Bing Maps. The Bing Maps key can be obtained from here, then append it to the Bing Maps URL before passing it to the getBingUrlTemplate method. The URL returned by this method must be passed to the urlTemplate property.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps id='container' :layers='layers' :load='load'>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin } from '@syncfusion/ej2-vue-maps';
Vue.use(MapsPlugin);
export default {
data () {
return {
layers: [
{
}
]
}
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
Types of Bing Maps
Bing Maps provides different types of Maps and it is supported in the Maps component.
- Aerial - Displays satellite images to highlight roads and major landmarks for easy identification.
- AerialWithLabel - Displays aerial Maps with labels for the continent, country, ocean, etc.
- Road - Displays the default Maps view of roads, buildings, and geography.
- CanvasDark - Displays dark version of the road Maps.
- CanvasLight - Displays light version of the road Maps.
- CanvasGray - Displays grayscale version of the road Maps.
To render the light version of the road Maps, set the CanvasLight value is passed via the URL into the getBingUrlTemplate method demonstrated in the following code sample.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps id='container' :centerPosition="centerPosition" :layers='layers' :load='load'>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin} from '@syncfusion/ej2-vue-maps';
Vue.use(MapsPlugin);
export default {
data () {
return{
layers: [{
}],
centerPosition: {
latitude: 38.8951,
longitude: -77.0364
}
}
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/CanvasLight?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
Enabling zooming and panning
Bing Maps layer can be zoomed and panned. Zooming helps to get a closer look at a particular area on a Maps for in-depth analysis. Panning helps to move a Maps around to focus the targeted area.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps id='container' :zoomSettings='zoomSettings' :layers='layers' :load='load'>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, Zoom } from '@syncfusion/ej2-vue-maps';
Vue.use(MapsPlugin);
export default {
data () {
return{
zoomSettings: {
enable: true,
toolbarSettings:{
buttonSettings: {
toolbarItems: ['Zoom', 'ZoomIn', 'ZoomOut', 'Pan', 'Reset']
}
}
},
layers: [{
}]
}
},
provide: {
maps: [Zoom]
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
Adding markers and navigation line
Markers can be added to the layers of Bing Maps by setting the corresponding location’s coordinates of latitude and longitude using e-markerSetting tag. Navigation lines can be added on top of an Bing Maps layer for highlighting a path among various places by setting the corresponding location’s coordinates of latitude and longitude in the e-navigationLineSetting tag.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps id='container' :zoomSettings='zoomSettings' :load='load' :centerPosition= 'centerPosition'>
<e-layers>
<e-layer>
<e-markerSettings>
<e-markerSetting visible= true height=25 width=15 :dataSource ="dataSource" ></e-markerSetting>
<e-markerSetting visible= true height=25 width=15 :dataSource ="dataSource1"></e-markerSetting>
</e-markerSettings>
<e-navigationLineSettings>
<e-navigationLineSetting visible = true :latitude ='latitude' :longitude ='longitude' :color ='color' :angle ='angle' :width="width">
</e-navigationLineSetting>
</e-navigationLineSettings>
</e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, Zoom, Marker, NavigationLine } from '@syncfusion/ej2-vue-maps';
Vue.use(MapsPlugin);
export default {
data () {
return{
zoomSettings: {
zoomFactor: 4
},
centerPosition: {
latitude: 29.394708,
longitude: -94.954653
},
dataSource: [
{
latitude: 34.060620,
longitude: -118.330491,
name: "California"
}],
dataSource1: [
{
latitude: 40.724546,
longitude: -73.850344,
name: "New York"
}],
color: "blue",
width: 5,
angle: 0.1,
latitude: [34.060620, 40.724546],
longitude: [-118.330491,-73.850344]
}
},
provide: {
maps: [Zoom, Marker, NavigationLine]
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
Adding sublayer
Any GeoJSON shape can be rendered as a sublayer on top of the Bing Maps layer for highlighting a particular continent or country in Bing Maps by adding another layer and specifying the type property of Maps layer to SubLayer.
<template>
<div id="app">
<div>
<ejs-maps id='container' :layers='layers' :load='load'>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin } from '@syncfusion/ej2-vue-maps';
import { africa } from './africa.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
layers: [{
},
{
type: 'SubLayer',
shapeData: africa,
shapeSettings: {
fill: 'blue'
}
}
]
}
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
Enabling legend
The legend can be added to the tile Maps by setting the visible property of legendSettings to true.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps id='container' :legendSettings='legendSettings' :load='load'>
<e-layers>
<e-layer :shapeSettings='shapeSettings' :markerSettings='markerSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, Marker, Legend } from '@syncfusion/ej2-vue-maps';
import { markerDataSource } from './marker-data.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
legendSettings: {
visible: true,
type: 'Markers',
useMarkerShape:true,
toggleLegendSettings: {
enable: true,
applyShapeSettings: false,
border: {
color: 'green',
width: 2
}
}
},
shapeSettings: {
fill: '#E5E5E5'
},
markerSettings: [
{
colorValuePath: 'color',
shapeValuePath:'shape',
legendText: 'country',
visible: true,
dataSource: markerDataSource
}
]
}
},
provide: {
maps: [Legend, Marker]
},
methods:{
load: function (args) {
let map=document.getElementById('container');
map.ej2_instances[0].getBingUrlTemplate("https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Aerial?output=json&uriScheme=https&key=?").then(function(url) {
map.ej2_instances[0].layers[0].urlTemplate= url;
});
}
}
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>