2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2020 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 { Feature } from 'model/Feature';
23 export const addBaseLayers = (map: mapboxgl.Map, selectedPoint: Feature|null, selectedLine: Feature|null) => {
25 const boundingBox = map.getBounds();
26 map.addSource('lines', {
28 data: { type: "FeatureCollection", features: [] }
31 const features = selectedLine !== null ? [selectedLine] : [];
33 map.addSource('selectedLine', {
35 data: { type: "FeatureCollection", features: features }
38 map.addSource('points', {
40 data: { type: "FeatureCollection", features: [] }
43 const selectedPointFeature = selectedPoint !== null ? [selectedPoint] : [];
46 map.addSource('selectedPoints', {
48 data: { type: "FeatureCollection", features: selectedPointFeature }
69 'source': 'selectedLine',
87 'circle-color': '#11b4da',
89 'circle-stroke-width': 1,
90 'circle-stroke-color': '#fff'
96 source: 'selectedPoints',
99 'circle-color': '#116bda',
101 'circle-stroke-width': 1,
102 'circle-stroke-color': '#fff'
106 map.addSource("alarmedPoints", {
108 data: {type:"FeatureCollection", features:[]}
113 source: 'alarmedPoints',
116 'circle-color': '#CC0000',
118 'circle-stroke-width': 1,
119 'circle-stroke-color': '#fff'
124 export const removeBaseLayers = (map: mapboxgl.Map) => {
126 map.removeLayer("points");
127 map.removeLayer("lines");
128 map.removeLayer('selectedPoints');
129 map.removeLayer('selectedLine');
131 map.removeSource("points");
132 map.removeSource("lines");
133 map.removeSource('selectedPoints');
134 map.removeSource('selectedLine');
137 let checkedLayers = false;
139 const createFilter = (type:'street lamp'|'high rise building'|'data center', selectedSiteId?:string) =>{
141 return selectedSiteId === undefined ? ['==', 'type', type] : ["all", ['==', 'type', type], ['!=', 'id', selectedSiteId]]
144 export const showIconLayers = (map: mapboxgl.Map, show: boolean, selectedSiteId?: string) => {
146 const zoom = map.getZoom();
152 const bounds = map.getBounds();
154 if(map.getLayer('points')!== undefined && map.getLayer('point-lamps')===undefined && !checkedLayers){
156 // if sites don't have a type don't change layers to icons
157 const elements = map.queryRenderedFeatures( undefined,{
158 layers: ['points'], filter:['has', 'type']
162 if(elements.length>0 && elements.length<1000){
164 if (map.getLayer('point-lamps') === undefined) {
165 map.removeLayer('points');
167 map.setLayoutProperty('selectedPoints', 'visibility', 'none');
174 'icon-allow-overlap': true,
175 'icon-image': 'lamp',
179 'filter': createFilter("street lamp", selectedSiteId),
183 'id': 'point-building',
186 'filter': createFilter("high rise building", selectedSiteId),
188 'icon-allow-overlap': true,
189 'icon-image': 'house',
195 'id': 'point-data-center',
198 'filter': createFilter("data center", selectedSiteId),
200 'icon-allow-overlap': true,
201 'icon-image': 'data-center',
206 id: 'point-remaining',
209 'filter': ['==', 'type', ''],
211 'circle-color': '#11b4da',
213 'circle-stroke-width': 1,
214 'circle-stroke-color': '#fff'
219 'id': 'select-point-lamps',
221 'source': 'selectedPoints',
223 'icon-allow-overlap': true,
224 'icon-image': 'lamp',
228 'filter': ['==', 'type', 'street lamp'],
232 'id': 'select-point-buildings',
234 'source': 'selectedPoints',
235 'filter': ['==', 'type', 'high rise building'],
237 'icon-allow-overlap': true,
238 'icon-image': 'house',
244 'id': 'select-point-data-center',
246 'source': 'selectedPoints',
247 'filter': ['==', 'type', 'data center'],
249 'icon-allow-overlap': true,
250 'icon-image': 'data-center',
268 export const swapLayersBack = (map: mapboxgl.Map) =>{
270 if (map.getLayer('points') === undefined) {
272 map.setLayoutProperty('selectedPoints', 'visibility', 'visible');
274 map.removeLayer('point-building');
275 map.removeLayer('point-lamps');
276 map.removeLayer('point-data-center');
277 map.removeLayer('point-remaining');
278 map.removeLayer('select-point-data-center');
279 map.removeLayer('select-point-buildings');
280 map.removeLayer('select-point-lamps');
289 'circle-color': '#11b4da',
291 'circle-stroke-width': 1,
292 'circle-stroke-color': '#fff'
296 map.moveLayer('points', map.getLayer('selectedPoints').id)
302 const addClusterLayers = (map: mapboxgl.Map, data: any) => {
303 map.addSource('clusters', {
308 map.addSource('selectedLine', {
310 data: { type: "FeatureCollection", features: [] }
313 map.addSource('selectedPoints', {
315 data: { type: "FeatureCollection", features: [] }
323 filter: ['has', 'count'],
351 filter: ['has', 'count'],
353 'text-field': '{count}',
354 'text-font': ['Roboto Bold'],
360 'id': 'selectedLine',
362 'source': 'selectedLine',
364 'line-join': 'round',
368 'line-color': '#888',
374 id: 'unclustered-points',
376 filter: ['!', ['has', 'count'],],
379 'circle-color': '#11b4da',
381 'circle-stroke-width': 1,
382 'circle-stroke-color': '#fff'
387 id: 'selectedPoints',
388 source: 'selectedPoints',
391 'circle-color': '#116bda',
393 'circle-stroke-width': 1,
394 'circle-stroke-color': '#fff'