【问题标题】:unable to resolve method in class无法解析类中的方法
【发布时间】: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


【解决方案1】:

您还需要传递您的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

【讨论】:

  • 但我不想给出两个争论,因为当我调用这个 addOnPostRenderListener(OnPostRenderListener listener) 时,这完全改变了 v-ol3 API 的设计; ,只有一个争论有没有机会?
  • 更新了我的答案 - 不知道这是否适合您
  • 在 JSNI 方法引用中期望一个有效的参数类型签名,我仍然遇到这个错误
  • 这条线你也修了吗? this.__postRenderListeners.push(OnPostRenderListener); 应该是 this.__postRenderListeners.push(listener);
  • 我根据您提到的上述几行更改了我的代码,但我仍然面临 var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource); 的问题错误是 ::::: Expected a valid parameter type signature in JSNI method reference
猜你喜欢
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-28
  • 1970-01-01
  • 1970-01-01
  • 2019-04-29
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多