Search in sources :

Example 1 with KmlPlacemark

use of org.osmdroid.bonuspack.kml.KmlPlacemark in project osmbonuspack by MKergall.

the class MapActivity method recordCurrentLocationInTrack.

void recordCurrentLocationInTrack(String trackId, String trackName, GeoPoint currentLocation) {
    // Find the KML track in the current KML structure - and create it if necessary:
    KmlTrack t;
    KmlFeature f = mKmlDocument.mKmlRoot.findFeatureId(trackId, false);
    if (f == null)
        t = createTrack(trackId, trackName);
    else if (!(f instanceof KmlPlacemark))
        // id already defined but is not a PlaceMark
        return;
    else {
        KmlPlacemark p = (KmlPlacemark) f;
        if (!(p.mGeometry instanceof KmlTrack))
            // id already defined but is not a Track
            return;
        else
            t = (KmlTrack) p.mGeometry;
    }
    // TODO check if current location is really different from last point of the track
    // record in the track the current location at current time:
    t.add(currentLocation, new Date());
    // refresh KML:
    updateUIWithKml();
}
Also used : KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark) KmlTrack(org.osmdroid.bonuspack.kml.KmlTrack) Date(java.util.Date)

Example 2 with KmlPlacemark

use of org.osmdroid.bonuspack.kml.KmlPlacemark in project osmbonuspack by MKergall.

the class MapActivity method createTrack.

KmlTrack createTrack(String id, String name) {
    KmlTrack t = new KmlTrack();
    KmlPlacemark p = new KmlPlacemark();
    p.mId = id;
    p.mName = name;
    p.mGeometry = t;
    mKmlDocument.mKmlRoot.add(p);
    // set a color to this track by creating a style:
    Style s = new Style();
    int color;
    try {
        color = Integer.parseInt(id);
        color = color % TrackColor.length;
        color = TrackColor[color];
    } catch (NumberFormatException e) {
        color = Color.GREEN - 0x20000000;
    }
    s.mLineStyle = new LineStyle(color, 8.0f);
    p.mStyle = mKmlDocument.addStyle(s);
    return t;
}
Also used : LineStyle(org.osmdroid.bonuspack.kml.LineStyle) Style(org.osmdroid.bonuspack.kml.Style) LineStyle(org.osmdroid.bonuspack.kml.LineStyle) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark) KmlTrack(org.osmdroid.bonuspack.kml.KmlTrack) KmlPoint(org.osmdroid.bonuspack.kml.KmlPoint) Paint(android.graphics.Paint) GeoPoint(org.osmdroid.util.GeoPoint)

Example 3 with KmlPlacemark

use of org.osmdroid.bonuspack.kml.KmlPlacemark in project osmbonuspack by MKergall.

the class OverpassAPIProvider method addInKmlFolder.

/**
 * Retrieve elements from url, and add them in a KML Folder, as KML Placemarks: Point, LineString, Polygon, or MultiGeometry.
 * @param kmlFolder KML folder in which elements will be added
 * @param url OverPass API url to retrieve elements.
 * Main requirements:<br>
 * - Content must be in JSON format<br>
 * - ways and relations must have the "geometry" element<br>
 * @return true if ok, false if technical error.
 */
public boolean addInKmlFolder(KmlFolder kmlFolder, String url) {
    Log.d(BonusPackHelper.LOG_TAG, "OverpassAPIProvider:addInKmlFolder:" + url);
    String jString = BonusPackHelper.requestStringFromUrl(url);
    if (jString == null) {
        Log.e(BonusPackHelper.LOG_TAG, "OverpassAPIProvider: request failed.");
        return false;
    }
    try {
        // parse JSON and build KML
        JsonParser parser = new JsonParser();
        JsonElement json = parser.parse(jString);
        JsonObject jResult = json.getAsJsonObject();
        JsonArray jElements = jResult.get("elements").getAsJsonArray();
        for (JsonElement j : jElements) {
            JsonObject jo = j.getAsJsonObject();
            KmlPlacemark placemark = new KmlPlacemark();
            placemark.mGeometry = buildGeometry(jo);
            placemark.mId = jo.get("id").getAsString();
            // Tags:
            if (jo.has("tags")) {
                JsonObject jTags = jo.get("tags").getAsJsonObject();
                if (jTags.has("name"))
                    placemark.mName = jTags.get("name").getAsString();
                // copy all tags as KML Extended Data:
                Set<Map.Entry<String, JsonElement>> entrySet = jTags.entrySet();
                for (Map.Entry<String, JsonElement> entry : entrySet) {
                    String key = entry.getKey();
                    String value = entry.getValue().getAsString();
                    placemark.setExtendedData(key, value);
                }
            }
            kmlFolder.add(placemark);
        }
        return true;
    } catch (JsonSyntaxException e) {
        Log.e(BonusPackHelper.LOG_TAG, "OverpassAPIProvider: parsing error.");
        return false;
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) KmlLineString(org.osmdroid.bonuspack.kml.KmlLineString) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark) Map(java.util.Map) JsonParser(com.google.gson.JsonParser)

