0.0.1-alpha โ€ข Published 4 years ago

wakecap-ol v0.0.1-alpha

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
4 years ago

wakecap-ol

Functional, composed, extended and react wrapper for OpenLayers

Version enter image description here CircleCI

๐Ÿคน Installation

npm install https://mezo@bitbucket.org/wakecapteam/wakecap-ol.git

๐ŸŽฏ Usage

You should have a basic knowledge about openlayers , basic concepts and how it works.

๐Ÿš€ Basic Usage that renders just a map canvas using osm raster layers.

	import React from 'react'
	import {Map} from 'wakecap-ol'
	import { fromLonLat } from  'ol/proj'

	function DemoMap(){
		return (
			<Map center={fromLonLat([15.124, 14.36])} zoom={4} type="osm" />
		)
	}

โšก Rendering a map with features

Currently available features are marker and polygon

	import React from 'react'
	import {Map, Marker, Polygon, Vector} from 'wakecap-ol'
	import { fromLonLat } from  'ol/proj'

	const polygonCoordinates = [[15.125, 14.36],
								[15.245, 14.46],
								[15.344, 14.66],
								[15.125, 14.36]]
	function DemoMap(){
		return (
			<Map center={fromLonLat([15.124, 14.36])} zoom={4} type="osm">
				<Vector>
					<Marker position={fromLonLat([15.124, 14.36])}/>
					<Polygon coordinates={fromLonLat(polygonCoordinates)} />
				</Vector>
			</Map>
		)
	}

Check the docs below for more props and available configurations.

๐Ÿ“ฆ Components:

Map

Map component props and options

proptyperequireddefault valueoptionsdescription
zoomnumberfalse31 - 16initial zoom level
centerCoordinatefalse[0, 0]center point
targetHTMLDivElementfalseinner divdiv for the map to render in
typestringfalseosmosm or imageRaster layer type

Vector

@see ol/layer/Vector

proptyperequireddefault valueoptionsdescription
sourceVectorSourcefalsenew VectorSource({})source of the vector @see ol/source/VectorSource
styleStylefalsenew Style({})Style of the vector layer

Image

One of the main purposes to create this library is to manage an image map with custom images and projection, so by default this layer applies a pixel projection extented with width and height provided to the component.

@see ol/layer/Image

proptyperequireddefault valueoptionsdescription
srcurltrueImage source
widthnumbertrueImage width
heightnumbertrueImage Height
zoomnumberfalse2minZoom - maxZoomzoom level
minZoomnumberfalse11 - 16min zoom level
maxZoomnumberfalse61 - 16max zoom level

Marker

OpenLayers dont have something called marker, but we use Point Feature as a marker here @see ol/geom/Point

proptyperequireddefault valueoptionsdescription
positionCoordinatetruePosition of the marker
colorstringfalsergba(35, 187, 245, 1)HEX or RGBA or color stringColor of the marker
iconurlfalsepngIf provided it applies as a marker image/icon and no other styles apply
strokenumberfalse2`number | stroke width around the marker
widthnumberfalse10numberwidth of the marker
isDraggablebooleanfalsefalsetrue or falseif you want to move the marker on the map
onDragEndfunctionfalsefunction(newPosition, oldPosition)Drag end handler

Polygon

@see ol/geom/Polygon

proptyperequireddefault valueoptionsdescription
coordinatesCoordinate[][]truePolygon Coordinates
colorstringfalsergba(35, 187, 245, 1)HEX or RGBA or color stringColor of the polygon fill
strokeColorstringfalseHEX or RGBA or color stringstroke color
strokeWidthnumberfalse2`number | stroke width around the marker
isDraggablebooleanfalsefalsetrue or falseif you want to move the marker on the map
onDragEndfunctionfalsefunction(coordinates)Drag end handler with new polygon coordinates
isEditablebooleanfalsefalsetrue or falseif you want to move the marker on the map
onEditEndfunctionfalsefunction(coordinates)Edit end handler with new polygon coordinates

Interctions

Draw

Should be wrapped in Vector component @see ol/interaction/Draw

proptyperequireddefault valueoptionsdescription
sourceVectorSourcefalsenew VectorSource({})source of the vector @see ol/source/VectorSource
typeGeometryTypefalsePolygonShape type
onDrawEndfunctionfalsefunction(feature, target)Draw end handler
allowUpdateDrawnFeaturesbooleanfalsefalsetrue or falseso you can update features after drawing
onDragEndfunctionfalsefunction(newPosition, oldPosition)Drag end handler if allowUpdateDrawnFeatures is enabled
onEditEndfunctionfalsefunction(coordinates)Edit end handler if allowUpdateDrawnFeatures is enabled

Tooltip

Wrap open layers features in Tooltip to show tooltip component on hovering the feature @see ol/overlay

proptyperequireddefault valueoptionsdescription
elementHTMLDivElementfalsedocument.createElement('div')Tooltip div container
childrenFeaturetrueFeature to show tooltip on
positionOverlayPositioningfalsecenter-leftbottom-left, bottom-center, bottom-right, center-left, center-center, center-right, top-left, top-center, top-right,Tooltip position
idstringfalseHTML ID for the tooltip
classNamestringol-tooltipClass name for the tooltip
coordinateCoordinatedefault coordinate for the tooltip to show

Popup

Wrap open layers features in Popup to show tooltip component on click the feature @see ol/overlay

Popup should have content or withComponent prop to render

proptyperequireddefault valueoptionsdescription
contentstringfalseContent to be shown in popup
withComponent(closePopup) => React.ReactComponentfalsefunction(closePopup)Class name for the popup
childrenFeaturetrueFeature to show popup on
idstringfalseHTML ID for the popup
classNamestringClass name for the popup

withPixelTransformation

TBD

๐Ÿ“‹ TODO

Components:

  • Layer
  • Popup
  • Overlay

Interactions:

  • Drag and drop
  • Modify
  • Translate

๐Ÿ“œ License

This library is created for WakeCap