Git Product home page Git Product logo

react-native-maps-draw's Introduction

Hi, I'm Aliaksei!

I am a passionate, successful Cross-Platform Mobile Developer with more than 3 years of experience. I have hands-on experience in developing scalable and responsive mobile applications, using modern software design techniques. I love working in environments where my skills can be consistently challenged to not only improve but revolutionise products or services. Highly motivated individual driven by passions and dreams. A talented leader with unique ideas and a history of successful contributions in the field.

React Native Developer at Muse Group

A little more about me...

const profile = {
  stack: [React-Native, Flutter, Node.js],
  tools: [MobX, Redux, Redux-Saga, Styled-Components, Reanimated, i18next, Native Modules/Component, RESTApi/JSONApi, Swagger, Socket.IO],
  language: [Swift, Java, TypeScript]
  social: {
     LinkedIn: https://www.linkedin.com/in/dev-event
  }
}

I love connecting with different people so if you want to say hi, I'll be happy to meet you more! :)


react-native-maps-draw's People

Contributors

dev-event avatar stoicrounin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-maps-draw's Issues

Support for Clustering

hi @dev-event ,
great job btw is it possible to include clustering inside of this map package? have tried to modify it by forking and i got some typescript issue 🙏🏻 thank you.

Expo SDK 47: Problems caused by react-native-SVG version conflict 13.4 vs 13.6..

Error when instanciating maspdraw:

Invariant Violation: Tried to register two views with the same name RNSVGCircle, js engine: hermes

Cause seems: Expo 47 requires "react-native-svg": "13.4.0",
and
maps-draw requires "react-native-svg": "13.6.0"

upgrading expo breaks svg on some other libs. Can you provide a diffrent build that allows 13.4? Or shall we fork?

Thank you!

isDrawMode issue

I have set isDrawMode false in the initial load but still, the Canvas view is visible for the first time.

Polygon appears 200km underneath the area I selected

Hi,

Thanks for the great library,

When I draw my polygon, it doesn't appear at the same location when I release the draw, for example:

image
image

`export default ({route}) => {
const navigation = useNavigation();

const mapRef = useRef(null);

const initialPolygon = useRef({
polygons: [],
distance: 0,
lastLatLng: undefined,
initialLatLng: undefined,
centerLatLng: undefined,
});

const [modePolygon, setPolygonCreated] = useState(false);

const [isActiveDraw, setDrawMode] = useState(false);
const [isReady, setIsReady] = useState(false);

const [points, setPoints] = useState([]);

const [polygon, setPolygon] = useState(initialPolygon.current);

const handleMapReady = useCallback(
() => mapRef.current && setIsReady(true),
[],
);

const handleRemovePolygon = useCallback(() => {
setPolygon(initialPolygon.current);
setPolygonCreated(false);
}, []);

const handleClear = useCallback(() => {
setPolygon(initialPolygon.current);
setPolygonCreated(false);
setPoints([]);
}, []);

const handleCanvasEndDraw = useCallback((locations) => {
zoomCenterPolygon(locations.centerLatLng).then(() => {
setPolygon(locations);
setPolygonCreated(true);
});

setDrawMode((prevMode) => !prevMode);

}, []);

const zoomCenterPolygon = async (center) => {
if (!mapRef.current) {
return;
}
await mapRef.current.getCamera();
if (Platform.OS === 'ios') {
mapRef.current.animateCamera({
center: center,
});
}
if (Platform.OS === 'android') {
}
};

const onPressToContinue = () => {
try {
} catch (e) {
Alert.alert(e.message);
}
};

const hasMarkerClose = polygon.centerLatLng && (

);

const handlePolygon = useCallback(
(item, index) => ,
[polygon.polygons],
);

return (


<Header title={'Définissez la zone de votre manifestation'} />

{'Dessinez à la main les coutours de la zone de manifestation'}

  <MapView
    showsUserLocation
    ref={mapRef}
    style={{flex: 1}}
    points={points}
    widthLine={3}
    onEndDraw={handleCanvasEndDraw}
    isDrawMode={isActiveDraw}
    onMapReady={handleMapReady}
    onStartDraw={handleClear}
    createdPolygon={modePolygon}
    onChangePoints={setPoints}
    backgroundCanvas={'rgba(0, 0, 0, 0.0)'}>
    {isReady &&
      modePolygon &&
      polygon.polygons &&
      polygon.polygons.length > 0 && (
        <>
          {hasMarkerClose}
          {polygon.polygons.map(handlePolygon)}
        </>
      )}
  </MapView>

  {points.length > 0 && (
    <BottomButton
      style={styles.toContinueButton}
      title={'Continuer'}
      onPress={onPressToContinue}
    />
  )}
</View>

);
};
`

