summaryrefslogtreecommitdiff
path: root/platform/android/src/annotation/multi_point.hpp
blob: e1152dfd60c1b332c4c2e834d45627e7c0d7b5ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <mbgl/util/noncopyable.hpp>
#include <jni/jni.hpp>

#include "../geometry/lat_lng.hpp"
#include "../java/util.hpp"

namespace mbgl {
namespace android {

class MultiPoint : protected mbgl::util::noncopyable {

protected:

  template <class Geometry>
  static Geometry toGeometry(JNIEnv& env, jni::Object<java::util::List> pointsList) {
      NullCheck(env, &pointsList);
      auto jarray = java::util::List::toArray<LatLng>(env, pointsList);
      NullCheck(env, &jarray);

      std::size_t size = jarray.Length(env);

      Geometry geometry;
      geometry.reserve(size);

      for (std::size_t i = 0; i < size; i++) {
          auto latLng = jarray.Get(env, i);
          NullCheck(env, &latLng);

          geometry.push_back(LatLng::getGeometry(env, latLng));

          jni::DeleteLocalRef(env, latLng);
      }

      jni::DeleteLocalRef(env, jarray);
      return geometry;
  }
};

} // namespace android
} // namespace mbgl