Migration Guide
On December 5th, 2022 we released Mappedin JS v5. This release focuses on improving the developer experience by making methods more accessible, simplifying complex methods, and reducing code required. This short migration guide explains the steps needed to migrate from version 4.
- The SDK is available on NPM at https://www.npmjs.com/package/@mappedin/mappedin-js
- API reference on our Developer Portal at https://docs.mappedin.com/web-sdk-api/v5/latest/
Changes
MapView
One of the largest changes with this release is how we apply labels to the maps. In v5 of the SDK Flat Labels and Floating Labels have been moved into their own object, with their own methods.
Floating Labels
// Before
mapView.labelAllLocations();
// After
mapView.FloatingLabels.labelAllLocations();
Please see 'Floating Labels' for all additional methods.
FlatLabels
// Before
mapView.labelAllLocations({ flatLabel: true });
// After
mapView.FlatLabels.labelAllLocations();
Please see 'Flat Labels' for all additional methods.
mapView.setPolygonColor
- Now only accepts a
MappedinPolygonas an argument. Polygon ID is not longer available as an option textColoris no longer an accepted parameter
setPolygonColor( polygon: MappedinPolygon, color: string )
mapView.enableImageFlippingPolygon
- Now only accepts a
MappedinPolygonas an argument - Options object, with polygon ID and rotation, no longer accepted as an argument
enableImageFlippingForPolygon( polygon: MappedinPolygon )
mapView.getPolygonsAtCoordinate now accepts an options object instead of an explicit parameter for includeNonInteractive.
mapView.getPolygonsAtCoordinate(MappedinCoordinate, {
includeNonInteractive: boolean,
});
mapView.createTooltip has been seperated into two methods with breaking changes. createTooltip now has a parameter that accepts a html snippet, rather than defining it within an options object. It is to be used for static content with our default wrapper styling.
createCustomTooltip is to be used for custom content with no wrapper, as well as accepts a custom selector
// Before
createTooltip(node: MappedinNode | MappedinCoordinate, options: TCreateTextTooltipOptions | TCreateCustomInnerHTMLTooltipOptions | TCreateCustomTooltipOptions)
// After
createTooltip(nodeOrCoordinate: MappedinNode | MappedinCoordinate, contentHtml: string, options?: TCreateTooltipOptions);
createCustomTooltip(nodeOrCoordinate: MappedinNode | MappedinCoordinate, contentHtml: string, selector: string, options?: TCreateTooltipCommonOptions);
mapView.setState is now asynchronous
Events
E_SDK_EVENT.POLYGON_CLICKED and E_SDK_EVENT.NOTHING_CLICKED have been deprecated in favor of a single event E_SDK_EVENT.CLICK.
mapView.on(
E_SDK_EVENT.CLICK,
({ position, polygons, nearBlueDot }: TMapClickEvent) => {
console.log(
`POSITION: ${position}, POLYGONS: ${polygons}, BLUEDOT: ${nearBlueDot});
}
)
E_CAMERA_EVENT.TILT_CHANGED,E_CAMERA_EVENT.ROTATION_CHANGED,E_CAMERA_EVENT.ZOOM_CHANGED, E_CAMERA_EVENT.POSITION_CHANGED have been deprecated in favor of a single event E_CAMERA_EVENT.CHANGED.
mapView.Camera.on(E_CAMERA_EVENT.CHANGED, ({ tilt, rotation, zoom, position }) => {
console.log(`TILT: ${tilt}, ROTATION: ${rotation}, ZOOM: ${zoom}, POSITION: ${position}`);
});
Camera Controls
mapview.Camera.focusOnnow takes two parameterstargetsandoptionsrather than just an options object
// Before
mapview.Camera.focusOn(options: TFocusOnOptions);
// After
mapview.Camera.focusOn(
targets: TCameraTargets,
options?: TFocusOnCameraOptions & TCameraAnimationOptions);
mapView.Camera.translatenow has explicitdirectionanddistanceparameters
// Before
mapview.Camera.translate(options: TMoveCameraOptions);
// After
mapview.Camera.translate(
direction: E_CAMERA_DIRECTION,
distance: number,
options?: TCameraAnimationOptions);
pointsremoved fromTFocusOnTargetsforfocusOn()andanimateCamera(). Use aMappedinCoordinateinsteadmapview.Camera.set'spositionOptionsargument is now required instead of being optionalTAnimatePositionOptionshas been renamed toTCameraTransformTFocusOnTargetshas been renamed toTCameraTargets
Removed
Mapview
mapView.updateClosedStateForPolygonandmapView.openAllPolygonshas been removed from the SDKmapView.createThreeJSMarker,mapView.removeThreeJSMarker, andmapView.removeAllThreeJSMarkershave been removed from the SDKMapView.labelPolygon,MapView.removeLabel,MapView.removeAllLabelshas been removed
Events
GET_NEAREST_NODEhas been removed. UseGET_NEAREST_NODE_BY_SCREEN_COORDINATESinstead
Camera
controller.Camera.setTilt,controller.Camera.setRotation, andcontroller.Camera.setZoomhave all been removed. Usecontroller.Camera.setinsteadFOCUS_ON_LEGACYhas been removed. Instead, useFOCUS_ONTFocusOnOptionshas been removedTMoveCameraOptionshas been removed
Journeys
controller.drawJourneyandcontroller.createJourneyhas been removed. UseJourney.drawinsteadcontroller.clearJourneyhas been removed. UseJourney.clearinstead
BlueDot
controller.BlueDotStatehas been removed. UseonBlueDotStateChangedinsteadcontroller.createFonthas been removed. No alternative option availableENABLE_BEARINGevent has been removedGET_BLUE_DOT_IS_FOLLOWINGhas been removedSET_BLUE_DOT_IS_FOLLOWINGhas been removedgeolocationSourcehas been removed from the typeTEnableBlueDotOptions
Search
Mappedin.Searchhas been removed. UseOfflineSeachinstead