@Override
  public Node loadNode(Amenity n) {
    if (n.getId() % 2 == 1) {
      // that's way id
      return null;
    }
    long nodeId = n.getId() >> 1;

    //		EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
    Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId);

    Map<AmenityType, Map<String, String>> typeNameToTagVal =
        MapRenderingTypes.getDefault().getAmenityTypeNameToTagVal();
    AmenityType type = n.getType();
    String tag = type.getDefaultTag();
    String subType = n.getSubType();
    String val = subType;
    if (typeNameToTagVal.containsKey(type)) {
      Map<String, String> map = typeNameToTagVal.get(type);
      if (map.containsKey(subType)) {
        String res = map.get(subType);
        if (res != null) {
          int i = res.indexOf(' ');
          if (i != -1) {
            tag = res.substring(0, i);
            val = res.substring(i + 1);
          } else {
            tag = res;
          }
        }
      }
    }
    entity.putTag(tag, val);
    entity.putTag(OSMTagKey.NAME.getValue(), n.getName());
    entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours());

    // check whether this is node (because id of node could be the same as relation)
    if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
      return entity;
    }
    return null;
  }
예제 #2
0
  @Override
  public Node loadNode(Amenity n) {
    if (n.getId() % 2 == 1) {
      // that's way id
      return null;
    }
    long nodeId = n.getId() >> 1;
    try {
      String res =
          sendRequest(
              SITE_API + "api/0.6/node/" + nodeId,
              "GET",
              null,
              ctx.getString(R.string.loading_poi_obj) + nodeId,
              false); //$NON-NLS-1$ //$NON-NLS-2$
      if (res != null) {
        OsmBaseStorage st = new OsmBaseStorage();
        st.parseOSM(
            new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); // $NON-NLS-1$
        EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
        Node entity = (Node) st.getRegisteredEntities().get(id);
        entityInfo = st.getRegisteredEntityInfo().get(id);
        // check whether this is node (because id of node could be the same as relation)
        if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
          return entity;
        }
        return null;
      }

    } catch (IOException e) {
      log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$
      AccessibleToast.makeText(
              ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG)
          .show();
    } catch (SAXException e) {
      log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$
      AccessibleToast.makeText(
              ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG)
          .show();
    }
    return null;
  }