2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 import * as mapboxgl from "mapbox-gl";
20 import { LatLon } from "../model/LatLon";
23 export const addBaseSource = (map : mapboxgl.Map, name: string) =>{
25 if(!map.getSource(name))
29 data: { type: "FeatureCollection", features: [] }
34 export const addPoint = (map : mapboxgl.Map, point: LatLon) =>{
41 [${point.longitude}, ${point.latitude}]
46 (map.getSource("route") as mapboxgl.GeoJSONSource).setData(JSON.parse(json));
49 export const addBaseLayer = (map: mapboxgl.Map, sourceName: string) =>{
51 if(!map.getLayer('line'))
67 if(!map.getLayer('points'))
74 'circle-color': '#223b53',
75 'circle-stroke-color': '#225ba3',
76 'circle-stroke-width': 3,
82 export const calculateDistanceInMeter = (lat1: number, lon1: number, lat2: number, lon2: number) => {
83 const lonRad1 = toRad(lon1);
84 const latRad1 = toRad(lat1);
85 const lonRad2 = toRad(lon2);
86 const latRad2 = toRad(lat2);
88 const dLon = lonRad2 - lonRad1;
89 const dLat = latRad2 - latRad1;
90 const a = Math.pow(Math.sin(dLat / 2), 2) +
91 Math.cos(latRad1) * Math.cos(latRad2) *
92 Math.pow(Math.sin(dLon / 2), 2);
94 const c = 2 * Math.asin(Math.sqrt(a));
100 function toRad(value: number) {
101 return (value * Math.PI) / 180;