0.1.0 • Published 2 years ago

radicle-map v0.1.0

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

Radicle Map docs

Getting Started

  • git clone git@git.2020.dev:gm/radicle-leaflet.git
  • cd [directory]
  • npm install
  • npm run dev to view example in browser with live reload

To add to your project, include dist/radicleMap.js and dist/radicleMap.css in your HTML page, or import via bundler using import "dist/radicleMap.js or const Radicle = require("dist/radicleMap.js).

Simple Example

HTML:

    <script src="path/to/dist/radicleMap.js"></script>
    <div id="myMap"></div>

JAVASCRIPT:

const map = new Radicle.Map(
    "myMap",                    //Container ID into which to render the Map map (required)
    {                           //JavaScript object containing a map of options and callbacks
        onMapLoad: ()=> {}      //You SHOULD include an `onMapLoad` callback to avoid crashes
    }
)

map.cff.set(cff_array)          //Load in a client-farm-field array (as a JavaScript array of maps or the equivalent JSON string)

Full Example

See test.html and source files in the testAssets directory for a full example.

The Gist

Initialize a map

Initialize a map as demonstrated above. You should include an onMapLoad() callback in which you place all your mapping logic or set some "ready" flag; accessing the map before it is ready will cause the application to crash.

You can see a full list of options and callbacks for map initialization here. Many of these options can be changed on the fly by changing mapInstance.options.whatever or mapInstance.options.callbacks.whatever.

Useful actions

Camera control

ActionEffect
Camera controls (granular)For granular map control, use MapBox functions.
map.view.centerView([])Center the view on one or an array of Field instances.
map.view.setMapBearing(angle, smooth?)Set the map bearing to an angle. Boolean smooth defaults to true; disable snap to position.
map.view.getMapBearing()

Client/Farm/Field manipulation

|Action |Effect | |--- |--- f | |map.cff.set(cff_array) |Load in a client-farm-field array (as a JavaScript array of maps or the equivalent JSON string) | |map.cff.getField(uuid) |Return a field instance by UUID| |field.getZone(uuid) |Return a zone instance by UUID| |map.activeField |Return the currently-active field| |map.fieldList|| |map.fieldListUuids|| |map.fieldListNames|| |map.fieldListShortNames|| |map.clientList|| |map.activeClient|| |map.farmList|| |map.activeFarm||

Enabling Sampling View (setting active field) and getting sample data

ActionEffect
field.sampleMode.start()Manually start sample mode, activating the field
field.sampleMode.end()Manually end sample mode, deactivating the field
field.collection.updateStatus()Manually update field status and color coding (if it does not do so automatically)
field.collection.updateZoneStatuses()Manually update field zone statuses and color coding (if it does not do so automatically)
field.collection.setNumberAnalyzed(num)Manually set the number of analyzed samples.
field.collection.addAnalysisResults(samples)Manually add analysis results to a field as an array of JavaScript sample objects or the equivalent JSON.
[field|zone].collectionStatsGet a field or zone's collection stats
[field|zone].collectionDataGet a field or zone's collection data
map.setSamplingMode(mode)Change sampling mode view. Pass one of ["collection", "p", "k", "ph", "bph"].

Etc.

ActionEffect
zone.target(color)Target a specific zone by overriding its default color. Accepts color string ("variables.$primary"), rgb string ("rgb(0,255,0)"), or hex ("#00ff00")
zone.untarget(color)Remove target and restore color defaults