Thanks,

Théo

'MapView' refers to a value, but is being used as a type here. Did you mean 'typeof MapView'?

import 'react-native-gesture-handler';
import React, { useCallback, useMemo, useRef, useState } from 'react';
import {
  Image, StyleSheet, Text, TouchableOpacity, View
} from 'react-native';
import {
  IDrawResult, Marker, TouchPoint
} from './src';
import { MarkerLocation } from './src/assets';
import MapView from './src/maps/maps';
import AnimatedPolygon from './src/components/polygon/polygon';

const App: React.FC = () => {
  const mapRef = useRef<MapView>(null);

Draw canvas off when mapView is not full screen

I see in the canvas that the view box is set to the height and width of the device window. For use cases like ours where the map screen has a header/footer it causes the Polyline to appear away from the finger.

Here are some updates I made that tested well in my case:

canvas.tsx

import Svg, { Polyline } from 'react-native-svg';
import type { ICanvasProps } from './types';
import React, { FC } from 'react';

const Canvas: FC<ICanvasProps> = ({
    path,
    colorLine,
    widthLine,
    fillColorCanvas,
    containerSize,
}) => {
    return (
        <Svg
            height="100%"
            width="100%"
            viewBox={`0 0 ${containerSize.width} ${containerSize.height}`}
        >
            <Polyline
                fill={fillColorCanvas}
                stroke={colorLine}
                points={path}
                strokeWidth={widthLine}
            />
        </Svg>
    );
};

export default Canvas;

maps.tsx

import React, {
    useRef,
    RefObject,
    useCallback,
    forwardRef,
    useMemo,
    useState,
} from 'react';
import MapView from 'react-native-maps';
import { StyleSheet, useWindowDimensions, View } from 'react-native';
import { Canvas } from '../canvas';
import { GestureHandler } from '../gesture';
import type { IMapProps } from './types';
import {
    DEFAULT_ACTIVE_COLOR_LINE_WIDTH,
    DEFAULT_FILL_BACKGROUND_CANVAS,
    DEFAULT_BACKGROUND_VIEW_CANVAS,
    DEFAULT_INDEX_INITIAL_LAT_LNG,
    DEFAULT_CREATED_NEW_POLYGON,
    DEFAULT_ACTIVE_COLOR_LINE,
    DEFAULT_UNIT_DISTANCE,
    DEFAULT_DRAW_MODE,
} from './contstant';
import * as _GEO from 'geolib';
import type { ILocationProps } from './types';
import useValidator from '../hooks/use-validator';

export default forwardRef<MapView, IMapProps>((props, ref) => {
    useValidator(props);
    const {
        points,
        children,
        colorLine = DEFAULT_ACTIVE_COLOR_LINE,
        widthLine = DEFAULT_ACTIVE_COLOR_LINE_WIDTH,
        onEndDraw,
        isDrawMode = DEFAULT_DRAW_MODE,
        renderPath,
        onStartDraw,
        unitDistance = DEFAULT_UNIT_DISTANCE,
        onChangePoints,
        createdPolygon = DEFAULT_CREATED_NEW_POLYGON,
        fillColorCanvas = DEFAULT_FILL_BACKGROUND_CANVAS,
        styleViewGesture,
        backgroundCanvas = DEFAULT_BACKGROUND_VIEW_CANVAS,
        ...rest
    } = props;
    const internalRef = useRef<MapView>(null);
    const mapRef = (ref as RefObject<MapView>) || internalRef;
    const { width, height } = useWindowDimensions();
    const [containerSize, setContainerSize] = useState({ width, height });

    const containerStyle = useMemo(
        () => [
            { zIndex: 1, backgroundColor: backgroundCanvas },
            StyleSheet.absoluteFill,
            styleViewGesture,
        ],
        [backgroundCanvas, styleViewGesture],
    );

    const path = useMemo(
        () => points.map((item) => `${item.x},${item.y}`).join(' '),
        [points],
    );

    const calculatedCenterPolygon = (coordinates: ILocationProps[]) =>
        Promise.resolve(_GEO.getCenter(coordinates));

    const convertPointToCoordinates = useCallback(
        (polygons) => {
            if (polygons && polygons.length > 0) {
                calculatedCenterPolygon(polygons).then((centerLatLng) => {
                    if (onEndDraw && centerLatLng) {
                        const distance = _GEO.convertDistance(
                            _GEO.getPathLength(polygons),
                            unitDistance,
                        );
                        const initialLatLng = polygons[DEFAULT_INDEX_INITIAL_LAT_LNG];
                        const lastLatLng = polygons[polygons.length - 1];
                        onEndDraw({
                            polygons,
                            distance,
                            centerLatLng,
                            initialLatLng,
                            lastLatLng,
                        });
                    }
                });
            }
        },
        [onEndDraw, unitDistance],
    );

    const convertByPoint = useCallback(
        async (item) => await mapRef.current?.coordinateForPoint(item),
        [mapRef],
    );

    const handleEndDraw = useCallback(
        async (data) => {
            await Promise.all(data.map(convertByPoint)).then(convertPointToCoordinates);
        },
        [convertByPoint, convertPointToCoordinates],
    );

    const handleSetContainerSize = useCallback((event) => {   // <---Added this function to calculate size of View container
        setContainerSize({
            width: event.nativeEvent.layout.width,
            height: event.nativeEvent.layout.height,
        });
    }, []);

    const hasCanvas = useMemo(() => {
        return (
            <View style={containerStyle} onLayout={handleSetContainerSize}>
                <>
                    {renderPath ? (
                        renderPath(path)
                    ) : (
                        <Canvas
                            containerSize={containerSize} //  <--------- Passing to canvas here
                            path={path}
                            widthLine={widthLine}
                            colorLine={colorLine}
                            fillColorCanvas={fillColorCanvas}
                        />
                    )}

                    <GestureHandler
                        onEndTouchEvents={handleEndDraw}
                        onStartTouchEvents={onStartDraw}
                        onChangeTouchEvents={onChangePoints}
                    />
                </>
            </View>
        );
    }, [
        containerSize,
        handleSetContainerSize,
        path,
        widthLine,
        colorLine,
        renderPath,
        onStartDraw,
        handleEndDraw,
        containerStyle,
        onChangePoints,
        fillColorCanvas,
    ]);

    const hasMap = (
        <MapView scrollEnabled={!isDrawMode} ref={mapRef} {...rest}>
            {children}
        </MapView>
    );

    return (
        <>
            {hasMap}
            {!createdPolygon && hasCanvas}
        </>
    );
});

Just a suggestion, feel free to use or update as you want. Thanks!

JS USAGE

Can it be used with javascript

Error in Typescript project

Module '"@dev-event/react-native-maps-draw"' has no exported member 'Polygon'. Did you mean to use 'import Polygon from "@dev-event/react-native-maps-draw"' instead? ts

import MapView, {
  LatLng,
  MapEvent,
  Polygon,
  PROVIDER_GOOGLE,
  MAP_TYPES,
  Camera,
  Region,
  Marker,
} from '@dev-event/react-native-maps-draw';

TTouchPoint not a component of @dev-event/react-native-maps-draw.

import type {TTouchPoint} from "@dev-event/react-native-maps-draw"
TTouvhPoint is throwing an error:
Module '"@dev-event/react-native-maps-draw"' has no exported member 'TTouchPoint'. Did you mean to use 'import TTouchPoint from "@dev-event/react-native-maps-draw"'

unable to draw on map

I am using this library currently for android side, i have used the code of example given in documentation, it shows map but unable to draw anything. Please anyone help us resolve this issue.

Is the example complete for Android?

Hi there, i am doing some investigations into whether this library is going to work for our needs. I have copied the example code into our app and the map shows, however I can't seem to draw any polygons.

I also noticed that if modePolygon is set to false then I can't scroll around the map, or click on any other components on the screen, other than the draw on/off button.
I am just wondering if the example is complete for Android?

Cheers

Here's some more information in case it helps

react: 17.0.2
react-native-gesture-handler: 1.10.3
react-native-svg: 12.1.1
react-native-maps-draw: 0.1.4

Android Version: 11
Pixel 5, API 30 -- Emulated

Unable to draw

Successfully used your package but after tapping on Draw area button inside menu-card button turns green and also the states you handle onPress of Draw area button is handled properly but i think the issue is inside the HandlePolygon callback function that not renders the animated polygon.....

Draw event still occurs when "isDrawMode" = false

Issue:
I am using something close to the basic example shown. When I have 'isDrawMode" set to false and swipe on the map the line is still drawn.

Expected behavior:
When "isDrawMode" is set to false I would expect to be able to pan and zoom around the map, then toggle draw mode on when ready to create a polygon.

Is there another prop I am missing that needs to be used in conjunction with this one?

Thanks! Love the project and hope it's going well for you! First thing like it I have found for RN and much needed in my project.

Also, somewhat unrelated but the line being drawn is above and slightly to the right from where the press is happening, is this the expected behavior?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.