Skip to content
This repository was archived by the owner on Oct 27, 2019. It is now read-only.

Commit ff59ef6

Browse files
authored
Add events handling to Hexbin API (#12)
* add a new fluent onClick(), onMouseOver() and onMouseOut() methods, * add an access to the "dispatcher" for direct dealing with D3 events, * bump version number for further release.
1 parent 7bce4d6 commit ff59ef6

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Add the dependency:
3333
<dependency>
3434
<groupId>pl.itrack</groupId>
3535
<artifactId>gwt-leaflet-d3</artifactId>
36-
<version>0.2.3</version>
36+
<version>0.3.0</version>
3737
</dependency>
3838
```
3939

examples/simple-hexbinlayer-demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>pl.itrack</groupId>
4242
<artifactId>gwt-leaflet-d3</artifactId>
43-
<version>0.2.3</version>
43+
<version>0.3.0</version>
4444
</dependency>
4545
</dependencies>
4646

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>pl.itrack</groupId>
55
<artifactId>gwt-leaflet-d3</artifactId>
6-
<version>0.2.3</version>
6+
<version>0.3.0</version>
77
<packaging>gwt-lib</packaging>
88
<name>GWT Leaflet plugin that allows integration with d3.js library</name>
99
<description>A GWT JsInterop wrapper for collection of plugins for using d3.js with Leaflet</description>

src/main/java/pl/itrack/leafletd3/client/wrapper/HexbinLayer.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,37 @@ public final void setData(T[] data) {
6868
@JsMethod
6969
public native HexbinLayer<T> addTo(Map map);
7070

71+
@JsMethod(name = "dispatch")
72+
public native EventDispatcher<T> getEventDispatcher();
73+
74+
@JsOverlay
75+
public final HexbinLayer<T> onClick(EventCallbackFn<T> callbackFn) {
76+
getEventDispatcher().on("click", callbackFn);
77+
return this;
78+
}
79+
80+
@JsOverlay
81+
public final HexbinLayer<T> onMouseOver(EventCallbackFn<T> callbackFn) {
82+
getEventDispatcher().on("mouseover", callbackFn);
83+
return this;
84+
}
85+
86+
@JsOverlay
87+
public final HexbinLayer<T> onMouseOut(EventCallbackFn<T> callbackFn) {
88+
getEventDispatcher().on("mouseout", callbackFn);
89+
return this;
90+
}
91+
7192
@JsFunction
7293
public interface CallbackFn<T> {
7394
double calculate(T value);
7495
}
7596

97+
@JsFunction
98+
public interface EventCallbackFn<T> {
99+
void execute(CallbackContainer<T>[] callers, double index);
100+
}
101+
76102
/**
77103
* For some leaflet-d3 methods the expected data is nested in function callback object.
78104
* It is wrapped for easier access.
@@ -177,10 +203,17 @@ public Config.Builder withRadiusDomain(double[] radiusDomain) {
177203
return this;
178204
}
179205

180-
181206
public Config build() {
182207
return this;
183208
}
184209
}
185210
}
211+
212+
@JsType(isNative = true, namespace = GLOBAL, name = "Object")
213+
public static class EventDispatcher<T> {
214+
215+
@JsMethod
216+
public native EventDispatcher<T> on(String type, EventCallbackFn<T> callbackFn);
217+
218+
}
186219
}

0 commit comments

Comments
 (0)