Android Open Source - SmartNavi Kml Placemark






From Project

Back to project page SmartNavi.

License

The source code is released under:

Apache License

If you think the Android project SmartNavi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.osmdroid.bonuspack.kml;
/*ww  w.j  a v a 2  s.  c o  m*/
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.osmdroid.bonuspack.overlays.Marker;
import org.osmdroid.bonuspack.overlays.Polygon;
import org.osmdroid.bonuspack.overlays.Polyline;
import org.osmdroid.util.BoundingBoxE6;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Overlay;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * KML Placemark. Support the following Geometry: Point, LineString, and Polygon. 
 * @author M.Kergall
 */
public class KmlPlacemark extends KmlFeature implements Cloneable, Parcelable {
  
  /** the KML Geometry of the Placemark. Null if none. */
  public KmlGeometry mGeometry;

  /** constructs a Placemark of unknown Geometry */
  public KmlPlacemark(){
    super();
  }
  
  /**
   * constructs a Placemark with a Point Geometry.  
   * @param position position of the Point
   */
  public KmlPlacemark(GeoPoint position){
    this();
    mGeometry = new KmlPoint(position);
  }
  
  /** constructs a Placemark from a Marker, as a KML Point */
  public KmlPlacemark(Marker marker){
    this(marker.getPosition());
    mName = marker.getTitle();
    mDescription = marker.getSnippet();
    mVisibility = marker.isEnabled();
    //TODO: Style / IconStyle => transparency, hotspot, bearing. 
  }

  /** constructs a Placemark from a Polygon overlay, as a KML Polygon */
  public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc){
    this();
    mName = polygon.getTitle();
    mDescription = polygon.getSnippet();
    mGeometry = new KmlPolygon();
    mGeometry.mCoordinates = (ArrayList<GeoPoint>)polygon.getPoints();
    ((KmlPolygon)mGeometry).mHoles = (ArrayList<ArrayList<GeoPoint>>)polygon.getHoles();
    mVisibility = polygon.isEnabled();
    //Style:
    Style style = new Style();
    style.mPolyStyle = new ColorStyle(polygon.getFillColor());
    style.mLineStyle = new LineStyle(polygon.getStrokeColor(), polygon.getStrokeWidth());
    mStyle = kmlDoc.addStyle(style);
  }

  /** constructs a Placemark from a Polyline overlay, as a KML LineString */
  public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc){
    this();
    mName = "LineString - "+polyline.getNumberOfPoints()+" points";
    mGeometry = new KmlLineString();
    mGeometry.mCoordinates = (ArrayList<GeoPoint>)polyline.getPoints();
    mVisibility = polyline.isEnabled();
    //Style:
    Style style = new Style();
    style.mLineStyle = new LineStyle(polyline.getColor(), polyline.getWidth());
    mStyle = kmlDoc.addStyle(style);
  }

  /** GeoJSON constructor */
  public KmlPlacemark(JsonObject json){
    this();
    if (json.has("id"))
        mId = json.get("id").getAsString();
    JsonObject geometry = json.getAsJsonObject("geometry");
    if (geometry != null) {
      mGeometry = KmlGeometry.parseGeoJSON(geometry);
        }
    if (json.has("properties")){
      //Parse properties:
      JsonObject properties = json.getAsJsonObject("properties");
      Set<Map.Entry<String,JsonElement>> entrySet = properties.entrySet();
      for (Map.Entry<String,JsonElement> entry:entrySet){
        String key = entry.getKey();
        String value = entry.getValue().getAsString();
        if (key!=null && value!=null)
          setExtendedData(key, value);
      }
      //Put "name" property in standard KML format:
      if (mExtendedData!=null && mExtendedData.containsKey("name")){
        mName = mExtendedData.get("name");
        mExtendedData.remove("name");
      }
    }
  }
  
  @Override public BoundingBoxE6 getBoundingBox(){
    if (mGeometry != null)
      return mGeometry.getBoundingBox();
    else
      return null;
  }
  
  @Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlDocument kmlDocument){
    if (mGeometry != null)
      return mGeometry.buildOverlay(map, defaultStyle, styler, this, kmlDocument);
    else 
      return null;
  }
  
  @Override public void writeKMLSpecifics(Writer writer){
    if (mGeometry != null)
      mGeometry.saveAsKML(writer);
  }
  
  protected JsonObject geoJSONProperties(){
    try {
      JsonObject json = new JsonObject();
      if (mName != null){
        json.addProperty("name", mName);
      }
      if (mExtendedData != null){
        for (HashMap.Entry<String, String> entry : mExtendedData.entrySet()) {
          String name = entry.getKey();
          String value = entry.getValue();
          json.addProperty(name, value);
        }
      }
      return json;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }

  /** @return this as a GeoJSON object. */
  @Override public JsonObject asGeoJSON(boolean isRoot){
    JsonObject json = new JsonObject();
    json.addProperty("type", "Feature");
    if (mId != null)
      json.addProperty("id", mId);
    json.add("geometry", mGeometry.asGeoJSON());
    json.add("properties", geoJSONProperties());
    return json;
  }
  
  //Cloneable implementation ------------------------------------

  @Override public KmlPlacemark clone(){
    KmlPlacemark kmlPlacemark = (KmlPlacemark)super.clone();
    if (mGeometry != null)
      kmlPlacemark.mGeometry = mGeometry.clone();
    return kmlPlacemark;
  }
  
  //Parcelable implementation ------------
  
  @Override public int describeContents() {
    return 0;
  }

  @Override public void writeToParcel(Parcel out, int flags) {
    super.writeToParcel(out, flags);
    out.writeParcelable(mGeometry, flags);
  }
  
  public static final Parcelable.Creator<KmlPlacemark> CREATOR = new Parcelable.Creator<KmlPlacemark>() {
    @Override public KmlPlacemark createFromParcel(Parcel source) {
      return new KmlPlacemark(source);
    }
    @Override public KmlPlacemark[] newArray(int size) {
      return new KmlPlacemark[size];
    }
  };
  
  public KmlPlacemark(Parcel in){
    super(in);
    in.readParcelable(KmlGeometry.class.getClassLoader());
  }
}




