Explore our entire suite of APIs & SDKs
SDKs for maps and traffic
APIs for search and discovery
APIs to solve complex routing problems
Connected embedded navigation
SDK to enable live location in your apps
Maps, search, routes for 238 nations
Hyperlocal, personalised O2O marketing
Route planning & optimisation
GeoBI meets Location AI
Field force automation APIs
Embed maps, navigation in your apps
Hybrid navgation for embedded systems
Intelligent mobility platform for PV, CV, EV
Offline navigation maps and app
Super app for maps, safety, and more
Connected embedded navigation
Connected embedded navigation
Convert movement data to traffic analytics
SDKs for maps and traffic
Hyperlocal, personalised O2O marketing
APIs for search and discovery
APIs to solve complex routing problems
Connected embedded navigation
Route planning & optimisation
APIs for 360° panoramic images
SDKs for maps and traffic
Hyperlocal, personalised O2O marketing
APIs for search and discovery
APIs to solve complex routing problems
Connected embedded navigation
Route planning & optimisation
APIs for 360° panoramic images
Bring and search with your data
SDKs for maps and traffic
Hyperlocal, personalised O2O marketing
APIs for search and discovery
APIs to solve complex routing problems
Connected embedded navigation
Route planning & optimisation
APIs for 360° panoramic images
Bring and search with your data
SDKs for maps and traffic
Hyperlocal, personalised O2O marketing
APIs for search and discovery
APIs to solve complex routing problems
Connected embedded navigation
Route planning & optimisation
APIs for 360° panoramic images
Bring and search with your data
Bezier Curve Polyline
/* First install : npm install mappls-web-maps */
import { Component, OnInit, ElementRef } from '@angular/core';
import { mappls } from 'mappls-web-maps';
@Component({
selector: 'app-root',
template: '',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
mapObject: any;
mapplsClassObject = new mappls();
title = "Bezier Curve Polyline";
polylineObj : any;
mapProps = { center: [28.6330, 77.2194], traffic: false, zoom: 4, geolocation: false, clickableIcons: false }
curveLine = (p:any, call:any) : any => {
var strt : any, end, ang = 45;
if (p.start != undefined) { strt = p.start }
if (p.end != undefined) { end = p.end }
if (p.angle != undefined) { ang = p.angle };
if (ang > 45) { console.log("Angle should be less than 45."); return false; }
if (!strt || !end) { console.log("Start and End point required."); return false; }
var st_lat = strt.lat, st_lng = strt.lng, end_lat = end.lat, end_lng = end.lng, fx = 1, fy = ang < 45 ? 0.8 : 1, points : any = [], path : any = [], resolution = 0.01;
var bearing1 = this.bearing(st_lat, st_lng, end_lat, end_lng);
bearing1 = bearing1 > 180 ? bearing1 + ang : bearing1 - ang;
var dia = this.distance(st_lat, st_lng, end_lat, end_lng) * fx;
var hyp = Math.sqrt(2) * ((dia * fy) / 2);
var pos = this.destinationpoint(strt, bearing1, hyp);
var mid_lat = pos.lat, mid_lng = pos.lng;
for (var it = 0; it <= 1; it += resolution) { points.push(this.getBezier({ x: st_lat, y: st_lng, }, { x: mid_lat, y: mid_lng, }, { x: end_lat, y: end_lng, }, it)); }
for (var i = 0; i < points.length - 1; i++) {
path.push({ lat: points[i].x, lng: points[i].y });
};
setTimeout(() => {
path.push(strt);
return call(path);
}, 100);
}
B1 = function (t:any) : any { return t * t; }
B2 = function (t:any) : any { return 2 * (1 - t) * t; }
B3 = function (t:any) : any { return (1 - t) * (1 - t); }
getBezier = (C1 : any, C2 : any, C3 : any, percent : any) => {
var pos : any = [];
pos.x = C1.x * this.B1(percent) + C2.x * this.B2(percent) + C3.x * this.B3(percent);
pos.y = C1.y * this.B1(percent) + C2.y * this.B2(percent) + C3.y * this.B3(percent);
return pos;
}
distance = (lat1 : any, lon1 : any, lat2 : any, lon2 : any) => {
const R = 6378137; // metres
const φ1 = (lat1 * Math.PI) / 180; // φ, λ in radians
const φ2 = (lat2 * Math.PI) / 180;
const Δφ = ((lat2 - lat1) * Math.PI) / 180;
const Δλ = ((lon2 - lon1) * Math.PI) / 180;
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // in metres
return d;
}
bearing = (λ1 : any, φ1 : any, λ2 : any, φ2 : any) => {
const lat1 = (λ1 * Math.PI) / 180;
const lat2 = (λ2 * Math.PI) / 180;
const dLon = (φ2 - φ1) * (Math.PI / 180);
const y = Math.sin(dLon) * Math.cos(lat2);
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
const brng = Math.atan2(y, x);
return (brng * (180 / Math.PI) + 360) % 360;
}
destinationpoint = (point : any, brng : any, dist : any) => {
dist = dist / 6378137;
brng = brng * Math.PI / 180;
var lat1 = point.lat * Math.PI / 180, lon1 = point.lng * Math.PI / 180;
var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
return { lat: lat2 * 180 / Math.PI, lng: lon2 * 180 / Math.PI };
}
ngOnInit() {
this.mapplsClassObject.map({ id: "map", key:"", properties: this.mapProps}, (data: any)=>{
this.mapObject = data //callback function return map object
this.curveLine({
start: { lng: 77.27428863526279, lat: 28.550908438470714 },
end: { lng: 77.53557294755876, lat: 28.660477852756003 },
angle: 30 // less than 45 degree
}, (data:any) => {
if (this.polylineObj) this.mapplsClassObject.removeLayer({ map: this.mapObject, layer: this.polylineObj });
this.polylineObj = this.mapplsClassObject.Polyline({
map: this.mapObject,
path: data,
strokeColor: "#333",
strokeOpacity: 1.0,
strokeWeight: 2,
fitbounds: true,
});
});
});
}
}
/* First install : npm install mappls-web-maps */
import { mappls } from 'mappls-web-maps';
import './App.css';
function App() {
const styleMap = {width: '99%', height: '99vh', display:'inline-block'}
var mapObject ;
var mapplsClassObject= new mappls();
const title = "Bezier Curve Polyline";
const mapProps = { center: [28.544, 77.2454] };
mapplsClassObject.map(
{
id: "map",
key: "",
properties: mapProps,
},
(data) => {
const mapObject = data;
const curveLine = (p, call)=> {
var strt,
end,
ang = 45;
if (p.start != undefined) {
strt = p.start;
}
if (p.end != undefined) {
end = p.end;
}
if (p.angle != undefined) {
ang = p.angle;
}
if (ang > 45) {
console.log("Angle should be less than 45.");
return false;
}
if (!strt || !end) {
console.log("Start and End point required.");
return false;
}
var st_lat = strt.lat,
st_lng = strt.lng,
end_lat = end.lat,
end_lng = end.lng,
fx = 1,
fy = ang < 45 ? 0.8 : 1,
points = [],
path = [],
resolution = 0.01;
var bearing1 = bearing(st_lat, st_lng, end_lat, end_lng);
bearing1 = bearing1 > 180 ? bearing1 + ang : bearing1 - ang;
var dia = distance(st_lat, st_lng, end_lat, end_lng) * fx;
var hyp = Math.sqrt(2) * ((dia * fy) / 2);
var pos = destinationpoint(strt, bearing1, hyp);
var mid_lat = pos.lat,
mid_lng = pos.lng;
for (let it = 0; it <= 1; it += resolution) {
points.push(
getBezier(
{ x: st_lat, y: st_lng },
{ x: mid_lat, y: mid_lng },
{ x: end_lat, y: end_lng },
it
)
);
}
for (var i = 0; i < points.length - 1; i++) {
path.push({ lat: points[i].x, lng: points[i].y });
}
setTimeout(() => {
path.push(strt);
return call(path);
}, 100);
};
const B1 = (t)=> {
return t * t;
};
const B2 = (t)=> {
return 2 * (1 - t) * t;
};
const B3 = (t)=> {
return (1 - t) * (1 - t);
};
const getBezier = (C1, C2, C3, percent)=> {
var pos = {};
pos.x = C1.x * B1(percent) + C2.x * B2(percent) + C3.x * B3(percent);
pos.y = C1.y * B1(percent) + C2.y * B2(percent) + C3.y * B3(percent);
return pos;
}
const distance = (lat1, lon1, lat2, lon2)=> {
const R = 6378137; // metres
const φ1 = (lat1 * Math.PI) / 180; // φ, λ in radians
const φ2 = (lat2 * Math.PI) / 180;
const Δφ = ((lat2 - lat1) * Math.PI) / 180;
const Δλ = ((lon2 - lon1) * Math.PI) / 180;
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // in metres
return d;
}
const bearing = (λ1, φ1, λ2, φ2)=> {
const lat1 = (λ1 * Math.PI) / 180;
const lat2 = (λ2 * Math.PI) / 180;
const dLon = (φ2 - φ1) * (Math.PI / 180);
const y = Math.sin(dLon) * Math.cos(lat2);
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
const brng = Math.atan2(y, x);
return (brng * (180 / Math.PI) + 360) % 360;
}
const destinationpoint = (point, brng, dist)=> {
dist = dist / 6378137;
brng = brng * Math.PI / 180;
var lat1 = point.lat * Math.PI / 180, lon1 = point.lng * Math.PI / 180;
var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
return { lat: lat2 * 180 / Math.PI, lng: lon2 * 180 / Math.PI };
}
mapObject.addListener('load',()=> {
curveLine({
start: { lng: 77.27428863526279, lat: 28.550908438470714 },
end: { lng: 77.53557294755876, lat: 28.660477852756003 },
angle: 30 // lessthan 45 deegree
}, function (data) {
console.log(data);
// if (polyline) mapplsClassObject.remove({ map: mapObject, layer: polyline });
const polyline = new mapplsClassObject.Polyline({
map: mapObject,
path: data,
strokeColor: "#333",
strokeOpacity: 1.0,
strokeWeight: 2,
fitbounds: true,
});
});
})
}
);
return (
);
}
export default App;
Personalisation SDK, by Mappls, is India's first O2O engagement tool that can 3X your customer engagement, retention and conversion.
There's so much that Mappls MapmyIndia can do for your enterprise or individual requirements. Explore our website to learn more or request a callback/email if you'd like us to connect with you.