Example 4 with KmlPlacemark

use of org.osmdroid.bonuspack.kml.KmlPlacemark in project osmbonuspack by MKergall.

the class KmlListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    KmlFeature item = (KmlFeature) getItem(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.kml_list_item, null);
    }
    TextView itemText = (TextView) convertView.findViewById(R.id.listItemTxt);
    itemText.setText(item.mName);
    // Handle checkbox:
    /*
        CheckBox checkBoxIsVisible = (CheckBox)convertView.findViewById(R.id.listItemCheckbox);
        checkBoxIsVisible.setChecked(mRoot.mItems.get(position).mVisibility);
        if (checkBoxIsVisible != null) {
	        checkBoxIsVisible.setOnClickListener(new OnClickListener(){
				@Override public void onClick(View view) {
					int position = (Integer)view.getTag();
					KmlFeature item = mRoot.mItems.get(position);
					item.mVisibility = ((CheckBox)view).isChecked();
				}
	        });
	        checkBoxIsVisible.setTag(position);
        }
        */
    ImageView img = (ImageView) convertView.findViewById(R.id.listItemImg);
    if (item instanceof KmlFolder) {
        img.setImageResource(R.drawable.moreinfo_arrow);
    } else if (item instanceof KmlPlacemark) {
        KmlGeometry geometry = ((KmlPlacemark) item).mGeometry;
        if (geometry instanceof KmlPoint)
            img.setImageResource(R.drawable.marker_kml_point);
        else if (geometry instanceof KmlLineString)
            img.setImageResource(R.drawable.kml_icon_linestring);
        else if (geometry instanceof KmlPolygon)
            img.setImageResource(R.drawable.kml_icon_polygon);
        else if (geometry instanceof KmlMultiGeometry)
            img.setImageResource(R.drawable.kml_icon_multigeometry);
        else if (geometry instanceof KmlTrack)
            img.setImageResource(R.drawable.kml_icon_gxtrack);
        else
            img.setImageDrawable(null);
    } else if (item instanceof KmlGroundOverlay) {
        img.setImageResource(R.drawable.kml_icon_groundoverlay);
    } else
        img.setImageDrawable(null);
    return convertView;
}
Also used : KmlPoint(org.osmdroid.bonuspack.kml.KmlPoint) KmlMultiGeometry(org.osmdroid.bonuspack.kml.KmlMultiGeometry) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) KmlGroundOverlay(org.osmdroid.bonuspack.kml.KmlGroundOverlay) LayoutInflater(android.view.LayoutInflater) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) TextView(android.widget.TextView) KmlGeometry(org.osmdroid.bonuspack.kml.KmlGeometry) ImageView(android.widget.ImageView) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark) KmlPolygon(org.osmdroid.bonuspack.kml.KmlPolygon) KmlLineString(org.osmdroid.bonuspack.kml.KmlLineString) KmlTrack(org.osmdroid.bonuspack.kml.KmlTrack)

Example 5 with KmlPlacemark

use of org.osmdroid.bonuspack.kml.KmlPlacemark in project osmbonuspack by MKergall.

the class MapActivity method addKmlPoint.

void addKmlPoint(GeoPoint position) {
    KmlFeature kmlPoint = new KmlPlacemark(position);
    mKmlDocument.mKmlRoot.add(kmlPoint);
    new KMLGeocodingTask().execute((KmlPlacemark) kmlPoint);
    updateUIWithKml();
}
Also used : KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark)

Aggregations

KmlPlacemark (org.osmdroid.bonuspack.kml.KmlPlacemark)5 KmlFeature (org.osmdroid.bonuspack.kml.KmlFeature)3 KmlTrack (org.osmdroid.bonuspack.kml.KmlTrack)3 KmlLineString (org.osmdroid.bonuspack.kml.KmlLineString)2 KmlPoint (org.osmdroid.bonuspack.kml.KmlPoint)2 Paint (android.graphics.Paint)1 LayoutInflater (android.view.LayoutInflater)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Date (java.util.Date)1 Map (java.util.Map)1 KmlFolder (org.osmdroid.bonuspack.kml.KmlFolder)1 KmlGeometry (org.osmdroid.bonuspack.kml.KmlGeometry)1 KmlGroundOverlay (org.osmdroid.bonuspack.kml.KmlGroundOverlay)1 KmlMultiGeometry (org.osmdroid.bonuspack.kml.KmlMultiGeometry)1