add MarkerLayer example

This commit is contained in:
Hannes Janetzek 2014-01-17 19:23:10 +01:00
parent ec7b7276c5
commit 143e981ad1
4 changed files with 89 additions and 1 deletions

View File

@ -38,6 +38,11 @@
android:label="@string/title_activity_map" >
</activity>
<activity
android:name="org.oscim.android.test.MarkerOverlayActivity"
android:label="@string/title_activity_map" >
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

View File

@ -0,0 +1,82 @@
/*
* Copyright 2014 Hannes Janetzek
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.android.test;
import java.util.ArrayList;
import java.util.List;
import org.oscim.android.MapActivity;
import org.oscim.android.MapView;
import org.oscim.android.canvas.AndroidGraphics;
import org.oscim.core.GeoPoint;
import org.oscim.layers.GenericLayer;
import org.oscim.layers.marker.ItemizedIconLayer;
import org.oscim.layers.marker.ItemizedIconLayer.OnItemGestureListener;
import org.oscim.layers.marker.MarkerItem;
import org.oscim.layers.marker.MarkerItem.HotspotPlace;
import org.oscim.layers.marker.MarkerSymbol;
import org.oscim.renderer.GridRenderer;
import android.os.Bundle;
import android.widget.Toast;
public class MarkerOverlayActivity extends MapActivity implements OnItemGestureListener<MarkerItem> {
MapView mMapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapView);
MarkerSymbol symbol = AndroidGraphics.makeMarker(getResources(),
R.drawable.marker_poi,
HotspotPlace.CENTER);
ItemizedIconLayer<MarkerItem> markerLayer =
new ItemizedIconLayer<MarkerItem>(mMap, new ArrayList<MarkerItem>(),
symbol, this);
mMap.getLayers().add(markerLayer);
List<MarkerItem> pts = new ArrayList<MarkerItem>();
for (double lat = -90; lat <= 90; lat += 5) {
for (double lon = -180; lon <= 180; lon += 5)
pts.add(new MarkerItem(lat + "/" + lon, "",
new GeoPoint(lat, lon)));
}
markerLayer.addItems(pts);
mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
mMap.setMapPosition(0, 0, 1);
}
@Override
public boolean onItemSingleTapUp(int index, MarkerItem item) {
Toast toast = Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT);
toast.show();
return true;
}
@Override
public boolean onItemLongPress(int index, MarkerItem item) {
return false;
}
}

View File

@ -37,6 +37,7 @@ public class Samples extends Activity {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples);
linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class));
}
private Button createButton(final Class<?> clazz) {