Skip to content
Commits on Source (3)
{
"name": "@zandor300/react-apple-mapkitjs",
"version": "0.8.1",
"version": "0.9.0",
"description": "A react wrapper for apple mapkit.js",
"main": "lib/index.js",
"scripts": {
......
import React, { Component } from 'react'
import TokenManager from "./TokenManager"
import ColorScheme from "./ColorScheme";
import FeatureVisibility from "./FeatureVisibility";
import MapType from "./MapType";
class AppleMaps extends Component {
constructor(props) {
......@@ -10,7 +13,15 @@ class AppleMaps extends Component {
}
componentDidMount() {
const { children, initialMapType, token, colorScheme } = this.props
const {
children,
initialMapType,
token,
colorScheme,
showsCompass,
showsMapTypeControl,
showsZoomControl
} = this.props
TokenManager.getInstance().setToken(token)
......@@ -29,10 +40,31 @@ class AppleMaps extends Component {
// Set initial mapType
if(initialMapType !== undefined) {
this.map.mapType = initialMapType
if(!MapType.isOneOf(initialMapType)) {
console.error("Invalid initialMapType provided to AppleMaps component.")
} else {
this.map.mapType = initialMapType
}
}
if(colorScheme !== undefined) {
this.map.colorScheme = colorScheme
if(!ColorScheme.isOneOf(colorScheme)) {
console.error("Invalid colorScheme provided to AppleMaps component.")
} else {
this.map.colorScheme = colorScheme
}
}
if(showsCompass !== undefined) {
if(!FeatureVisibility.isOneOf(showsCompass)) {
console.error("Invalid showsCompass provided to AppleMaps component.")
} else {
this.map.showsCompass = showsCompass
}
}
if(showsMapTypeControl !== undefined) {
this.map.showsMapTypeControl = showsMapTypeControl
}
if(showsZoomControl !== undefined) {
this.map.showsZoomControl = showsZoomControl
}
// Annotations
......@@ -90,13 +122,33 @@ class AppleMaps extends Component {
width,
height,
autoAdjust,
colorScheme
colorScheme,
showsCompass,
showsMapTypeControl,
showsZoomControl
} = this.props
TokenManager.getInstance().setToken(token)
if(colorScheme !== prevProps.colorScheme) {
this.map.colorScheme = colorScheme
if(!ColorScheme.isOneOf(colorScheme)) {
console.error("Invalid colorScheme provided to AppleMaps component.")
} else {
this.map.colorScheme = colorScheme
}
}
if(showsCompass !== prevProps.showsCompass) {
if(!FeatureVisibility.isOneOf(showsCompass)) {
console.error("Invalid showsCompass provided to AppleMaps component.")
} else {
this.map.showsCompass = showsCompass
}
}
if(showsMapTypeControl !== prevProps.showsMapTypeControl) {
this.map.showsMapTypeControl = showsMapTypeControl
}
if(showsZoomControl !== prevProps.showsZoomControl) {
this.map.showsZoomControl = showsZoomControl
}
if((
......
const Light = "light"
const Dark = "dark"
const isOneOf = (value) => {
switch(value) {
case Light:
case Dark:
return true
default:
return false
}
}
export default {
Light,
Dark
Dark,
isOneOf
}
const Adaptive = "adaptive"
const Hidden = "hidden"
const Visible = "visible"
const isOneOf = (value) => {
switch(value) {
case Adaptive:
case Hidden:
case Visible:
return true
default:
return false
}
}
export default {
Adaptive,
Hidden,
Visible,
isOneOf
}
......@@ -3,9 +3,22 @@ const MutedStandard = "mutedStandard"
const Hybrid = "hybrid"
const Satellite = "satellite"
const isOneOf = (value) => {
switch(value) {
case Standard:
case MutedStandard:
case Hybrid:
case Satellite:
return true
default:
return false
}
}
export default {
Standard,
MutedStandard,
Hybrid,
Satellite
Satellite,
isOneOf
}
......@@ -2,5 +2,8 @@ export { default as AppleMaps } from './AppleMaps'
export { default as Annotation } from './Annotation'
export { default as ImageAnnotation } from './ImageAnnotation'
export { default as CurrentLocationOverride } from './CurrentLocationOverride'
export { default as MapType } from './MapType';
export { default as ColorScheme } from './ColorScheme';
// Enums
export { default as MapType } from './MapType'
export { default as ColorScheme } from './ColorScheme'
export { default as FeatureVisibility } from './FeatureVisibility'