Java Source Code List

com.ilm.sandwich.BuildConfig.java
com.ilm.sandwich.Config.java
com.ilm.sandwich.GoogleMapActivity.java
com.ilm.sandwich.Info.java
com.ilm.sandwich.MySupportMapFragment.java
com.ilm.sandwich.OsmMapActivity.java
com.ilm.sandwich.Settings.java
com.ilm.sandwich.Smartgeo.java
com.ilm.sandwich.StartChooser.java
com.ilm.sandwich.TouchableWrapper.java
com.ilm.sandwich.helferklassen.HttpRequests.java
com.ilm.sandwich.helferklassen.Locationer.java
com.ilm.sandwich.helferklassen.MapDownload.java
com.ilm.sandwich.helferklassen.MyItemizedOverlay.java
com.ilm.sandwich.helferklassen.PlacesAutoComplete.java
com.ilm.sandwich.helferklassen.PlacesTextSearch.java
com.ilm.sandwich.helferklassen.Rechnung.java
com.ilm.sandwich.helferklassen.SuggestionsAdapter.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.cachemanager.CacheManager.java
org.osmdroid.bonuspack.clustering.GridMarkerClusterer.java
org.osmdroid.bonuspack.clustering.MarkerClusterer.java
org.osmdroid.bonuspack.clustering.StaticCluster.java
org.osmdroid.bonuspack.kml.ColorStyle.java
org.osmdroid.bonuspack.kml.IconStyle.java
org.osmdroid.bonuspack.kml.KmlDocument.java
org.osmdroid.bonuspack.kml.KmlFeature.java
org.osmdroid.bonuspack.kml.KmlFolder.java
org.osmdroid.bonuspack.kml.KmlGeometry.java
org.osmdroid.bonuspack.kml.KmlGroundOverlay.java
org.osmdroid.bonuspack.kml.KmlLineString.java
org.osmdroid.bonuspack.kml.KmlMultiGeometry.java
org.osmdroid.bonuspack.kml.KmlPlacemark.java
org.osmdroid.bonuspack.kml.KmlPoint.java
org.osmdroid.bonuspack.kml.KmlPolygon.java
org.osmdroid.bonuspack.kml.LineStyle.java
org.osmdroid.bonuspack.kml.Style.java
org.osmdroid.bonuspack.location.FlickrPOIProvider.java
org.osmdroid.bonuspack.location.GeoNamesPOIProvider.java
org.osmdroid.bonuspack.location.GeocoderGisgraphy.java
org.osmdroid.bonuspack.location.GeocoderNominatimOld.java
org.osmdroid.bonuspack.location.GeocoderNominatim.java
org.osmdroid.bonuspack.location.NominatimPOIProvider.java
org.osmdroid.bonuspack.location.POI.java
org.osmdroid.bonuspack.location.PicasaPOIProvider.java
org.osmdroid.bonuspack.mapsforge.GenericMapView.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileModuleProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileSource.java
org.osmdroid.bonuspack.overlays.DefaultInfoWindow.java
org.osmdroid.bonuspack.overlays.ExtendedOverlayItem.java
org.osmdroid.bonuspack.overlays.FolderOverlay.java
org.osmdroid.bonuspack.overlays.GroundOverlay.java
org.osmdroid.bonuspack.overlays.InfoWindow.java
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.java
org.osmdroid.bonuspack.overlays.MapEventsOverlay.java
org.osmdroid.bonuspack.overlays.MapEventsReceiver.java
org.osmdroid.bonuspack.overlays.MarkerInfoWindow.java
org.osmdroid.bonuspack.overlays.Marker.java
org.osmdroid.bonuspack.overlays.Polygon.java
org.osmdroid.bonuspack.overlays.Polyline.java
org.osmdroid.bonuspack.routing.GoogleRoadManager.java
org.osmdroid.bonuspack.routing.MapQuestRoadManager.java
org.osmdroid.bonuspack.routing.OSRMRoadManager.java
org.osmdroid.bonuspack.routing.RoadLeg.java
org.osmdroid.bonuspack.routing.RoadManager.java
org.osmdroid.bonuspack.routing.RoadNode.java
org.osmdroid.bonuspack.routing.Road.java
org.osmdroid.bonuspack.utils.BonusPackHelper.java
org.osmdroid.bonuspack.utils.DouglasPeuckerReducer.java
org.osmdroid.bonuspack.utils.HttpConnection.java
org.osmdroid.bonuspack.utils.PolylineEncoder.java
org.osmdroid.bonuspack.utils.WebImageCache.java