Skip to content

Commit

Permalink
NEW FILTERS
Browse files Browse the repository at this point in the history
Jesús Calderón committed Apr 2, 2019
1 parent b5ae5e1 commit dd5d7b2
Showing 18 changed files with 212 additions and 146 deletions.
Binary file modified .gradle/4.10.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.10.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/4.10.1/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.10.1/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

217 changes: 108 additions & 109 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/assets/bicimad.geojson

Large diffs are not rendered by default.

127 changes: 91 additions & 36 deletions app/src/main/java/com/jeluchu/mapboxu/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -5,15 +5,13 @@ import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import android.widget.Toast
import androidx.annotation.NonNull
import androidx.annotation.RequiresApi
@@ -42,12 +40,10 @@ import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.plugins.building.BuildingPlugin
import com.mapbox.mapboxsdk.plugins.places.autocomplete.PlaceAutocomplete
import com.mapbox.mapboxsdk.plugins.places.autocomplete.model.PlaceOptions
import com.mapbox.mapboxsdk.style.expressions.Expression.eq
import com.mapbox.mapboxsdk.style.expressions.Expression.literal
import com.mapbox.mapboxsdk.style.layers.CircleLayer
import com.mapbox.mapboxsdk.style.layers.FillLayer
import com.mapbox.mapboxsdk.style.layers.PropertyFactory
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.layers.*
import com.mapbox.mapboxsdk.style.layers.Property.NONE
import com.mapbox.mapboxsdk.style.layers.Property.VISIBLE
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions
@@ -90,6 +86,8 @@ class MainActivity : AppCompatActivity(), OnMapReadyCallback, MapboxMap.OnMapCli
private val REQUEST_CODE_AUTOCOMPLETE = 1
private val PLACES_PLUGIN_SEARCH_RESULT_SOURCE_ID = "PLACES_PLUGIN_SEARCH_RESULT_SOURCE_ID"

// FILTER
private val listItems = arrayOf("Cámaras", "BiciMad", "Parking")

override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
@@ -124,6 +122,48 @@ class MainActivity : AppCompatActivity(), OnMapReadyCallback, MapboxMap.OnMapCli
R.id.searchPlace -> findPlace()
R.id.downloadMap -> {}
R.id.listPlace -> {}
R.id.filterLayer -> {
val builder = AlertDialog.Builder(this@MainActivity)
builder.setTitle("Choose item")
val checkedItem = 0 //this will checked the item when user open the dialog

val individualCamerasLayer: Layer = mapboxMap!!.style!!.getLayer("cameras")!!
val individualBiciMadLayer: Layer = mapboxMap!!.style!!.getLayer("bici")!!


builder.setSingleChoiceItems(listItems, checkedItem) { _, which ->

when (which) {
0 ->
{
individualCamerasLayer.setProperties(
visibility(VISIBLE)
)
individualBiciMadLayer.setProperties(
visibility(NONE)
)
}
1 ->
{

individualCamerasLayer.setProperties(
visibility(NONE)
)
individualBiciMadLayer.setProperties(
visibility(VISIBLE)
)

}
2 -> { }
}

}
builder.setPositiveButton("Done") { dialog, _ ->
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
}
R.id.pictureInPicture -> initPictureInPicture()
}
}
@@ -156,37 +196,16 @@ class MainActivity : AppCompatActivity(), OnMapReadyCallback, MapboxMap.OnMapCli

mapboxMap.addOnMapClickListener(this@MainActivity)

/*val geoJsonSource = GeoJsonSource(
"source-id", Feature.fromJson(
Point.fromLngLat(-3.7111951, 40.4074126).toString()
)
)
style.addSource(geoJsonSource)
val btm = BitmapFactory.decodeResource(this@MainActivity.resources, R.drawable.security_camera).scale(60, 60)
style.addImage("camera_id", btm)
val symbolLayer = SymbolLayer("layer-id", "source-id")
symbolLayer.withProperties(
PropertyFactory.iconImage("camera_id")
)
style.addLayer(symbolLayer) */

// LAYERS
cameraGeoJsonSource(style)
addPointsLayer(style)
}
}
addCameraPointsLayer(style)

private fun cameraGeoJsonSource(loadedMapStyle: Style) {
// Load data from GeoJSON file in the assets folder
loadedMapStyle.addSource(
GeoJsonSource(
"layer-id", loadJsonFromAsset("cameras.geojson")
)
)
biciMadGeoJsonSource(style)
addbiciMadPointsLayer(style)
}
}

/* ------------------------ LOAD JSON FROM ASSETS ----------------------------------- */
private fun loadJsonFromAsset(filename: String): String? {
return try {
val `is` = assets.open(filename)
@@ -203,7 +222,17 @@ class MainActivity : AppCompatActivity(), OnMapReadyCallback, MapboxMap.OnMapCli

}

private fun addPointsLayer(loadedMapStyle: Style) {
// CAMERA LAYER
private fun cameraGeoJsonSource(loadedMapStyle: Style) {
// Load data from GeoJSON file in the assets folder
loadedMapStyle.addSource(
GeoJsonSource(
"layer-id", loadJsonFromAsset("cameras.geojson")
)
)
}

private fun addCameraPointsLayer(loadedMapStyle: Style) {

val btm = BitmapFactory.decodeResource(this@MainActivity.resources, R.drawable.security_camera).scale(60, 60)
loadedMapStyle.addImage("camera_id", btm)
@@ -216,6 +245,32 @@ class MainActivity : AppCompatActivity(), OnMapReadyCallback, MapboxMap.OnMapCli

}

// BICIMAD LAYER
private fun biciMadGeoJsonSource(loadedMapStyle: Style) {
// Load data from GeoJSON file in the assets folder
loadedMapStyle.addSource(
GeoJsonSource(
"layer-bici-id", loadJsonFromAsset("bicimad.geojson")
)
)
}

private fun addbiciMadPointsLayer(loadedMapStyle: Style) {

val btm = BitmapFactory.decodeResource(this@MainActivity.resources, R.drawable.bikemad).scale(60, 60)
loadedMapStyle.addImage("bici_id", btm)

val symbolBiciLayer = SymbolLayer("bici", "layer-bici-id")
symbolBiciLayer.withProperties(
PropertyFactory.iconImage("bici_id")
)
symbolBiciLayer.setProperties(
visibility(NONE)
)
loadedMapStyle.addLayer(symbolBiciLayer)

}

/* ----------------------------------- PLUGINS -------------------------------------- */
private fun initBuildingPlugin(@NonNull loadedMapStyle: Style) {
buildingPlugin = mapboxMap?.let { BuildingPlugin(mapView, it, loadedMapStyle) }
Binary file added app/src/main/res/drawable/bikemad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_filter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="459"
android:viewportWidth="459" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M178.5,382.5h102v-51h-102V382.5zM0,76.5v51h459v-51H0zM76.5,255h306v-51h-306V255z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_navigation.xml
Original file line number Diff line number Diff line change
@@ -18,6 +18,11 @@
android:title="@string/listado"
android:icon="@drawable/ic_places"
app:showAsAction="ifRoom|withText"/>
<item
android:id="@+id/filterLayer"
android:title="@string/filtrado"
android:icon="@drawable/ic_filter"
app:showAsAction="ifRoom|withText"/>

<item
android:id="@+id/pictureInPicture"
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -36,5 +36,8 @@
además de ver el tráfico a tiempo real.
</string>
<string name="url_github">https://github.com/Jeluchu/mapboxU</string>
<string name="filtrado">Filtrado</string>

<string name="cero">0</string>

</resources>

0 comments on commit dd5d7b2

Please sign in to comment.