VectorSDK Map Animated Polyline

by mapmyindia_map

HTML

<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

<script src="https://apis.mapmyindia.com/advancedmaps/api/<Token or Key>/map_sdk?layer=vector&v=2.0"></script>

<div id="main">
  <section id="left-menu">
    <center><h4>Map Animated PolyLine</h4></center>
    <!-- Draw PolyLine -->
    <div id="flip1">
      <div id="panel1">
        <span class="texlable">Path True/False</span>       
        <select name="label" id="path_option" class="form-control b-shadow">
          <option disabled>Select</option>
          <option value="true" selected>True</option>
          <option value="false">False</option>
        </select>            
        <span class="texlable">Speed</span>
        <input type="text" id="speed" value="10" placeholder="Enter Speed" class="form-control b-shadow">
        <span class="texlable">strokeColor</span>
        <input type="text" id="strokecolor" value="blue" placeholder="Enter strokeColor" class="form-control b-shadow">
        <span class="texlable">strokeOpacity</span>
        <input type="text" id="strokeopacity" value="1.0" placeholder="Enter strokeOpacity" class="form-control b-shadow">
        <span class="texlable">strokeWeight</span>
        <input type="text" id="strokeweight" value="9" placeholder="Enter strokeWeight" class="form-control b-shadow">
        <span class="texlable">lineGap</span>
        <input type="text" id="linegap" value="0" placeholder="Enter lineGap" class="form-control b-shadow">
        <span class="texlable">PopupHtml</span>
        <input type="text" id="poly_popuphtml" value="Route 1" placeholder="Enter popuphtml" class="form-control b-shadow">
        <span class="texlable">Fitbound</span>
        <select name="label" id="poly_fitbounds" class="form-control b-shadow">
          <option...

CSS

#main{
  width: 100%;
  height: 100%;
  background-color: gray;
}
#left-menu{
  width: 230px;
  height: 100%;
  background-color:  #e0e0e0;
  float: left;
  overflow: auto;
}
#right-menu{
  width: calc(100% - 230px);
  height: 100vh;
  float: left;
  position:fixed;
  right:0;
}
/* Switch checkbox */
.switch {
  position: relative;
  display: inline-block;
  width: 55px;
  height: 28px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}
input:checked+.slider {
  background-color: #2196F3;
}

input:focus+.slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked+.slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

@media only screen and (max-width: 600px) {
  #left-menu {
    -webkit-transition: height 0.2s;
    transition: height 0.2s;
    width: 100%;
    height: 30%;
    background-color:  #e0e0e0;
    position: absolute;
    bottom: 0%;
    z-index: 2;
    overflow: auto;
  }
  #right-menu{
    width: 100%;
    height: 70%;
    position: absolute;
    z-index: 1;
  }
  #l1,#cl1{
    display:none;
  }

}

#flip1
{
  color: #3c3c3c;
  font-size: 20px;
  background-color: #f3f3f3;
  padding: 6px 0px;
  margin-bottom: 3px;
  margin-left: 6px;
  margin-right: 6px;
  border-radius: 6px;	

}
#panel1{
  padding:5px 10px 0px;
  display: block;
}

::-webkit-scrollbar {
  width: 5px;
  display: none;
}

.form-control.b-shadow {
  -moz-box-shadow:    inset 0 0 5px lightgray;
  -webkit-box-shadow: inset 0 0 5px lightgray;
 ...

JavaScript

var map1;
var center = "28.5507160000001,77.2689280000001";
var center = center.split(",");
var lat = center[0];var lng=center[1];
var pl;
// Draw Animated Polyline
document.getElementById('checkbox').addEventListener('change', (event) => {
  if (event.target.checked) {
    // call Animated polyline function
    animated_polyline();
  } 
  else {
    map1.setZoom(4);
    MapmyIndia.remove({map:map1,layer:pl});
    map1.setCenter({lat: lat, lng: lng});
  }
});

// Map Function
function initMap1() {
  var center = {lat: lat, lng: lng};
  map1 = new MapmyIndia.Map(document.getElementById('right-menu'), 
                            {
    center: center,
    zoomControl: true,
    location: true,
  });
}
// Animated polyline function
function animated_polyline(){
  var strokecolor=  document.getElementById('strokecolor').value;
  var strokeopacity=  document.getElementById('strokeopacity').value;
  var strokeweight=  document.getElementById('strokeweight').value;
  var poly_position=  document.getElementById('poly_position').value;
  var polyline_events=  document.getElementById('polyline_events').value;
  var linegap=  document.getElementById('linegap').value;
  var poly_fitbounds=  document.getElementById('poly_fitbounds').value;
  var poly_popuphtml =  document.getElementById('poly_popuphtml').value;
  var path_option = document.getElementById('path_option').value;
  var speed = document.getElementById('speed').value;

  pl = new MapmyIndia.Polyline({
    map:map1,
    path: eval(poly_position),
    animate:{
      path:JSON.parse(path_option),
      speed:JSON.parse(speed),
    },
    strokeColor: strokecolor,
    strokeOpacity: JSON.parse(strokeopacity),
    strokeWeight: JSON.parse(strokeweight),
    fitbounds:JSON.parse(poly_fitbounds),
    lineGap:JSON.parse(linegap),
    fitboundOptions:{padding: 120,duration:1000},
    popupHtml:poly_popuphtml,
    popupOptions:{offset: {'bottom': [0, -20]}}
  }); 
  // Animated Polyline Events
 ...