1。是否可以将gwt中的本机方法调用到另一个本机方法中?
这是我从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类中创建了一个本机方法,并获取功能,我想将这些功能值返回给 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 < / strong>方法
var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);
我的目标是将VectorSource.java类中的getFeatures()方法调用到Map.java类中,并将值发送给另一个本机方法,即addOnPostRenderListener方法。
界面
public interface OnPostRenderListener {
public void onRender(MapEvent posEvent);
}
MapEvent
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);
}-*/;
}
答案 0 :(得分:0)
您还需要传递VectorSource sourceFeature
参数。您在that.@org.vaadin.gwtol3.client.Map::getFeatures(Lcom/google/gwt/core/client/Source;);
中丢失了它。
一种方法是将其添加到您的
addOnPostRenderListener(OnPostRenderListener listener)
例如addOnPostRenderListener(OnPostRenderListener listener, VectorSource vectorSource)
然后像这样访问它:
var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);
尽管我建议完全删除JSNI ,并使用更好的 JsInterop 。也有一个使用JsInterop的OL实现。看看 here