-
Notifications
You must be signed in to change notification settings - Fork 75
Add a clickable marker to map
mtehver edited this page Mar 6, 2013
·
2 revisions
You can add various kinds of objects to map: points, lines, polygons, even 3D models. Here we start with most common one: point marker which opens bubble/callout what we call Label when you click on it. For all map elements you need to define style for it. In case of markers the key element is bitmap image, usually png from application resources. Also you will see here how all the data in the map is organised as Layers. Here for Markers you need to define new overlay Layer (we use MarkerLayer for it) and add it to the MapView. Markers themselves are added to the MarkerLayer.
// define marker style (image, size, color)
Bitmap pointMarker = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.olmarker);
MarkerStyle markerStyle = MarkerStyle.builder().setBitmap(pointMarker).setSize(0.5f).setColor(Color.WHITE).build();
// define label what is shown when you click on marker
Label markerLabel = new DefaultLabel("San Francisco", "Here is a marker");
// define location of the marker, it must be converted to base map coordinate system
MapPos markerLocation = mapLayer.getProjection().fromWgs84(-122.416667f, 37.766667f);
// create layer and add object to the layer, finally add layer to the map.
// All overlay layers must be same projection as base layer, so we reuse it
MarkerLayer markerLayer = new MarkerLayer(mapLayer.getProjection());
markerLayer.add(new Marker(markerLocation, markerLabel, markerStyle, markerLayer));
mapView.getLayers().addLayer(markerLayer);
Marker size (here: 0.5, see setSize method) is in arbitrary map view units; and real visible size may vary, especially in 2.5D perspective.