Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法解析类中的方法_Javascript_Gwt_Openlayers_Jsni - Fatal编程技术网

Javascript 无法解析类中的方法

Javascript 无法解析类中的方法,javascript,gwt,openlayers,jsni,Javascript,Gwt,Openlayers,Jsni,1.是否可以将gwt中的本机方法调用到另一个本机方法中 这就是我从VectorSource.java调用到Map.java的方法 其余代码与下面链接中显示的代码相同 在下面的代码中,我得到了错误,因为在JSNI方法引用中预期会有一个有效的参数类型签名这些代码行在addOnPostRenderListener方法中 var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource); 我的目标是将VectorS

1.是否可以将gwt中的本机方法调用到另一个本机方法中

这就是我从VectorSource.java调用到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);
}
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);
    }-*/;
}

您还需要传递
VectorSourceFeature
参数。您在
中缺少它。@org.vaadin.gwtol3.client.Map::getFeatures(Lcom/google/gwt/core/client/Source;)

一种方法是将其添加到您的

addOnPostRenderListener(OnPostRenderListener侦听器)

e、 g.
addOnPostRenderListener(OnPostRenderListener侦听器,矢量源矢量源)

然后像这样访问它:

var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);

尽管我建议完全放弃JSNI并使用更好的JsInterop。还有一个使用JsInterop的OL实现。看看

您使用的是哪一版本的gwt?@Halko 2.8.0版本,但您在2.8.0的Api中看不到这一点,因为这些是我编写的扩展方法,用于使用gwt-ol3 Api获取地图上多边形的像素值,但我不想给出两个论点,因为这完全改变了v-ol3 Api的设计我称这个addOnPostRenderListener(OnPostRenderListener侦听器),有没有可能只有一个参数?更新了我的答案-不知道这是否是您的一个选项在JSNI方法引用中需要一个有效的参数类型签名,,我得到了TST直到这个错误您也修复了这行吗<代码>此.uu postrenderlistener.push(OnPostRenderListener)应该是
这个我根据您提到的上述行更改了代码,但我仍然面临var feature=that的问题。@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);错误为:在JSNI方法引用中应为有效的参数类型签名
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);
    }-*/;
}
var feature=that.@org.vaadin.gwtol3.client.Map::getFeatures(vectorSource);