UNPKG

supermap

Version:

超图地理信息应用开发工具

102 lines (96 loc) 3.19 kB
/** * Created by will on 2016/6/17. */ import { NativeModules,DeviceEventEmitter } from 'react-native'; let MC = NativeModules.JSMapControl; import Map from './Map.js'; import Navigation2 from './Navigation2.js'; export default class MapControl{ static ACTION = { PAN:1, VERTEXADD:55, VERTEXDELETE:56, SELECT:8, VERTEXEDIT:54, CREATEPOINT:16, CREATEPOLYLINE:17, CREATEPOLYGON:27, } async getMap(){ try{ var {mapId} =await MC.getMap(this.mapControlId); var map = new Map(); map.mapId = mapId; return map; }catch(e){ console.error(e); } } async setAction(actionType){ try{ await MC.setAction(this.mapControlId,actionType); }catch(e){ console.error(e); } } async submit(){ try{ var submited = await MC.submit(this.mapControlId); return submited; }catch (e){ console.error(e); } } /** * 监听编辑行为的变更事件 * @param actionChange 编辑行为变更函数,回调事件参数:e:newAction,e:oldAction */ async addActionChangedListener(actionChange){ try{ DeviceEventEmitter.addListener('ActionChange', function(e) { actionChange && actionChange(e); }); if(typeof actionChange == "function"){ await MC.addActionChangedListener(this.mapControlId); }else{ throw new Error("addActionChangedListener need a callback function as first argument!"); } }catch (e){ console.error(e); } } /** * 监听导航事件 * @param longPressHandler 长按事件处理函数,回调事件参数: e:x,e:y,即长按点的屏幕坐标。 * @param scrollHandler 滑动事件处理函数 */ async setGestureDetector(longPressHandler,scrollHandler){ try{ DeviceEventEmitter.addListener('NavigationLongPress',function (e) { longPressHandler && longPressHandler(e); console.log("Long press excute!"); }); DeviceEventEmitter.addListener('NavigationScroll',function (e) { scrollHandler && scrollHandler(e); }); if(longPressHandler && scrollHandler){ await MC.setGestureDetector(this.mapControlId); console.log("GestrueDetector listening!"); }else{ throw new Error("setGestureDetector need callback functions as first two argument!"); } }catch (e){ console.error(e); } } async getNavigation2(){ try{ var {navigation2Id} = await MC.getNavigation2(this.mapControlId); var navigation2 = new Navigation2(); navigation2.navigation2Id = navigation2Id; return navigation2; }catch (e){ console.error(e); } } }