Programming Libraries In JavaScript
React
A JavaScript library for building user interfaces with reusable components.
JavaScript Library
A collection of pre-written JavaScript code that provides reusable functions and tools.
What is a JavaScript library?
A collection of reusable JavaScript code.
Moment.js
A library for parsing, validating, manipulating, and formatting dates and times.
marker.bindPopup("<b>Hello</b>")
Example of adding a popup to a marker in Leaflet.
Order of Scripts
HTML processes scripts top to bottom, so libraries should be included before scripts that use them.
Which LeafletJS object is used to create a map?
L.map()
Which LeafletJS method is used to add a marker?
L.marker().addTo(map)
Which JavaScript library simplifies mapping and geographic data?
LeafletJS
Why Use LeafletJS?
Lightweight, mobile-friendly, customizable, and supports extensive plugins.
What does Axios do?
Makes HTTP requests to APIs using Promises.
Which library is used for formatting dates and times?
Moment.js
The L Object
The core namespace in LeafletJS that contains its classes, methods, and properties.
How to Import LeafletJS
Use `<script>` and `<link>` tags to include Leaflet from a CDN.
Creating a Map in Leaflet
Uses `L.map()` and `L.tileLayer()` to set up a basic map.
Adding a Marker in Leaflet
Uses `L.marker().addTo(map)` to place a point on the map.
Adding a Polygon in Leaflet
Uses `L.polygon()` to create a multi-point shape on the map.
Adding a Polyline in Leaflet
Uses `L.polyline()` to draw a line between multiple points.
Examples of JavaScript Libraries
React, Lodash, Moment.js, Axios.
Why Use JavaScript Libraries?
Reusable code, abstraction, modularity, and cross-browser compatibility.
Axios
A promise-based HTTP client for making API requests.
Lodash
A utility library that provides functions for working with arrays, objects, and strings.
CDN (Content Delivery Network)
A way to include JavaScript libraries by linking to an external hosted file.
What is the purpose of `bindPopup()` in Leaflet?
Adds a tooltip to a marker or shape.
LeafletJS
An open-source JavaScript library for creating interactive maps.
What is the purpose of Lodash?
Provides utility functions for handling arrays, objects, and strings.
Which library is used for building user interfaces?
React