【发布时间】:2018-07-25 13:05:25
【问题描述】:
1.是否可以将gwt中的native方法调用到其他native方法中?
这是我从 VectorSource.java 调用到 Map.java 的方法 https://github.com/VOL3/v-ol3/blob/master/gwt-ol3/src/main/java/org/vaadin/gwtol3/client/source/VectorSource.java
public final native JsArray<Feature> getFeatures()/*-{
return this.getFeatures();
}-*/;
我在 Map.java 类中创建了一个本地方法并获取了 Features,我想将这些特征值返回给 addOnPostRenderListener 方法,下面是 Map 中的更改.java 类
public native final Feature getFeatures(VectorSource sourceFeature)/*-{
var features=sourceFeature.@org.vaadin.gwtol3.client.source.VectorSource::getFeatures();
return features;
}-*/;
public native final void addOnPostRenderListener(OnPostRenderListener listener)/*-{
if(!this.__registered){
var that=this;
that.once('postrender',function(){
var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);
if(feature!=null){
var coordinate=feature.getGeometry().getCoordinate();
if(coordinates!=null){
var MapEvent={Pixel:that.getPixelFromCoordinate(that.__transformInputCoordinate(coordinates))};
that.__notifyPostRenderListeners(MapEvent);
}
}})
this.__postRenderListeners.push(listener);
}
}-*/;
其余代码与以下链接所示相同 https://github.com/VOL3/v-ol3/blob/master/gwt-ol3/src/main/java/org/vaadin/gwtol3/client/Map.java
在下面的代码中我得到了错误,因为 在 JSNI 方法参考中预期有一个有效的参数类型签名这些代码行在 addOnPostRenderListener 方法
var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);
我的目标是将 VectorSource.java 类中的 getFeatures() 方法调用到 Map.java 类中,并将值发送到另一个本机方法,即 addOnPostRenderListener 方法。
界面
public interface OnPostRenderListener {
public void onRender(MapEvent posEvent);
}
地图事件
public class MapEvent extends JavaScriptObject {
protected MapEvent() {
}
public static final native Feature create()/*-{
return new $wnd.ol.Feature();
}-*/;
public native final Geometry getGeometry()-{
return this.getGeometry();
}-;*/
public native final Geometry getGeometry()/*-{
return this.geometry;
}-*/;
public native final Coordinate getCoordinate()/*-{
return this.coordinate;
}-*/;
public native final Pixel getPixel()/*-{
return this.Pixel;
}-*/;
//written code not used
public native final Map getPixelFromCoordinate(Coordinate coord)/*-{
return this.getPixelFromCoordinate(coord);
}-*/;
}
【问题讨论】:
-
您使用的是哪个版本的 gwt?
-
@Halko 2.8.0 版本,但您在 2.8.0 的 Api 中看不到这一点,因为这些是我编写的扩展方法,用于使用 gwt-ol3 获取地图上多边形的像素值API
标签: javascript gwt openlayers jsni