Exemplo n.º 1
0
 public FeatureLayer addLayer(String url) {
   if (url == null || url.equals("url")) {
     return null;
   }
   Geodatabase localGdb = null;
   try {
     localGdb = new Geodatabase(PathUitl.getInnerSDCardPath() + url);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   if (localGdb != null) {
     for (GeodatabaseFeatureTable gdbFeatureTable : localGdb.getGeodatabaseTables()) {
       if (gdbFeatureTable.hasGeometry()) {
         FeatureLayer featureLayer = new FeatureLayer(gdbFeatureTable);
         Symbol symbol = new SimpleFillSymbol(Color.BLUE);
         Renderer renderer = new SimpleRenderer(symbol);
         featureLayer.setRenderer(renderer);
         featureLayer.setVisible(false);
         mMapView.addLayer(featureLayer);
         mMapView.setExtent(featureLayer.getExtent());
         return featureLayer;
       }
     }
   }
   return null;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);

    mapView.addLayer(
        new ArcGISTiledMapServiceLayer(
            "http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"));

    layer = new GraphicsLayer();
    mapView.addLayer(layer);

    mapView.getLocationDisplayManager().start();
    mapView.getLocationDisplayManager().setLocationListener(this);

    try {
      client =
          new MqttAndroidClient(
              this, "tcp://broker.mqttdashboard.com:1883", "Likaci/MqttMap/" + id);
      client.setCallback(this);
      MqttConnectOptions options = new MqttConnectOptions();
      options.setKeepAliveInterval(10);
      options.setConnectionTimeout(1000);
      options.setCleanSession(false);
      client.connect(options, null, this);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  private void initMap() {
    //        TDTImgLayer = new TianDiTuLayer(TianDiTuLayerTypes.TIANDITU_IMAGE_2000);
    //        TDTImgAnnotationLayer = new TianDiTuLayer(
    //                TianDiTuLayerTypes.TIANDITU_IMAGE_ANNOTATION_CHINESE_2000);
    //        mMapView.addLayer(TDTImgLayer);
    //        mMapView.addLayer(TDTImgAnnotationLayer);

    // GPS定位的图形层
    gpsLayer = new GraphicsLayer();
    // gpsLayer.setVisible(false);
    // mMapView.addLayer(gpsLayer);

    //        addLayer(localGdb);
    mapls = new ArrayList<MapTypeLayer>();
    for (String layername : layertypes) {
      for (int i = 0; i < lmtl.size(); i++) {
        if (layername.equals(lmtl.get(i).getName())) {
          mapls.add(lmtl.get(i));
          break;
        }
      }
    }

    locallist = new ArrayList<ArcGISLocalTiledLayer[]>();
    for (int i = 0; i < mapls.size(); i++) {
      MapTypeLayer maptypelayer = mapls.get(i);
      System.out.println(maptypelayer.getName());
      ArrayList<MAPLayer> maplays = maptypelayer.getMaplist();
      ArcGISLocalTiledLayer[] local = new ArcGISLocalTiledLayer[maplays.size()];

      for (int j = 0; j < maplays.size(); j++) {
        local[j] = new ArcGISLocalTiledLayer(maplays.get(j).getuRL());
        mMapView.addLayer(local[j]);
        if (i == 0) {
          local[j].setVisible(true);
        } else {
          local[j].setVisible(false);
        }
      }
      locallist.add(local);
    }

    adapter = new MapLayerShow(context, mapls, mMapView);
    map_layers.setAdapter(adapter);

    mMapView.setOnStatusChangedListener(
        new OnStatusChangedListener() {
          public void onStatusChanged(Object source, STATUS status) {
            // 地图加载成功后定位到详细位置
            if (status == STATUS.LAYER_LOADED) {

              //     Point centerPt = new Point(116.45, 27.60);
              //    mMapView.zoomToScale(centerPt, 3000000);
            }
          }
        });
  }
Exemplo n.º 4
0
 /**
  * 获取当前图层
  *
  * @param map
  * @return
  */
 private GraphicsLayer GetGraphicLayer(MapView map) {
   if (mGraphicsLayer == null) {
     mGraphicsLayer = new GraphicsLayer();
     map.addLayer(mGraphicsLayer);
   }
   return mGraphicsLayer;
 }
  // Display
  public void show() {
    if (mIsDisplayed) return;

    FragmentActivity activity = (FragmentActivity) mMapView.getContext();
    FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.popup_rotate_in, R.anim.popup_rotate_out);
    transaction.add(android.R.id.content, this, null);
    transaction.addToBackStack(null);
    transaction.commit();
    setDisplayed(true);
  }
Exemplo n.º 6
0
  public void search(String keywords) {
    System.out.println(keywords);
    featureLayer.clearSelection();
    QueryParameters q = new QueryParameters();
    q.setWhere("NAME = '" + keywords + "'");
    q.setReturnGeometry(true);
    q.setInSpatialReference(mMapView.getSpatialReference());
    // q.setGeometry(g.getGeometry());
    q.setSpatialRelationship(SpatialRelationship.INTERSECTS);
    featureLayer.selectFeatures(
        q,
        FeatureLayer.SelectionMode.NEW,
        new CallbackListener<FeatureResult>() {
          @Override
          public void onError(Throwable e) {
            e.printStackTrace();
          }

          @Override
          public void onCallback(FeatureResult featureResult) {
            if (null != featureResult) {
              // If there are no query results, inform user.
              if (featureResult.featureCount() < 1) {
                System.out.println("无查询结果");
                return;
              }

              // Iterate the results and select each feature.
              for (Object objFeature : featureResult) {
                Feature feature = (Feature) objFeature;
                System.out.println(feature.getAttributes().get("NAME"));
                resultCallOut = mMapView.getCallout();
                //    content = (View) view.findViewById(R.layout.calloutlayout);//弹出窗口布局文件对象
                //                        PopupContainer mPopupContainer = new
                // PopupContainer(mMapView);
                //                        Popup popup =featureLayer.createPopup(mMapView, 0,
                // feature);
                //
                //                        popup.setEditable(true);
                //
                //                        mPopupContainer.addPopup(popup);

                //  mMapView.centerAt(feature.getGeometry(), true);
                // mMapView.setExtent(feature.getGeometry());
                //  featureLayer.selectFeature(feature.getId());
              }
              // 创建弹出窗体

            }
          }
        });
  }
Exemplo n.º 7
0
  private void updateToNewLocation(Location location) {
    gpsLayer.removeAll();
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    Point ptMap1 =
        (Point)
            GeometryEngine.project(
                new Point(longitude, latitude),
                SpatialReference.create(4326),
                mMapView.getSpatialReference());

    gpsLayer.addGraphic(new Graphic(ptMap1, resultIcon));

    // mMapView.zoomToScale(ptMap1, 4223);
    // mMapView.centerAt(ptMap1, true);

  }
  // Get the feature layer which is associated with the current popup
  private ArcGISFeatureLayer getFeatureLayer(Popup popup) {
    ArcGISFeatureLayer featureLayer = null;

    if ((mMapView == null) || (popup == null)) return null;
    PopupInfo popupInfo = popup.getPopupInfo();
    if (popupInfo instanceof ArcGISPopupInfo) {
      ArcGISPopupInfo agsPopupInfo = (ArcGISPopupInfo) popupInfo;
      Layer[] layers = mMapView.getLayers();
      for (Layer layer : layers) {
        if ((layer instanceof ArcGISFeatureLayer)
            && (layer.getUrl().compareToIgnoreCase(agsPopupInfo.getLayerUrl()) == 0)) {
          featureLayer = (ArcGISFeatureLayer) layer;
          return featureLayer;
        }
      }
    }

    return featureLayer;
  }
Exemplo n.º 9
0
        public void dispatchMessage(android.os.Message msg) {
          try {
            jsonArray = new JSONArray(jsonResult);
            points.clear();
            for (int i = 0; i < jsonArray.length(); i++) {
              Point startpt =
                  new Point(
                      StringToDouble(jsonArray.getJSONObject(i).getString("LONG1")),
                      StringToDouble(jsonArray.getJSONObject(i).getString("LAT"))); // 创建一个点对象
              points.add(startpt);
              Graphic startgp =
                  new Graphic(
                      startpt,
                      new PictureMarkerSymbol(
                          context.getResources().getDrawable(R.drawable.mark))); // 设置样式
              GetGraphicLayer(mapView).addGraphic(startgp);
              sx = sy = ex = ey = 0;
              SelectionView.this.invalidate();
            }
            final Callout callout = mapView.getCallout(); // 通过MapView获取Callout实例对象
            callout.setStyle(R.xml.callout_style); // 为Callout设置样式文件
            final View popView =
                ((Activity) context).getLayoutInflater().inflate(R.layout.pop_entinfo, null);
            mapView.setOnSingleTapListener(
                new OnSingleTapListener() {
                  private static final long serialVersionUID = 1L;

                  @Override
                  public void onSingleTap(float x, float y) {
                    int gapOldValue = 1000;
                    int currentIndex = -1;
                    for (int i = 0; i < points.size(); i++) {
                      Point targetPoint = mapView.toScreenPoint(points.get(i));
                      int gapValue =
                          (int)
                              ((x - targetPoint.getX()) * (x - targetPoint.getX())
                                  + (y - targetPoint.getY()) * (y - targetPoint.getY()));
                      if (gapOldValue > gapValue) {
                        currentIndex = i;
                        gapOldValue = gapValue;
                      }
                    }
                    callout.setMaxHeight(700);
                    callout.setMaxWidth(1500);
                    callout.hide();
                    callout.setOffset(0, -15); // 设置偏移量
                    try {
                      ((TextView) popView.findViewById(R.id.content))
                          .setText(
                              "公司名称 :"
                                  + jsonArray.getJSONObject(currentIndex).getString("NAME")
                                  + "\n"
                                  + "公司地址 :"
                                  + jsonArray.getJSONObject(currentIndex).getString("ADDRESS")
                                  + "\n"
                                  + "企业注册号 :"
                                  + jsonArray.getJSONObject(currentIndex).getString("ENROL"));
                      callout.show(points.get(currentIndex), popView); // 设置弹出窗显示的内容
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
          } catch (JSONException e) {
            e.printStackTrace();
          }
        }