コード例 #1
0
ファイル: GeoData.java プロジェクト: tvesalainen/mailblog
 public void writeRegionKeys(DS.CacheWriter cw, BoundingBox bb) {
   JSONObject json = new JSONObject();
   JSONArray jarray = new JSONArray();
   json.put("keys", jarray);
   for (Map.Entry<BoundingBox, List<Pair<BoundingBox, Key>>> entry : boxList.entrySet()) {
     if (bb.isIntersecting(entry.getKey())) {
       for (Pair<BoundingBox, Key> pair : entry.getValue()) {
         if (bb.isIntersecting(pair.getFirst())) {
           jarray.put(KeyFactory.keyToString(pair.getSecond()));
         }
       }
     }
   }
   for (Pair<GeoPt, Key> pair : locationList) {
     if (bb.isInside(pair.getFirst())) {
       jarray.put(KeyFactory.keyToString(pair.getSecond()));
     }
   }
   if (firstPlacemarkKey != null && bb.isIntersecting(placemarkBoundingBox)) {
     jarray.put(KeyFactory.keyToString(firstPlacemarkKey));
   }
   json.write(cw);
   cw.cache();
 }
コード例 #2
0
ファイル: GeoData.java プロジェクト: tvesalainen/mailblog
  public GeoData(DS ds) {
    Iterable<Entity> tracksIterable = ds.fetchTracks();
    Iterable<Entity> imageLocationsIterable = ds.fetchImageLocations();
    Iterable<Entity> blogLocationsIterable = ds.fetchBlogLocations();

    boxList = new HashMapList<>();
    Date lastBegin = null;
    for (Entity track : tracksIterable) {
      BoundingBox bbTrack = new BoundingBox(track);
      for (Entity trackSeq : ds.fetchTrackSeqs(track.getKey())) {
        BoundingBox bbTrackSeq = new BoundingBox(trackSeq);
        boxList.add(bbTrack, new Pair<BoundingBox, Key>(bbTrackSeq, trackSeq.getKey()));
        Date begin = (Date) trackSeq.getProperty(BeginProperty);
        if (lastBegin == null || lastBegin.before(begin)) {
          lastBegin = begin;
        }
      }
    }
    Iterable<Entity> placemarksIterable;
    if (lastBegin != null) {
      placemarksIterable = ds.fetchPlacemarks(lastBegin);
    } else {
      placemarksIterable = ds.fetchPlacemarks();
    }
    firstPlacemarkKey = null;
    placemarkBoundingBox = new BoundingBox();
    for (Entity placemark : placemarksIterable) {
      if (firstPlacemarkKey == null) {
        firstPlacemarkKey = placemark.getKey();
      }
      GeoPt location = (GeoPt) placemark.getProperty(LocationProperty);
      placemarkBoundingBox.add(location);
    }
    locationList = new ArrayList<>();
    for (Entity metadata : imageLocationsIterable) {
      GeoPt location = (GeoPt) metadata.getProperty(LocationProperty);
      if (location != null) {
        locationList.add(new Pair<>(location, metadata.getKey()));
      }
    }
    for (Entity blog : blogLocationsIterable) {
      GeoPt location = (GeoPt) blog.getProperty(LocationProperty);
      if (location != null) {
        locationList.add(new Pair<>(location, blog.getKey()));
      }
    }
  }