0.1.6 • Published 6 years ago

nkm-mapbox-map v0.1.6

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

nkm Mapbox Map

Map component using mapbox gl js library.

Parameters

optionRequiredTypeDefaultDescription
accessTokenrequiredstringnonemapbox accessToken (talk to Keino)
styleUrlrequiredstringnonemapbox style url (talk to Keino for norkarts own style)
centerCoordsxobj{lat: 65.2, lng: 15.4 }center coordinates for the map
zoomLevelxnumber3.6zoom level for map
shouldFlyxbooleantrueIf map should have a smooth fly to effect when center coords are changed
pitchxnumber0Pitch (tilt) for map in degrees
bearingxnumber0Bearing (rotation) for map in degrees
fireMapResizexbooleanfalseFires a resize of the map that is necessary after changing size of container. Useful for implementing for example full screen.
layersxarray of objectsnoneList of valid mapbox geojson layers. See example below
interactivexbooleantrueIf map should be interactive or static
controlsxarray of objects with fields control and optionsnonea list of controls that should be added to the map, for example: {'control': this.draw, 'option': 'top-left'}
eventsxarray of objects with fields type and callbacknonea list of events that should be added to the map, for example: {'type': 'draw.create', 'callback': this._handleDrawUpdate};
onMapLoadedxfunctionnonecallback that is called once map is completed loading
onMoveendxfunctionnonecallback for when moveend event is fired, that returns a mapview object containing the new: center, zoom, pitch, bearing and bbox
onLayerDraggedxfunctionnonecallback for when map is unmounting that sends latlng on draggable layer so that you know the final position of the draggable point.
wmsLayersxarraynonewms layers to draw, with extra options as explained in example
fitBoundsxobjectnoneoption for fitting mapview to a bbox. Exp: fitBounds: {bounds:11.1422228114504, 60.2830018178217, 11.1676969648912, 60.2979382905685, padding: 20 }. Padding is optional, and default 0. NB! This will ignore other props concering mapview (i.e. centerCoords).

Valid mapbox geojson layer

'id': 'maine',
'type': 'fill',
'source': {
    'type': 'geojson',
    'data': {
        'type': 'Feature',
        'geometry': {
            'type': 'Polygon',
            'coordinates':
                [[[-67.13734351262877, 45.137451890638886],
                [-66.96466, 44.8097],
                [-68.03252, 44.3252]]]
        }
    }
},
'layout': {},
'paint': {
    'fill-color': '#088',
    'fill-opacity': 0.8
}

Draggable layer

If you want one of your layers to be draggable add draggable: true to properties in the geojson layer. NB! Only works on point layers

'id': 'maine',
'type': 'fill',
'source': {
    'type': 'geojson',
    'data': {
       ...
    }
},
'layout': {},
'properties' {
    draggable: true
}

If you want another layer to follow the draggable layer (i.e a polygon following a draggable point) add followDraggable: true to properties in the geojson layer

'id': 'maine',
'type': 'fill',
'source': {
    'type': 'geojson',
    'data': {
        ...
    }
},
'layout': {},
'properties' {
   followDraggable: true
}

wmsLayer

These are example options, but you can read more on mapbox docs.

optionRequiredTypeDefaultDescription
idxstringnoneunique identifier
urlxstringnoneurl for wms. Exp: https://openwms.statkart.no/skwms1/wms.vegnett?LAYERS=all&TRANSPARENT=TRUE&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG:3857&BBOX={bbox-epsg-3857}&WIDTH=256&HEIGHT=256
minZoomxnumbernoneminimale zoom for displaying the layer
maxZoomxnumbernonemaximum zoom for displaying the layer (NB! Hidden on giben maxZoom)
minZoom: PropTypes.number,
maxZoom: PropTypes.number,
url: PropTypes.string

Developing:


- run ```npm start```
- edit code in ```src/```

Deploying:


  1. Update version number in package.json
  2. npm publish

Testing


npm test