@Override public void DeleteOrderReceived(String msg) { // {delete:fieldName=PlotID,fieldValue=xxxxxxx} int pos = msg.indexOf(":"); if (pos > msg.length() || pos < 0) return; String order = msg.substring(1, pos); msg = msg.substring(pos + 1); if (!order.equalsIgnoreCase("delete")) { return; } pos = msg.indexOf(","); if (pos > msg.length() || pos < 0) return; // fileName为fieldName=PlotID String fieldName = msg.substring(0, pos); msg = msg.substring(pos + 1); pos = fieldName.indexOf("="); if (pos > fieldName.length() || pos < 0) return; fieldName = fieldName.substring(pos + 1); if (!fieldName.equalsIgnoreCase("PlotID")) { return; } // fileValue为fieldValue=xxxxxxx} String fieldValue = msg.substring(0, msg.length() - 1); pos = fieldValue.indexOf("="); if (pos > fieldValue.length() || pos < 0) return; fieldValue = fieldValue.substring(pos + 1, msg.length() - 1); // 查处所有数据集对象,依次遍历找到PlotID值为fieldValue的对象,并删除???? DatasetVector dv = (DatasetVector) (mapShow .getMap() .getWorkspace() .getDatasources() .get("multimedia") .getDatasets() .get("CAD")); Recordset recordset = dv.getRecordset(false, CursorType.DYNAMIC); recordset.moveFirst(); while (!recordset.isEOF()) { String value = (String) recordset.getFieldValue(fieldName); if (value.equalsIgnoreCase(fieldValue)) { recordset.delete(); recordset.update(); break; } recordset.moveNext(); } recordset.close(); recordset.dispose(); }
/** * 增加查询结果 * * @param recordset */ public void addResult(Recordset recordset) { int count = recordset.getRecordCount(); if (recordset.getRecordCount() > 0) { boolean hasContain = false; for (int i = mResultData.size() - 1; i >= 0; i--) { if (mResultData.get(i).getDataset().getName().equals(recordset.getDataset().getName())) { hasContain = true; break; } } if (!hasContain) { mResultData.add(recordset); } } }
private void clearScreen() { if (m_popupMultiMedia != null) { m_popupMultiMedia.clearMultiMedia(); } // 获取当前编辑图层 Layer layer = mMapControl.getMap().getLayers().get(0); // 由图层获取关联数据集的记录集 Recordset rc = ((DatasetVector) layer.getDataset()).getRecordset(false, CursorType.DYNAMIC); // 编辑删除操作 rc.deleteAll(); // 更新记录集 rc.update(); // 清空动态层 m_locateDynamicView.clear(); mMapControl.getMap().refresh(); clearLists(); }
public void sendPlot() { Layer layerCAD = mMapControl.getMap().getLayers().get(0); Recordset record = ((DatasetVector) layerCAD.getDataset()).getRecordset(false, CursorType.DYNAMIC); record.moveFirst(); int failedCount = 0; // 记录发送失败的数据个数 while (!record.isEOF()) { String msg = "{content_type=2}"; String plotID = record.getFieldValue("PlotID").toString(); if (m_ArraySendedIDs.contains(plotID)) { record.moveNext(); continue; } msg += "{PlotID="; msg += plotID; msg += "}"; // 对象类型 GeometryType type = record.getGeometry().getType(); msg += "{type="; msg += type.value(); // type.toString(); msg += "}"; String geoJson = record.getGeometry().toXML(); msg += geoJson; boolean bOk = m_MessageQueue.sendMessageByType(msg, 2); if (bOk) { m_ArraySendedIDs.add(plotID); MyApplication.getInstance().showInfo("发送成功"); } else { failedCount++; } record.moveNext(); } record.dispose(); if (failedCount != 0) { MyApplication.getInstance().showInfo("发送失败" + failedCount + "个对象,请继续发送!"); } }
private void GeometrySelected(Recordset recordset, boolean bCAD) { if (recordset == null || recordset.getRecordCount() == 0) { return; } if (bCAD) { boolean bFrom = mapShow .getMap() .getLayers() .get("CAD@multimedia") .getSelection() .fromRecordset(recordset); System.out.println(bFrom); } else { mapShow .getMap() .getLayers() .get("MQDemo_MediaDataset@multimedia") .getSelection() .fromRecordset(recordset); // String mediaFilePath = MyApplication.SDCARD + // mapShow.getWorkspace().getDatasources().get("multimedia").getDatasets().get("MQDemo_MediaDataset").getDescription(); // String mediaFileName = (String)recordset.getFieldValue("MediaFileName"); // mediaFilePath += mediaFileName; // String strExtension; // int pos = mediaFileName.indexOf("."); // strExtension = mediaFileName.substring(pos + 1); // //// mediaFilePath = "/storage/emulated/0/SuperMap/MediaFiles/1440488164716.jpeg"; //// strExtension = "jpeg"; // Intent intent = new Intent(Intent.ACTION_VIEW); // Uri uri = Uri.fromFile(new File(mediaFilePath)); // // if(strExtension.equals("jpeg")){ // intent.setDataAndType(uri, "image/*"); // }else if(strExtension.equals("mp4")){ // intent.setDataAndType(uri, "video/*"); // }else { // intent.setDataAndType(uri, "audio/*"); // } // // getApplicationContext().startActivity(intent); } }
@Override public void PlotObjectsReceived(String msg) { // {PlotID=xxxxxxxxxx}xml int pos = msg.indexOf("}"); if (pos > msg.length() || pos < 0) return; String plotID = msg.substring(1, pos); msg = msg.substring(pos + 1); pos = plotID.indexOf("="); if (pos > msg.length() || pos < 0) return; plotID = plotID.substring(pos + 1); if (plotID.equalsIgnoreCase("0")) { return; } // 获取数据类型 {type=**} pos = msg.indexOf("}"); if (pos > msg.length() || pos < 0) return; String type = msg.substring(1, pos); msg = msg.substring(pos + 1); pos = type.indexOf("="); if (pos > type.length() || pos < 0) return; type = type.substring(pos + 1); GeometryType geometryType = (GeometryType) Enum.parse(GeometryType.class, Integer.parseInt(type)); Geometry geometry; if (geometryType == GeometryType.GEOGRAPHICOBJECT) { geometry = new GeoGraphicObject(); geometry.fromXML(msg); } else if (geometryType == GeometryType.GEOREGION) { geometry = new GeoRegion(); geometry.fromXML(msg); } else { geometry = new GeoLine(); geometry.fromXML(msg); } Layer layerCAD = mMapControl.getMap().getLayers().get(0); Recordset record = ((DatasetVector) layerCAD.getDataset()).getRecordset(false, CursorType.DYNAMIC); record.moveFirst(); String nodeName = "PlotID"; try { boolean bHasGeometry = false; while (!record.isEOF()) { String old = record.getFieldValue(nodeName).toString(); if (old.equalsIgnoreCase(plotID)) { record.edit(); record.setGeometry(geometry); record.update(); bHasGeometry = true; break; } record.moveNext(); } if (!bHasGeometry) { record.edit(); if (geometry.getType() == GeometryType.GEOLINE) { GeoStyle style = new GeoStyle(); style.setLineColor(new com.supermap.data.Color(127, 127, 127)); style.setFillForeColor(new com.supermap.data.Color(189, 235, 255)); style.setLineWidth(1.0); geometry.setStyle(style); } else if (geometry.getType() == GeometryType.GEOREGION) { GeoStyle style = new GeoStyle(); style.setLineColor(new com.supermap.data.Color(91, 89, 91)); style.setFillForeColor(new com.supermap.data.Color(189, 235, 255)); style.setLineWidth(1.0); geometry.setStyle(style); } record.addNew(geometry); record.setFieldValue(nodeName, plotID); record.update(); m_ArraySendedIDs.add(plotID); } } catch (Exception ex) { ex.printStackTrace(); } record.close(); record.dispose(); mMapControl.getMap().refresh(); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.consult_message: { mMapControl.submit(); mMapControl.setAction(Action.SELECT); mMapControl.getMap().refresh(); if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } m_nMessageCount = 0; btnNewMessage.setVisibility(4); showMessageList(v); } break; case R.id.message_switch: { if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } mMessageQueueOn = !mMessageQueueOn; if (!mMessageQueueOn) { btnMessageSwitch.setBackgroundResource(R.drawable.btn_message_switch_noselect); m_MessageQueue.suspend(); } else { btnMessageSwitch.setBackgroundResource(R.drawable.btn_message_switch_focused); m_MessageQueue.resume(); // 先去下载一次多媒体数据 if (m_popupMultiMedia == null) { // 多媒体列表初始化 m_popupMultiMedia = new MultiMediaPopup(btnMultiMedia.getRootView(), getApplicationContext(), this); // 设置多媒体工作空间 m_popupMultiMedia.setWorkspace(mapShow.getWorkspace(), mapShow.getBounds()); } } } break; case R.id.locate: { if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } m_StartPoint = m_TencentLocation.getGPSPoint(); if ((m_StartPoint.getX() == 0) || (m_StartPoint.getY() == 0)) { MyApplication.getInstance().showInfo("现在无法定位,请稍后再试!"); break; } // 导航纠偏 m_StartPoint = m_Navigation.encryptGPS(m_StartPoint.getX(), m_StartPoint.getY()); Point2D pt = mapShow.getPoint(m_StartPoint); if (pt == null) { MyApplication.getInstance().showInfo("现在无法定位,请稍后再试!"); break; } drawCircleOnDyn(pt, 0, m_TencentLocation.getAccuracy()); mapShow.panTo(pt); m_MapView.refresh(); } break; case R.id.multi_media: { mMapControl.submit(); mMapControl.setAction(Action.SELECT); mMapControl.getMap().refresh(); if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } showMultiMediaPopup(v); break; } case R.id.plot: { if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } mMapControl.submit(); mMapControl.setAction(Action.SELECT); mMapControl.getMap().refresh(); if (m_PlotTypePopup == null) { m_PlotTypePopup = new PlotTypePopup(mMapControl, btnPlot.getRootView(), this); } if (m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); mMapControl.setAction(Action.SELECT); } else { m_PlotTypePopup.show(v); } break; } case R.id.text_message: { mMapControl.submit(); mMapControl.setAction(Action.SELECT); mMapControl.getMap().refresh(); if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } if (!mMessageQueueOn) { MyApplication.getInstance().showInfo("请先打开消息开关!"); break; } if (m_popupTextMessage == null) { m_popupTextMessage = new TextMessagePopup(btnTextMessage.getRootView(), getApplicationContext(), this); } if (m_popupTextMessage.isShowing()) { m_popupTextMessage.dismiss(); } else { m_popupTextMessage.setFocusable(true); m_popupTextMessage.show(); } } break; case R.id.send_message: { mMapControl.submit(); mMapControl.setAction(Action.SELECT); mMapControl.getMap().refresh(); if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } if (!mMessageQueueOn) { MyApplication.getInstance().showInfo("请先打开消息开关!"); break; } sendPlot(); } break; case R.id.position_upload: { if (m_popupMultiMedia != null && m_popupMultiMedia.isShowing()) { m_popupMultiMedia.dismiss(); } if (m_PlotTypePopup != null && m_PlotTypePopup.isShowing()) { m_PlotTypePopup.dismiss(); } if (!mMessageQueueOn) { MyApplication.getInstance().showInfo("请先打开消息开关!"); break; } m_StartPoint = m_TencentLocation.getGPSPoint(); if ((m_StartPoint.getX() == 0) || (m_StartPoint.getY() == 0)) { MyApplication.getInstance().showInfo("现在无法定位,请稍后再试!"); break; } // 导航纠偏 m_StartPoint = m_Navigation.encryptGPS(m_StartPoint.getX(), m_StartPoint.getY()); String json = m_StartPoint.toJson(); String msg = "{content_type=0}" + json; boolean bOk = m_MessageQueue.sendMessageByType(msg, 0); if (bOk) { MyApplication.getInstance().showInfo("发送成功"); } else { MyApplication.getInstance().showInfo("发送失败,请重新发送!"); } } break; case R.id.delete: { if (m_layerSelected == null || m_IDSelected == -1) { break; } DatasetVector dataset = (DatasetVector) m_layerSelected.getDataset(); if (dataset != null && dataset.getName().equalsIgnoreCase("CAD")) { QueryParameter parameter = new QueryParameter(); parameter.setAttributeFilter("SmID=" + m_IDSelected); parameter.setCursorType(CursorType.DYNAMIC); Recordset recordset = dataset.query(parameter); recordset.moveFirst(); if (!recordset.isEmpty()) { String strPlotID = (String) recordset.getFieldValue("PlotID"); recordset.delete(); recordset.update(); String msg = "{content_type=5}"; msg += "{delete:feildName=PlotID,feildValue="; msg += strPlotID; msg += "}"; m_MessageQueue.sendMessageByRoutingKey(msg, "plot"); } recordset.close(); recordset.dispose(); } mMapControl.getMap().refresh(); mMapControl.setAction(Action.SELECT); m_IDSelected = -1; btnDelete.setVisibility(4); break; } case R.id.clear: { // 清空屏幕 clearScreen(); break; } default: { // mMapControl.getMap().refresh(); } } }
@Override public Object getItem(int index) { return mRecordset.getFieldValue(index); }
public RecordsetAdapter(Recordset recordset) { mRecordset = recordset; mFieldInfos = mRecordset.getFieldInfos(); point = mRecordset.getGeometry().getInnerPoint(); }
@Override public View getChildView( int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { TextView holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_queryresult_item, null); holder = (TextView) convertView.findViewById(R.id.tv_name); convertView.setTag(holder); } else { holder = (TextView) convertView.getTag(); } try { final Recordset recordset = mResultData.get(groupPosition); recordset.moveTo(childPosition); String fieldName = "Name"; // 这个字段一定存在 Geometry geometry = recordset.getGeometry(); if (geometry.getType() == GeometryType.GEOREGION) { fieldName = "SMID"; } // 得先找一下哪个字段合适 FieldInfos finfos = recordset.getFieldInfos(); for (int i = 0; i < finfos.getCount(); i++) { if ((finfos.get(i).getName().contains("name") || finfos.get(i).getName().contains("NAME")) && finfos.get(i).getType() == FieldType.TEXT) { fieldName = finfos.get(i).getName(); break; } } final Object obj = recordset.getFieldValue(fieldName); holder.setText(obj == null ? "null" : obj.toString()); convertView.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { recordset.moveTo(childPosition); Geometry geometry = recordset.getGeometry(); if (geometry.getType() == GeometryType.GEOREGION) { GeoStyle geostyle = new GeoStyle(); geostyle.setFillForeColor(new com.supermap.data.Color(255, 0, 0)); geostyle.setFillOpaqueRate(30); geostyle.setLineColor(new com.supermap.data.Color(180, 180, 200)); geostyle.setLineWidth(0.4); geometry.setStyle(geostyle); int index = mTrackingLayer.indexOf("dypt"); if (index >= 0) mTrackingLayer.remove(index); mTrackingLayer.add(geometry, "dypt"); mMapControl.getMap().refresh(); } if (geometry.getType() == GeometryType.GEOLINE) { GeoStyle geostyle = new GeoStyle(); geostyle.setLineColor(new com.supermap.data.Color(255, 0, 0)); geostyle.setLineWidth(1); geometry.setStyle(geostyle); int index = mTrackingLayer.indexOf("dypt"); if (index >= 0) mTrackingLayer.remove(index); mTrackingLayer.add(geometry, "dypt"); mMapControl.getMap().refresh(); } mDynView.clear(); mMapView.removeAllCallOut(); final CallOut calloutLocation = new CallOut(mMapView.getContext()); calloutLocation.setStyle(CalloutAlignment.BOTTOM); calloutLocation.setLocation( geometry.getInnerPoint().getX(), geometry.getInnerPoint().getY()); calloutLocation.setCustomize(true); // 设置自定义背景 ImageView imageView = new ImageView(mMapControl.getContext()); // 显示起点 imageView.setBackgroundResource(R.drawable.ic_btn_poi); calloutLocation.setContentView(imageView); calloutLocation.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { CallOut checkedCallOut = mMapView.getCallOut("POI"); if (checkedCallOut != null) return; CallOut callout = new CallOut(mMapView.getContext()); callout.setStyle(CalloutAlignment.LEFT); callout.setBackground(Color.WHITE, Color.WHITE); callout.setLocation( calloutLocation.getLocationX(), calloutLocation.getLocationY()); View calloutView = mInflater.inflate(R.layout.callout, null); TextView name = (TextView) calloutView.findViewById(R.id.tv_name); name.setText(obj == null ? "null" : obj.toString()); calloutView .findViewById(R.id.btn_close) .setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { mMapView.removeCallOut("POI"); mMapView.refresh(); } }); ListView list = (ListView) calloutView.findViewById(R.id.list_record); list.setAdapter(new RecordsetAdapter(recordset)); callout.setContentView(calloutView); mMapView.addCallout(callout, "POI"); mMapView.refresh(); } }); mMapView.addCallout(calloutLocation, "Locate"); mDynView.refresh(); mMapControl.panTo(geometry.getInnerPoint(), 300); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return convertView; }
@Override public Object getChild(int groupPosition, int childPosition) { Recordset recordset = mResultData.get(groupPosition); recordset.moveTo(childPosition); return recordset; }