@Override
  public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    if (topic.equals("Likaci/MqttMap")) {
      String msg = new String(mqttMessage.getPayload());
      JSONObject json = new JSONObject(msg);
      if (!json.getString("id").equals(id)) {
        Point p =
            (Point)
                GeometryEngine.project(
                    new Point(json.getDouble("x"), json.getDouble("y")),
                    SpatialReference.create(4326),
                    SpatialReference.create(3857));

        layer.removeAll();

        SimpleMarkerSymbol markerSymbol =
            new SimpleMarkerSymbol(
                Color.parseColor("#763382"), 15, SimpleMarkerSymbol.STYLE.DIAMOND);
        layer.addGraphic(new Graphic(p, markerSymbol));

        TextSymbol textSymbol =
            new TextSymbol(
                15,
                json.getString("id"),
                Color.parseColor("#763382"),
                TextSymbol.HorizontalAlignment.CENTER,
                TextSymbol.VerticalAlignment.MIDDLE);
        textSymbol.setOffsetY(-15);
        layer.addGraphic(new Graphic(p, textSymbol));
      }
    }
  }
Пример #2
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);

  }