0.0.20 • Published 2 years ago

@akaribrahim/here-maps-drawing v0.0.20

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Status License


📝 Table of Contents

🧐 About

We can do simple operations using Here Maps Js API but it doesn't provide any drawing tools. The purpose of this library is to be able to draw shapes like polygons on Here Maps.

🏁 Installation

npm install @akaribrahim/here-maps-drawing

🎈 Usage

<HereMapContainer apiKey={hereApiKey}>
  {(mapObjects: MapObjects): JSX.Element => <PolygonDraw map={mapObjects.map} />}
</HereMapContainer>

🎈 Docs

KNOWN ISSUE: Components are having trouble working with StrictMode that comes with React 18 or later. It will run in the production environment, but you must disable StrictMode in the development environment.

HereMapContainer

With the onSuccess method, we can take the map, platform, ui, behavior objects and perform all the operations written in the HereMaps document.

DescriptionDefault ValueisRequired
apiKeyHereMaps Api KeynullYes
centerCenter coordinates to be given when the map is loaded{lat:41.03115 , lng: 29.00214}No
zoomZoom level when map is loaded9No
useEventsUse EventstrueNo
useUiUse UitrueNo
containerStylesStyle object of map container{height: 500, width: '100%'}No
resizeOnWidthChangeResize the map on window.resize eventtrueNo
mapLanguageMap Language'en-US'No
onSuccessCallback function returning map objects({map, platform, behavior, ui}) => {}No

PolygonDraw

With the onSuccess method, we can take the map, platform, ui, behavior objects and perform all the operations written in the HereMaps document.

DescriptionDefault ValueisRequired
mapCore Map ObjectnullYes
colorInstead of messing with the whole style from scratch, just changing the color (HEX)nullNo
drawingStylesStyles for each step, see DrawingStyles section for more detailsSee DrawingStylesNo
useShortcutsUse keyboard shortcut to help drawingtrueNo
shortcutsshortcut keysSee ShortcutKeysNo
onShortcutCallbackCallback that returns information when using a shortcut({keyCode, char}) => {}No
onSuccessCallback function, on polygon drawing finish(finalPolygon, mainGroup) => {}No
onPutCornerPointCallback function, on each corner point({ currentPointCount }) => {}No
onEdit(Coming Soon)Callback function, on polygon edited(finalPolygon, polygonIndex, mainGroup) => {}No
isResizable(Coming Soon)Final polygon resizable or nottrueNo

DrawingStyles

Default Values of drawingStyles as follows.

Icons must be in the form that H.map.Icon() will accept

drawingStyles: {
    firstIcon: rectangleSvg('#185CF7').trim(),
    icon: rectangleSvg().trim(),
    polylineStylesOnDraw: { // The line drawn around the polygon at the drawing stage
       lineWidth: 3,
       strokeColor: '#185CF7',
       lineJoin: 'round',
    },
    polygonStylesOnDraw: { // Polygon at the drawing stage
       lineWidth: 0,
       fillColor: 'rgba(24, 92, 247, 0.2)',
    },
    movingPolylineStyles: { // The line following mouse movements
       lineWidth: 3,
       strokeColor: '#185CF7',
       lineJoin: 'round',
       lineDash: [2],
       lineDashOffset: 1,
    },
    finalPolygonStyles: { // Polygon created in the final
       lineWidth: 3,
       strokeColor: '#185CF7',
       lineJoin: 'round',
       fillColor: 'rgba(24, 92, 247, 0.2)',
    },
}

ShortcutKeys

You can create shortcuts for three different events. Events only work during the polygon drawing phase

It can be customized by changing the keyCode and char values in the format given below.

Undo => Deletes the last point

Merge => Completes the polygon by connecting it with the first point

Cancel => Deletes the polygon in the drawing phase.

{
    undo: {
       keyCode: 85,
       char: 'U',
    },
    merge: {
       keyCode: 77,
       char: 'M',
    },
    cancel: {
       keyCode: 27,
       char: 'ESC',
    },
}

✍️ Authors

0.0.20

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.15

2 years ago

0.0.9

2 years ago

0.0.16

2 years ago

0.0.8

2 years ago

0.0.17

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago