# Getting Started with Java Leaflet
This guide will help you get up and running with Java Leaflet in minutes, whether you're building a JavaFX desktop application or a Vaadin web application.
## Table of Contents
- [Installation](#installation)
- [JavaFX Setup](#javafx-setup)
- [Vaadin Setup](#vaadin-setup)
- [Creating Your First Map](#creating-your-first-map)
- [JavaFX Example](#javafx-example)
- [Vaadin Example](#vaadin-example)
- [Basic Concepts](#basic-concepts)
- [Next Steps](#next-steps)
---
## Installation
### Prerequisites
- **Java 17** or higher
- **Maven 3.6+** or Gradle 7+
- For JavaFX: **JavaFX SDK 19+**
- For Vaadin: **Node.js 16+** (for frontend compilation)
### JavaFX Setup
Add the JavaFX dependency to your `pom.xml`:
```xml
This is a popup
" ); ``` ### Drawing Shapes ```java // Draw a circle mapView.getVectorLayer().addCircle( new JLLatLng(51.508, -0.11), 500, // radius in meters JLOptions.builder() .color(JLColor.BLUE) .fillColor(JLColor.BLUE) .fillOpacity(0.3) .build() ); // Draw a polygon JLLatLng[] vertices = { new JLLatLng(51.509, -0.08), new JLLatLng(51.503, -0.06), new JLLatLng(51.51, -0.047) }; mapView.getVectorLayer().addPolygon( new JLLatLng[][][] { new JLLatLng[][] { vertices } }, JLOptions.builder() .color(JLColor.RED) .build() ); ``` ### Controlling the View ```java // Pan to a location mapView.getControlLayer().panTo(new JLLatLng(51.505, -0.09)); // Animate to a location mapView.getControlLayer().flyTo(new JLLatLng(48.8566, 2.3522), 10); // Zoom mapView.getControlLayer().zoomIn(2); mapView.getControlLayer().setZoom(12); // Fit bounds JLBounds bounds = JLBounds.builder() .southWest(new JLLatLng(51.5, -0.1)) .northEast(new JLLatLng(51.52, -0.08)) .build(); mapView.getControlLayer().fitBounds(bounds); ``` --- ## Complete Example Here's a more complete example showing multiple features: ```java import io.github.makbn.jlmap.fx.JLMapView; import io.github.makbn.jlmap.map.JLMapProvider; import io.github.makbn.jlmap.model.*; import io.github.makbn.jlmap.listener.event.ClickEvent; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class ComprehensiveExample extends Application { @Override public void start(Stage primaryStage) { // Create map JLMapView mapView = JLMapView.builder() .jlMapProvider(JLMapProvider.OSM_MAPNIK.build()) .startCoordinate(new JLLatLng(51.505, -0.09)) .showZoomController(true) .build(); // Add a marker with popup JLMarker marker = mapView.getUiLayer().addMarker( new JLLatLng(51.505, -0.09), "Click me!", true ); // Add click listener marker.setOnActionListener((source, event) -> { if (event instanceof ClickEvent) { System.out.println("Marker clicked!"); } }); // Draw a circle around the marker mapView.getVectorLayer().addCircle( new JLLatLng(51.505, -0.09), 500, JLOptions.builder() .color(JLColor.BLUE) .fillOpacity(0.2) .build() ); // Create scene BorderPane root = new BorderPane(mapView); Scene scene = new Scene(root, 1000, 700); primaryStage.setTitle("Java Leaflet - Comprehensive Example"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` --- ## Troubleshooting ### JavaFX: Map Not Showing If the map doesn't appear: 1. **Check JavaFX modules** - Ensure JavaFX modules are in your module path 2. **Wait for map load** - The map loads asynchronously. Use event listeners if needed 3. **Check console** - Look for JavaScript errors in the console ### Vaadin: Compilation Errors If you get frontend compilation errors: 1. **Install Node.js** - Vaadin requires Node.js for frontend compilation 2. **Run `mvn clean install`** - This will download and install frontend dependencies 3. **Check Vaadin version** - Ensure you're using Vaadin 24+ ### Module Path Issues If you encounter module issues: ```java module com.example.myapp { requires io.github.makbn.jlmap.fx; // For JavaFX // OR requires io.github.makbn.jlmap.vaadin; // For Vaadin requires javafx.controls; // For JavaFX requires javafx.web; // For JavaFX } ``` --- ## Next Steps Now that you have a basic map running, explore more features: 1. **[Context Menus](Context-Menu-Guide)** - Add right-click menus to map objects 2. **[Journey System](Journey-System)** - Create animated journeys 3. **[API Reference](API-Reference)** - Explore the complete API 4. **[Examples & Tutorials](Examples-and-Tutorials)** - Learn from more examples 5. **[Architecture](Architecture)** - Understand the internals --- ## Additional Resources - **[JavaFX Documentation](https://openjfx.io/)** - Learn more about JavaFX - **[Vaadin Documentation](https://vaadin.com/docs)** - Learn more about Vaadin - **[Leaflet.js](https://leafletjs.com/)** - Original JavaScript library - **[GitHub Repository](https://github.com/makbn/java_leaflet)** - Source code and examples --- **Previous**: [← Home](Home) | **Next**: [Architecture Overview →](Architecture)