U2a1 - Leaflet Api
U2a1 - Leaflet Api
“LEAFLET API”
PRESENTA:
Topic Page
Index of Figures.................................................................... ii
Introduction ......................................................................... 1
Requirements ....................................................................... 2
i
Index of Figures
Figure Page
ii
Introduction
The primary objective of this activity is to guide through the installation process
and demonstrate the creation of a pinpoint location on the campus of
“Universidad Tecnológica de Tamaulipas Norte”.
Figure 1 My Pin
1
Requirements
For the development of the application, make sure to have the following essential
elements installed on your system:
2
App Creation
Follow the steps below to set up a project, integrate essential libraries and create
an interactive map that enhances the application's functionality.
Directory Creation
Commence the project by creating a directory through Visual Studio and Apache
Cordova. Execute the command "Cordova create leaftlet_API" in the terminal to
establish the project framework.
Navigate to the project directory with "cd leaflet_API" and enhance platform
compatibility by adding the browser and Android platforms.
Figure 3 Platforms
3
Install essential libraries seamlessly by running npm commands. Use "npm install
jquery" and "npm install bootstrap" to add jQuery and Bootstrap to the project.
Optimize the project structure by relocating the "bootstrap" directory into the
"css" directory. Import it into the "init.css" file.
4
Figure 7 Organization of the directories
Map Creation
Open the "index.html" file located in "www" directory and ensure that the Leaflet,
jQuery, and CSS files are properly linked to guarantee the correct functionality of
the application.
Add a new <div> element with the id "map" inside the main "app" <div> in the
HTML file.
5
Figure 10 Map <div> Creation
In the CSS file, set specific height and width constraints for the map to ensure
proper styling.
Create a new JavaScript file and copy the following scripts into it.
6
Initialize the map by setting its view to the geographical coordinates of
“Universidad Tecnológica de Tamaulipas Norte” and configuring an appropriate
zoom level.
Adds a tile layer to the map, in this case it is an OpenStreetMap tile layer.
Include the JavaScript file in the "index.html" after adding the Leaflet.js library
and defining the <div>. This order ensures that the script executes after loading
dependencies and structural elements, ensuring proper functionality.
7
Figure 17 Leaflet Map
In addition to tile layers, other things can be easily added to the map, such as
markers, polylines, polygons, circles, and pop-ups.
Polygon
8
Circle
Establish the "Reunion Point" with a circle. Construct the circle by specifying
center coordinates and customizing its appearance. Provide the center
coordinates within brackets and adjust attributes like color, fill, opacity, and radius
for the desired visual effect. Include a pop-up describing the purpose of the circle
as the "Reunion Point."
Marker
Locate the current classroom position with a marker. Markers, being fixed images,
can't be modified directly. Pinpoint the classroom on the map by specifying its
coordinates. Display the classroom number with a popup.
9
Result
If all instructions have been followed correctly, the map should look like this:
10