React Offline Maps
This module allows users to create maps without any internet connectivity - simply using overlays of images.
It makes use of svg-pan-zoom to display this map in a very user-friendly way.
Install
NPM
npm install --save react-offline-map
Props
Prop | Default | Type | Description |
---|---|---|---|
width | required | Number | Width of the viewer displayed on screen |
height | required | Number | Height of the viewer displayed on screen |
mapQuality | 'medium' | String | Creates a map of low, medium or high quality |
images | [] | Array | Images to be displayed on the screen |
text | [] | Array | Text to be displayed on the screen |
polylines | [] | Array | Polylines to be displayed on the screen |
circles | [] | Array | Circles to be displayed on the screen |
buttons | [] | Array | Buttons to be displayed on the screen |
polygons | [] | Array | Polygons to be displayed on the screen |
showWorldMap | true | bool | Decides whether background includes world map |
initialPos | {'lat': 0, 'lng': 0, 'zoom': 1} | Object | Sets the initial position of the viewer |
bounds | {'topLat': 90, 'topLng': -180, 'bottomLat': -90, 'bottomLng': 180} | Object | Sets the bounds for a viewer |
onClick | function | func | Allows a callback function. Returns Evt in form {lat: [latitude of click], lng: [longitude of click], evt: [mouseEvent] |
NOTE: all coordinates given in Lat/Long (UTM not accepted)
mapQuality
must be a string of value 'low', 'medium' or 'high'. No other options
images
in form:
[{'url': String, 'topLat': num, 'topLng', num, 'bottomLat', num, 'bottomLng': num], ..., ]
such that top left point of image is at coordinate {topLat, topLng},
bottom left of image is at coordinate {bottomLat, bottomLng}
polylines
in form:
[{'points': ["lat1,lng1", "lat2,lng2", lat3,lng3", ...], 'color': String, 'width': num}, ..., ]
where the first line will draw points between coordinates {lat1,lng1}, {lat2,lng2}, {lat3,lng3}, ...
circles
in form:
[{'lat': num, 'lng': num, 'r', num, 'fill', String]}, ..., ]
such that each circle is centred at coordinate {lat,lng} with radius r
polygon
in form:
[{'points': ["lat1,lng1", "lat2,lng2", lat3,lng3", ...], 'fill': String}, ..., ]
where the first polygon will draw points with coordinates {lat1,lng1}, {lat2,lng2}, {lat3,lng3}, ... and filled using fill color.
This is essentially the same as polyline, but the shape is filled.
buttons
in form:
[{'name': String, 'lat': num, 'lng', num, 'zoom', num]}, ..., ]
such that a button is created with title 'name' (same as {button.name}).
When clicked, button will jump the viewer to coordinate {lat,lng}, with zoom=button.zoom.
bounds
Helps with rendering if, for example, you only want to view a very small area on the map. Shows only a portion of the map.
Eg. If you just want to view UK, you would put bounds={{'topLat': 60, 'topLng': -15, 'bottomLat': 50, 'bottomLng': 5}}
NOTE: "top" and "bottom" refer to measurements at the top-left and bottom-right corners of an image respectively.
Therefore, although it may seem counter-intuitive, topLat > bottomLat and bottomLng > topLng.
In a normal map (default), top-right corner will be (90,-180) and bottom-right will be (-90,180) -- measurements in form (lat,long).
Therefore, default values are {'topLat': 90, 'topLng': -180, 'bottomLat': -90, 'bottomLng': 180}.
Examples of Use
Most Basic Implementation
; Component return <div> <Map width=800 height=600 /> </div> }
Advanced
;;;;;; Component { superprops; thisstate = showWorldMap: true } { this }; { console; console; }; { var images = 'url': mojave 'topLat': 35184619089603586 'topLng': -11619619200291318 'bottomLat': 35173016651002655 'bottomLng': -11618129480877964 'url': iraq 'topLat': 3361611111 'topLng': 4409638889 'bottomLat': 3301611111 'bottomLng': 4469638889 'url': sanfran 'topLat': 3828555556 'topLng': -12280972222 'bottomLat': 3728555556 'bottomLng': -12181000000 'url': baja 'topLat': 32533305 'topLng': -117123229 'bottomLat': 22837566 'bottomLng': -109396867 'url': bajaZoom 'topLat': 32533305 'topLng': -117123229 'bottomLat': 31981218 'bottomLng': -115213926 ; var averageLatMojave = 35184619089603586 + 35173016651002655 / 2; var averageLngMojave = -11619619200291318 + -11618129480877964 / 2; var averageLatIraq = 3361611111 + 3301611111 / 2; var averageLngIraq = 4409638889 + 4469638889 / 2; var averageLatSanFran = 3828555556 + 3728555556 / 2; var averageLngSanFran = -12280972222 + -12181000000 / 2; var averageLatBaja = 32533305 + 22837566 / 2; var averageLngBaja = -117123229 + -109396867 / 2; var averageLatBajaZoom = 32533305 + 31981218 / 2; var averageLngBajaZoom = -117123229 + -115213926 / 2; var buttons = 'name': 'Example Zoom 1: Baja (x10)' 'lat': averageLatBaja 'lng': averageLngBaja 'zoom': 10 'name': 'Example Zoom 2: Baja zoom (x100)' 'lat': averageLatBajaZoom 'lng': averageLngBajaZoom 'zoom': 100 'name': 'Example Zoom 3: San Francisco (x200)' 'lat': averageLatSanFran 'lng': averageLngSanFran 'zoom': 200 'name': 'Big zoom: Iraq (x400)' 'lat': averageLatIraq 'lng': averageLngIraq 'zoom': 400 'name': 'Extreme zoom: Mojave desert (x20000)' 'lat': averageLatMojave 'lng': averageLngMojave 'zoom': 20000 ; var circles = 'lat': 321322 'lng': -1163452 'r': 01 'fill': 'red' 'lat': 321022 'lng': -1157452 'r': 01 'fill': 'red' 'lat': 322722 'lng': -1158252 'r': 005 'fill': 'red' ; var polylines = 'points': '32.1322,-116.3452' '32.1022,-115.7452' '32.2722,-115.8252' '32.1322,-116.3452' 'color': 'blue' 'width': 005 'points': '35.177319,-116.194' '35.18,-116.192' '35.177319,-116.19' '35.18,-116.188' '35.177319,-116.186' 'color': 'blue' 'width': 000005 ; var polygons = 'points': '35.179319, -116.1834' '35.181319, -116.1834' '35.181319, -116.1854' '35.179319, -116.1854' 'fill': 'yellow' ; return <div className="App"> <button onClick=thisupdateMap>Toggle world map</button> <Map images=images width=windowinnerWidth * 09 height=windowinnerHeight * 09 buttons=buttons showWorldMap=thisstateshowWorldMap mapQuality='high' circles=circles polylines=polylines polygons=polygons handleClick=thisprintClick /> </div> ; } ;
Additions?
This is still a very new project, and there's many more features I could add if people feel they are necessary.
Feel free to open an issue with any bugs or enhancements you think I should work on!