Tampilan maps android
- screens/Maps/MapsView2.tsx ### No Issue
This commit is contained in:
@@ -1,29 +1,25 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { StyleSheet, View } from "react-native";
|
import { Image, StyleSheet, View } from "react-native";
|
||||||
|
|
||||||
// Cek versi >= 10.x gunakan ini
|
// Cek versi >= 10.x gunakan ini
|
||||||
|
import API_IMAGE from "@/constants/api-storage";
|
||||||
|
import { MainColor } from "@/constants/color-palet";
|
||||||
|
import { apiMapsGetAll } from "@/service/api-client/api-maps";
|
||||||
import {
|
import {
|
||||||
MapView,
|
|
||||||
Camera,
|
Camera,
|
||||||
|
MapView,
|
||||||
PointAnnotation,
|
PointAnnotation,
|
||||||
Images,
|
|
||||||
ShapeSource,
|
|
||||||
SymbolLayer,
|
|
||||||
} from "@maplibre/maplibre-react-native";
|
} from "@maplibre/maplibre-react-native";
|
||||||
|
import { router, useFocusEffect } from "expo-router";
|
||||||
import {
|
import {
|
||||||
ButtonCustom,
|
|
||||||
DrawerCustom,
|
DrawerCustom,
|
||||||
DummyLandscapeImage,
|
DummyLandscapeImage,
|
||||||
Grid,
|
|
||||||
Spacing,
|
Spacing,
|
||||||
StackCustom,
|
StackCustom,
|
||||||
TextCustom,
|
TextCustom,
|
||||||
ViewWrapper,
|
Grid,
|
||||||
|
ButtonCustom,
|
||||||
} from "@/components";
|
} from "@/components";
|
||||||
import { apiMapsGetAll } from "@/service/api-client/api-maps";
|
|
||||||
import { router, useFocusEffect } from "expo-router";
|
|
||||||
import { Image } from "expo-image";
|
|
||||||
import API_IMAGE from "@/constants/api-storage";
|
|
||||||
import GridTwoView from "@/components/_ShareComponent/GridTwoView";
|
import GridTwoView from "@/components/_ShareComponent/GridTwoView";
|
||||||
import { ICON_SIZE_SMALL } from "@/constants/constans-value";
|
import { ICON_SIZE_SMALL } from "@/constants/constans-value";
|
||||||
import { openInDeviceMaps } from "@/utils/openInDeviceMaps";
|
import { openInDeviceMaps } from "@/utils/openInDeviceMaps";
|
||||||
@@ -31,6 +27,31 @@ import { FontAwesome, Ionicons } from "@expo/vector-icons";
|
|||||||
|
|
||||||
const MAP_STYLE = "https://tiles.openfreemap.org/styles/liberty";
|
const MAP_STYLE = "https://tiles.openfreemap.org/styles/liberty";
|
||||||
|
|
||||||
|
interface TypeMaps {
|
||||||
|
id: string;
|
||||||
|
isActive: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
namePin: string;
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
authorId: string;
|
||||||
|
portofolioId: string;
|
||||||
|
imageId: string;
|
||||||
|
pinId: string | null;
|
||||||
|
Portofolio: {
|
||||||
|
id: string;
|
||||||
|
namaBisnis: string;
|
||||||
|
logoId: string;
|
||||||
|
alamatKantor: string;
|
||||||
|
tlpn: string;
|
||||||
|
MasterBidangBisnis: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const defaultRegion = {
|
const defaultRegion = {
|
||||||
latitude: -8.737109,
|
latitude: -8.737109,
|
||||||
longitude: 115.1756897,
|
longitude: 115.1756897,
|
||||||
@@ -40,7 +61,7 @@ const defaultRegion = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function MapsView2() {
|
export default function MapsView2() {
|
||||||
const [list, setList] = useState<any[] | null>(null);
|
const [list, setList] = useState<TypeMaps[] | null>(null);
|
||||||
const [loadList, setLoadList] = useState(false);
|
const [loadList, setLoadList] = useState(false);
|
||||||
const [openDrawer, setOpenDrawer] = useState(false);
|
const [openDrawer, setOpenDrawer] = useState(false);
|
||||||
const [selected, setSelected] = useState({
|
const [selected, setSelected] = useState({
|
||||||
@@ -67,6 +88,7 @@ export default function MapsView2() {
|
|||||||
const response = await apiMapsGetAll();
|
const response = await apiMapsGetAll();
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
// console.log("[RESPONSE]", JSON.stringify(response.data, null, 2));
|
||||||
setList(response.data);
|
setList(response.data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -76,57 +98,51 @@ export default function MapsView2() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Data GeoJSON untuk marker
|
|
||||||
const markerData: GeoJSON.FeatureCollection = {
|
|
||||||
type: "FeatureCollection",
|
|
||||||
features: [
|
|
||||||
{
|
|
||||||
type: "Feature",
|
|
||||||
geometry: {
|
|
||||||
type: "Point",
|
|
||||||
coordinates: [115.1756897, -8.737109],
|
|
||||||
},
|
|
||||||
properties: { id: "1", title: "Lokasi A" },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "Feature",
|
|
||||||
geometry: {
|
|
||||||
type: "Point",
|
|
||||||
coordinates: [106.83, -6.18],
|
|
||||||
},
|
|
||||||
properties: { id: "2", title: "Lokasi B" },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<MapView style={styles.map} mapStyle={MAP_STYLE}>
|
<MapView style={styles.map} mapStyle={MAP_STYLE}>
|
||||||
<Camera
|
<Camera
|
||||||
zoomLevel={14}
|
zoomLevel={12}
|
||||||
centerCoordinate={[defaultRegion.longitude, defaultRegion.latitude]}
|
centerCoordinate={[defaultRegion.longitude, defaultRegion.latitude]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Images
|
{list?.map((item: TypeMaps) => {
|
||||||
images={{
|
const imageUrl = API_IMAGE.GET({ fileId: item.Portofolio.logoId });
|
||||||
customMarker: API_IMAGE.GET({
|
|
||||||
fileId: "cmcvppftd00t7bpnnnma0hfei",
|
return (
|
||||||
}),
|
<PointAnnotation
|
||||||
|
key={item.id}
|
||||||
|
id={item.id}
|
||||||
|
coordinate={[item.longitude, item.latitude] as [number, number]}
|
||||||
|
onSelected={() => {
|
||||||
|
setOpenDrawer(true);
|
||||||
|
setSelected({
|
||||||
|
id: item?.id,
|
||||||
|
bidangBisnis: item?.Portofolio?.MasterBidangBisnis?.name,
|
||||||
|
nomorTelepon: item?.Portofolio?.tlpn,
|
||||||
|
alamatBisnis: item?.Portofolio?.alamatKantor,
|
||||||
|
namePin: item?.namePin,
|
||||||
|
imageId: item?.imageId,
|
||||||
|
portofolioId: item?.Portofolio?.id,
|
||||||
|
latitude: item?.latitude,
|
||||||
|
longitude: item?.longitude,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onImageMissing={(imageKey) => console.log("Missing:", imageKey)}
|
>
|
||||||
|
<View style={styles.markerContainer}>
|
||||||
|
<Image
|
||||||
|
source={{ uri: imageUrl }}
|
||||||
|
style={styles.markerImage}
|
||||||
|
resizeMode="cover"
|
||||||
|
onError={(e: any) =>
|
||||||
|
console.log("Image error:", e.nativeEvent.error)
|
||||||
|
} // Tangkap error image
|
||||||
/>
|
/>
|
||||||
<ShapeSource id="markers-source" shape={markerData}>
|
</View>
|
||||||
<SymbolLayer
|
</PointAnnotation>
|
||||||
id="markers-layer"
|
);
|
||||||
style={{
|
})}
|
||||||
iconImage: "customMarker", // Nama alias dari Images
|
|
||||||
iconSize: 0.05, // Skala ukuran
|
|
||||||
iconAnchor: "bottom", // Titik anchor marker
|
|
||||||
iconAllowOverlap: true, // Marker tidak saling menyembunyikan
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ShapeSource>
|
|
||||||
</MapView>
|
</MapView>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -223,10 +239,21 @@ export default function MapsView2() {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: { flex: 1 },
|
container: { flex: 1 },
|
||||||
map: { flex: 1 },
|
map: { flex: 1 },
|
||||||
marker: {
|
markerContainer: {
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 30,
|
height: 30,
|
||||||
borderRadius: 100,
|
borderRadius: 100,
|
||||||
backgroundColor: "red",
|
overflow: "hidden", // Wajib agar borderRadius terapply pada Image
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: MainColor.darkblue, // Opsional, biar lebih cantik
|
||||||
|
elevation: 4, // Shadow Android
|
||||||
|
shadowColor: "#000", // Shadow iOS
|
||||||
|
shadowOffset: { width: 0, height: 2 },
|
||||||
|
shadowOpacity: 0.3,
|
||||||
|
shadowRadius: 3,
|
||||||
|
},
|
||||||
|
markerImage: {
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user