DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Data Life With Algorithms
  • Unleashing the Power of Python: A Deep Dive into Data Visualization
  • Importance and Impact of Exploratory Data Analysis in Data Science
  • The Power of Visualization in Exploratory Data Analysis (EDA)

Trending

  • Performance Optimization Techniques for Snowflake on AWS
  • Build an MCP Server Using Go to Connect AI Agents With Databases
  • Accelerating AI Inference With TensorRT
  • AI's Dilemma: When to Retrain and When to Unlearn?
  1. DZone
  2. Data Engineering
  3. Data
  4. Geospatial Data Analysis in Angular

Geospatial Data Analysis in Angular

This article will explain the method to create an interactive geospatial data visualization with Angular 8, MapboxGL and DeckGL.

By 
Imaginea Technologies user avatar
Imaginea Technologies
·
Mar. 02, 20 · Analysis
Likes (3)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

Immersive experience has tapped into data analysis with a dazzling array of visualization techniques. The evolution of visualization-based data analysis influences business and sets apart from the competition since it can help provide the desired user experience. Users prefer data storytelling and demand data visualization beyond reports and dashboards. IT teams add visualization features to enable and standardize data visualization as it is a powerful mode for displaying the metrics.

You may also like: What Data Analysis Tools Should I Learn to Start a Career as a Data Analyst?

Deck.gl is a WebGL-powered framework from Uber for visual exploratory data analysis of large datasets. In simple words, Deck.gl is a library that is used to create interactive visualizations on the web for large datasets and the library is powered by WebGL.

This blog will explain the method to create an interactive geospatial data visualization with Angular 8, MapboxGL and DeckGL. Here you can find a way to integrate Deck.gl, an Uber Visualization library into Angular Apps. After several trial and error approach from multiple Vanilla JS/Non-Angular guides, this how-to procedure holds true with most of the Angular Versions (2+) but it is most accurate with Angular 8.

To ensure a workable environment for Angular CLI, prior installation of node and npm is essential.

Creating an Angular App

  • If you have Angular CLI Installed then you are good to go, else Install Angular CLI from here.
  • Create an Angular app using the CLI ng new visualization.
  • If you are using CLI V8 then you will be prompted with a couple of questions about routing and CSS pre-processors configurations before creating the app, select the appropriate option that works for you and proceed to generate the app.
  • Now navigate to the directory of your project cd visualization.
  • Run the command ng serve and open localhost:4200 on your browser. You will see the below screen (or a different one depending on your CLI/Angular Versions).

Generate Mapbox Token

  • Go to Mapbox, create an account, and generate a Mapbox token.
  • Add the Mapbox token to your src/environments/environment.ts file.
CSS
 




xxxxxxxxxx
1


 
1
export const environment = {
2
production: false,
3
mapboxToken: ‘YOUR_MAPBOX_TOKEN’
4
};



Install and Initialize MapboxGL

  • Now Install MapboxGL packages into your project using npm i –save mapbox-gl  @types/mapbox-gl
  • Delete everything in src/app/app.component.html and add the following HTML code.
HTML
 




xxxxxxxxxx
1


 
1
<div id=”container”>
2
<div id=”map”></div>
3
</div>



  • Add the following CSS to your src/app/app.component.css.
CSS
 




xxxxxxxxxx
1
14


 
1
#container {
2
position: fixed;
3
top: 0;
4
left: 0;
5
right: 0;
6
bottom: 0;
7
}
8
#container > * {
9
position: absolute;
10
top: 0;
11
left: 0;
12
width: 100%;
13
height: 100%;
14
}



  • Import MapboxGL, configure the Mapbox token and Initialize Mapbox-gl on the container as below in your src/app/app.component.ts.
CSS
 




