Skip to content

Commit 5a04ba8

Browse files
“makbn”“makbn”
authored andcommitted
updating readme to add new functionalities and description
1 parent 6fa83f6 commit 5a04ba8

File tree

2 files changed

+65
-24
lines changed

2 files changed

+65
-24
lines changed

.github/doc/app.png

5.14 MB
Loading

README.md

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
## Java Leaflet
22
Java wrapper for Leaflet, JavaScript library for mobile-friendly interactive maps.
33

4-
* Current version: **v1.6.0**
4+
* Current version: **v1.9.4**
5+
* Previous version: [v1..6.0](https://github.com/makbn/java_leaflet/tree/release/1.6.0)
56

6-
![Java-Leaflet Test](http://tilin.ir/gnjlRNk)
7+
![Java-Leaflet Test](.github/doc/app.png)
78
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmakbn%2Fjava_leaflet.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmakbn%2Fjava_leaflet?ref=badge_shield)
89

910
> Leaflet is the leading open-source JavaScript library for mobile-friendly interactive maps. Weighing just about 38 KB of JS, it has all the mapping features most > developers ever need.
@@ -17,12 +18,12 @@ First, you need to initialize an instance of `JLMapView`:
1718
```java
1819
final JLMapView map = JLMapView
1920
.builder()
20-
.mapType(JLProperties.MapType.DARK)
21-
.accessToken(ACCESS_TOKEN)
21+
.mapType(JLProperties.MapType.OSM_MAPNIK)
22+
.showZoomController(true)
2223
.startCoordinate(JLLatLng.builder()
23-
.lat(43.54)
24-
.lng(22.54)
25-
.build())
24+
.lat(51.044)
25+
.lng(114.07)
26+
.build())
2627
.build();
2728

2829
```
@@ -31,6 +32,8 @@ Based on Leaflet JS, you can interact with map in different layers. in this proj
3132
* `map` for direct changes on map
3233
* `map.getUiLayer()` for changes on UI layer like markers.
3334
* `map.getVectorLayer()` represents the Vector layer on Leaflet map.
35+
* `map.getControlLayer()` represents the control layer for setting the zoom level.
36+
* `map.getGeoJsonLayer()` represents the GeoJson layer.
3437

3538

3639
### Map functions
@@ -43,8 +46,7 @@ Some map view functionalities are available in map layer like `setView` or `setM
4346
map.setView(JLLatLng.builder()
4447
.lng(10)
4548
.lat(10)
46-
.build()
47-
);
49+
.build());
4850
```
4951

5052
* Add a listener for map events:
@@ -62,11 +64,18 @@ map.setMapListener(new OnJLMapViewListener() {
6264
}
6365

6466
@Override
65-
public void onMove(Action action, JLLatLng center, JLBounds bounds, int zoomLevel) {
66-
super.onMove(action, center, bounds, zoomLevel);
67-
68-
System.out.println("map on move: " + action + " c:" + center + " \t bounds:" + bounds + "\t z:" + zoomLevel);
69-
67+
public void onAction(Event event) {
68+
if (event instanceof MoveEvent moveEvent) {
69+
log.info("move event: " + moveEvent.action() + " c:" + moveEvent.center()
70+
+ " \t bounds:" + moveEvent.bounds() + "\t z:" + moveEvent.zoomLevel());
71+
} else if (event instanceof ClickEvent clickEvent) {
72+
log.info("click event: " + clickEvent.center());
73+
map.getUiLayer().addPopup(clickEvent.center(), "New Click Event!", JLOptions.builder()
74+
.closeButton(false)
75+
.autoClose(false).build());
76+
} else if (event instanceof ZoomEvent zoomEvent) {
77+
log.info("zoom event: " + zoomEvent.zoomLevel());
78+
}
7079
}
7180
}
7281
```
@@ -86,6 +95,14 @@ map.getUiLayer()
8695
.setOnActionListener(getListener());
8796
```
8897

98+
Controlling map's zoom level:
99+
```java
100+
// map zoom functionalities
101+
map.getControlLayer().setZoom(5);
102+
map.getControlLayer().zoomIn(2);
103+
map.getControlLayer().zoomOut(1);
104+
```
105+
89106
you can add a listener for some Objects on the map:
90107
91108
```java
@@ -105,7 +122,7 @@ marker.setOnActionListener(new OnJLObjectActionListener<JLMarker>() {
105122
106123
### Vector layer
107124
108-
Represents the Vector layer on Leaflet map. Poly lines, Polygons, and shapes are available in this layer.
125+
Represents the Vector layer for Leaflet map. Poly lines, Polygons, and shapes are available in this layer.
109126
110127
```java
111128
map.getVectorLayer()
@@ -116,6 +133,18 @@ map.getVectorLayer()
116133
);
117134
```
118135
136+
### GeoJson layer
137+
Represents the GeoJson layer for Leaflet map and defines methods for adding and managing
138+
GeoJSON data layers in a Leaflet map.
139+
```java
140+
JLGeoJsonObject geoJsonObject = map.getGeoJsonLayer()
141+
.addFromUrl("https://pkgstore.datahub.io/examples/geojson-tutorial/example/data/db696b3bf628d9a273ca9907adcea5c9/example.geojson");
142+
143+
```
144+
You can add GeoJson data from three different sources:
145+
* From a file using `map.getGeoJsonLayer().addFromFile([FILE])`
146+
* From a URL using `map.getGeoJsonLayer().addFromUrl([URL])`
147+
* From a GeoJson content `map.getGeoJsonLayer().addFromContent([CONTENT])`
119148
### Styling
120149
121150
You can pass `JLOptions` to each method for changing the default style!
@@ -133,23 +162,35 @@ You can pass `JLOptions` to each method for changing the default style!
133162
);
134163
```
135164
136-
For the map itself, you can choose between these themes:
165+
For the map itself, you can choose between themes available in `JLProperties.MapType` class. The `JLProperties.MapType.OSM_MAPNIK` is available to be used without any access key but for the rest of them, you need to define your own map using `JLProperties.MapType` and passing proper list of key-values containing all the necessary access keys.
166+
```java
167+
JLProperties.MapType myMapType = new JLProperties.MapType("HEREv3.terrainDay",
168+
Set.of(new JLMapOption.Parameter("apiKey", "<insert apiKey here>")));
169+
170+
JLMapView map = JLMapView
171+
.builder()
172+
.mapType(myMapType)
173+
.showZoomController(true)
174+
.startCoordinate(JLLatLng.builder()
175+
.lat(51.044)
176+
.lng(114.07)
177+
.build())
178+
.build();
179+
```
180+
181+
Read more:
137182
138-
* `LIGHT` for mapbox/light-v10
139-
* `DARK` for mapbox/dark-v10
140-
* `OUTDOOR` for mapbox/outdoors-v11
141-
* `SATELLITE` for mapbox/satellite-v9
142-
* `SATELLITE_STREET` for mapbox/satellite-streets-v11
143-
* `STREET` for mapbox/streets-v11
183+
* https://github.com/leaflet-extras/leaflet-providers!
144184
145185
146186
## TODO
147187
148-
- [ ] Adding GeoJson Support
188+
- [X] Adding GeoJson Support
189+
- [ ] Adding better support for Map providers
149190
- [ ] Adding SVG support
150191
- [ ] Adding animation support
151192
- [ ] Separating JS and HTML
152-
- [ ] Publishing package on Github
193+
- [ ] Publishing package on GitHub
153194
154195
**Disclaimer**: I've implemented this project for one of my academic paper in the area of geo-visualization. So, im not contributing actively! One more thing, I'm not a Javascript developer!
155196

0 commit comments

Comments
 (0)