Search in sources :

Example 1 with AidlMapLayer

use of net.osmand.plus.views.layers.AidlMapLayer in project Osmand by osmandapp.

the class OsmandAidlApi method registerAddMapLayerReceiver.

private void registerAddMapLayerReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver addMapLayerReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            String layerId = intent.getStringExtra(AIDL_OBJECT_ID);
            String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
            if (mapActivity != null && layerId != null && packName != null) {
                ConnectedApp connectedApp = connectedApps.get(packName);
                if (connectedApp != null) {
                    AidlMapLayerWrapper layer = connectedApp.getLayers().get(layerId);
                    if (layer != null) {
                        OsmandMapLayer mapLayer = connectedApp.getMapLayers().get(layerId);
                        if (mapLayer != null) {
                            mapActivity.getMapView().removeLayer(mapLayer);
                        }
                        mapLayer = new AidlMapLayer(mapActivity, layer, connectedApp.getPack());
                        mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
                        connectedApp.getMapLayers().put(layerId, mapLayer);
                    }
                }
            }
        }
    };
    registerReceiver(addMapLayerReceiver, mapActivity, AIDL_ADD_MAP_LAYER);
}
Also used : Context(android.content.Context) WeakReference(java.lang.ref.WeakReference) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AidlMapLayer(net.osmand.plus.views.layers.AidlMapLayer) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with AidlMapLayer

use of net.osmand.plus.views.layers.AidlMapLayer in project Osmand by osmandapp.

the class ConnectedApp method registerMapLayers.

void registerMapLayers(@NonNull Context context) {
    OsmandApplication app = (OsmandApplication) context.getApplicationContext();
    OsmandMapTileView mapView = app.getOsmandMap().getMapView();
    for (AidlMapLayerWrapper layer : layers.values()) {
        OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
        if (mapLayer != null) {
            mapView.removeLayer(mapLayer);
        }
        mapLayer = new AidlMapLayer(context, layer, pack);
        mapView.addLayer(mapLayer, layer.getZOrder());
        mapLayers.put(layer.getId(), mapLayer);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) AidlMapLayer(net.osmand.plus.views.layers.AidlMapLayer)

Aggregations

AidlMapLayer (net.osmand.plus.views.layers.AidlMapLayer)2 OsmandMapLayer (net.osmand.plus.views.layers.base.OsmandMapLayer)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 WeakReference (java.lang.ref.WeakReference)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 MapActivity (net.osmand.plus.activities.MapActivity)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1