xxxxxxxxxx
1
26


 
1
// src/app/app.component.ts
2
import { Component, AfterViewInit } from ‘@angular/core’;
3
import { environment } from ‘src/environments/environment’;
4
import * as mapboxgl from ‘mapbox-gl’;
5
@Component({…}) // default code
6
export class AppComponent implements AfterViewInit{
7
ngAfterViewInit() {
8
(mapboxgl as any).accessToken = environment.mapboxToken; // configure the mapbox token
9
const INITIAL_VIEW_STATE = {
10
latitude: 51.47,
11
longitude: 0.45,
12
zoom: 4,
13
bearing: 0,
14
pitch: 30
15
};
16
const map = new mapboxgl.Map({
17
container: ‘map’, // should be the div id
18
style: ‘mapbox://styles/mapbox/dark-v10’,
19
interactive: false, // deck.gl will be in charge of interaction and event handling
20
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
21
zoom: INITIAL_VIEW_STATE.zoom,
22
bearing: INITIAL_VIEW_STATE.bearing,
23
pitch: INITIAL_VIEW_STATE.pitch
24
});
25
}
26
}



Reload your browser window (if it isn’t auto-reloaded) and you will see the map loaded on to your screen. It isn’t interactive as you used the flag interactive: false in your Mapbox configuration above. We will explain this in the following steps.

Install and Initialize DeckGL

  • Install the required packages for using deck.gl
    npm i –save deck.gl @deck.gl/core @deck.gl/layers
  • Add a canvas element to src/app/app.component.html, and your HTML code should look like:
HTML
 




xxxxxxxxxx
1


 
1
<div id=”container”>
2
<div id=”map”></div>
3
<canvas id=”deck-canvas”></canvas>
4
</div>



  • Import the required packages in src/app/app.component.ts
CSS
 




xxxxxxxxxx
1


 
1
import { Deck } from ‘@deck.gl/core’;
2
import { GeoJsonLayer, ArcLayer } from ‘@deck.gl/layers’;



  • Add the data sources inside ngAfterViewInit
JSON
 




xxxxxxxxxx
1


 
1
const AIR_PORTS = ‘https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson’;



The above data source if from official DeckGL examples.

  • Initialize deck.gl just below the MapboxGL Initialization const map = new mapboxgl.Map({…});
CSS
 




xxxxxxxxxx
1
27


 
1
const deck = new Deck({
2
canvas: ‘deck-canvas’,
3
width: ‘100%’,
4
height: ‘100%’,
5
initialViewState: INITIAL_VIEW_STATE,
6
controller: true,
7
onViewStateChange: ({ viewState }) => {
8
map.jumpTo({
9
center: [viewState.longitude, viewState.latitude],
10
zoom: viewState.zoom,
11
bearing: viewState.bearing,
12
pitch: viewState.pitch
13
});
14
},
15
layers: [
16
new ArcLayer({
17
id: ‘arcs’,
18
data: AIR_PORTS,
19
dataTransform: d => d.features.filter(f => f.properties.scalerank < 4),
20
getSourcePosition: f => [-0.4531566, 51.4709959], // London
21
getTargetPosition: f => f.geometry.coordinates,
22
getSourceColor: [0, 128, 200],
23
getTargetColor: [200, 0, 80],
24
getWidth: 1
25
})
26
]
27
});



You can use the same approach to add another set of DeckGL layers to the map or integrate this map into other components.

Deck.gl has an amazing set of prebuilt visualizations that you could use to visually represent large sets of data. A few of the screenshots of examples are listed below. If you want to try them out then you can find a list of examples here.

With the above-described building blocks of data visualizations, businesses can create better data visualization to tell compelling stories. The interactive ways in which businesses deliver real-time analytics create greater awareness of data and deliver insights in a way that engages with decision-makers in an easily assimilated form.


Further Reading

Comparison of Data Analysis Tools: Excel, R, Python, and BI Tools

Principles of Data Analysis for Beginners

Data analysis Data visualization AngularJS

Published at DZone with permission of Imaginea Technologies. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Data Life With Algorithms
  • Unleashing the Power of Python: A Deep Dive into Data Visualization
  • Importance and Impact of Exploratory Data Analysis in Data Science
  • The Power of Visualization in Exploratory Data Analysis (EDA)

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!