VectorSDK Map InfoWindow
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 InfoWindow</h4></center>
<div id="flip1">
<div id="panel1">
<span class="texlable">Class</span><span><sup style="font-size:10px; margin-left:3px; color:green;">optional</sup></span>
<input type="text" id="info_class" value="class" placeholder="Enter Class" class="form-control b-shadow">
<span class="texlable">Position</span>
<input type="text" id="info_position" value='{"lng":"77.2689280000001","lat":"28.5507160000001"}' placeholder="Enter Position" class="form-control b-shadow">
<span class="texlable">Offset</span>
<input type="text" id="offset" value='[0,10]' placeholder="Enter Position" class="form-control b-shadow">
<span class="texlable">Anchor</span>
<select name="label" id="anchor" class="form-control b-shadow">
<option value="center" selected>Center</option>
<option value="top">Top</option>
<option value="bottom">bottom</option>
<option value="left">Left</option>
<option value="right">Right</option>
<option value="top-left">Top-left</option>
<option value="top-right">Top-right</option>
<option value="bottom-left">Bottom-left</option>
<option value="bottom-right">Bottom-right</option>
</select>
<span class="texlable">CloseButton</span>
<select name="label" id="closeButton" class="form-control b-shadow">
<option value="true" selected>True</option>
<option value="false">False</option>
</select>
...
CSS
#main{
width: 100%;
height: 100%;
background-color: gray;
}
#left-menu{
width: 230px;
height: 100vh;
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 pp;
var center = "28.5507160000001,77.2689280000001";
var center = center.split(",");
var lat = center[0];var lng=center[1];
var info_class = document.getElementById('info_class').value;
var info_position = document.getElementById('info_position').value;
var info_setcontent = document.getElementById('info_setcontent').value;
var info_maxwidth = document.getElementById('info_maxwidth').value;
var offset = document.getElementById('offset').value;
var anchor = document.getElementById('anchor').value;
var closeButton = document.getElementById('closeButton').value;
var closeOnClick = document.getElementById('closeOnClick').value;
// InfoWindow
document.getElementById('checkbox').addEventListener('change', (event) => {
if (event.target.checked) {
MapmyIndia.remove({map:map1,layer:pp});
info();
}
else{
MapmyIndia.remove({map:map1,layer:pp});
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,
});
info();
}
function info(){
info_class = document.getElementById('info_class').value;
info_position = document.getElementById('info_position').value;
info_setcontent = document.getElementById('info_setcontent').value;
info_maxwidth = document.getElementById('info_maxwidth').value;
offset = document.getElementById('offset').value;
anchor = document.getElementById('anchor').value;
closeButton = document.getElementById('closeButton').value;
closeOnClick = document.getElementById('closeOnClick').value;
/// Infowindow
pp=new MapmyIndia.InfoWindow({
position:JSON.parse(info_position),
class:info_class,
map:map1,
content:info_setcontent,
offset:eval(offset),
anchor:anchor,
closeButton:JSON.parse(info_position),
closeOnClick:JSON.parse(info_position),
...