private FMMap mFMMap;
/**
* 加载地图数据
*/
private void openMap() {
FMMapView mapView = (FMMapView) findViewById(R.id.map_view);
mFMMap = mapView.getFMMap();
//打开Fengmap服务器上的地图数据10347
String mapId = "10347";
mFMMap.openMapById(mapId, true);
}
@Override
public void onBackPressed() {
if (mFMMap != null) {
mFMMap.onDestroy();
mFMMap = null;
}
super.onBackPressed();
this.finish();
}
private FMMap mFMMap;
/**
* 加载地图数据
*/
private void openMap() {
FMMapView mapView = (FMMapView) findViewById(R.id.map_view);
mFMMap = mapView.getFMMap();
mFMMap.setOnFMMapInitListener(this);
//打开Fengmap服务器上的地图数据10347
String mapId = "10347";
mFMMap.openMapById(mapId, true);
}
@Override
public void onMapInitSuccess(String path) {
setMultiDisplay();
}
/**
* 多层显示
*/
void setMultiDisplay() {
//多楼层显示地图,默认显示第一层
int[] showFloors = mFMMap.getMapGroupIds();
int focus = 0; //默认焦点层
mFMMap.setMultiDisplay(showFloors, focus, null); //设置楼层多层显示
}
/**
* 单层显示
*/
void setSingleDisplay() {
int groupId = mFMMap.getFocusGroupId();
int[] showFloors = {groupId};
int focus = 0; //默认焦点层
mFMMap.setMultiDisplay(showFloors, focus, null); //设置楼层单层层显示
}
@Override
public void onBackPressed() {
if (mFMMap != null) {
mFMMap.onDestroy();
mFMMap = null;
}
super.onBackPressed();
this.finish();
}
private FMMap mFMMap;
private FMTextLayer mTextLayer;
private FMImageLayer mImageLayer;
private FMLineLayer mLineLayer;
private FMLocationLayer mLocationLayer;
private FMPolygonLayer mPolygonLayer;
/**
* 加载地图数据
*/
private void openMap() {
FMMapView mapView = (FMMapView) findViewById(R.id.map_view);
mFMMap = mapView.getFMMap();
mFMMap.setOnFMMapInitListener(this);
//打开Fengmap服务器上的地图数据10347
String mapId = "10347";
mFMMap.openMapById(mapId, true);
}
@Override
public void onMapInitSuccess(String path) {
//地图焦点层
int groupId = mFMMap.getFocusGroupId();
//添加文字图层
mTextLayer = mFMMap.getFMLayerProxy().createFMTextLayer(groupId);
mFMMap.addLayer(mTextLayer);
//添加图片图层
mImageLayer = mFMMap.getFMLayerProxy().createFMImageLayer(groupId);
mFMMap.addLayer(mImageLayer);
//添加定位图层
mLocationLayer = mFMMap.getFMLayerProxy().getFMLocationLayer();
mFMMap.addLayer(mLocationLayer);
//添加线图层
mLineLayer = mFMMap.getFMLayerProxy().getFMLineLayer();
mFMMap.addLayer(mLineLayer);
//不规则图形图层
mPolygonLayer = mFMMap.getFMLayerProxy().createFMPolygonLayer(groupId);
mFMMap.addLayer(mPolygonLayer);
}
// 添加文字标注
private void addTextMarker() {
//文字标注所在地图坐标
FMMapCoord position = new FMMapCoord(1.296164E7, 4861845.0);
FMTextMarker textMarker = new FMTextMarker(position, "添加一个文字标注");
textMarker.setTextFillColor(Color.RED);
textMarker.setTextStrokeColor(Color.RED);
textMarker.setTextSize(30);
//设置文字偏移高度
textMarker.setFMTextMarkerOffsetMode(FMTextMarker.FMTextMarkerOffsetMode.FMNODE_CUSTOM_HEIGHT);
textMarker.setCustomOffsetHeight(5);
mTextLayer.addMarker(textMarker);
}
//添加图片标注
private void addImageMarker() {
//图片标注所在地图坐标
FMMapCoord position = new FMMapCoord(1.296164E7, 4861845.0);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
FMImageMarker imageMarker = new FMImageMarker(position, bitmap);
//设置图片宽高
imageMarker.setMarkerWidth(30);
imageMarker.setMarkerHeight(30);
//设置图片垂直偏离距离
imageMarker.setFMImageMarkerOffsetMode(FMImageMarker.FMImageMarkerOffsetMode.FMNODE_CUSTOM_HEIGHT);
imageMarker.setCustomOffsetHeight(5);
mImageLayer.addMarker(imageMarker); //添加图片标注
}
//添加定位标注
private void addLocationMarker() {
FMMapCoord position = new FMMapCoord(1.296164E7, 4861845.0);
FMLocationMarker locationMarker = new FMLocationMarker(mFMMap.getFocusGroupId(), position);
//设置定位点图片
locationMarker.setActiveImageFromRes(R.drawable.ic_launcher);
//设置定位图片宽高
locationMarker.setMarkerWidth(30);
locationMarker.setMarkerHeight(30);
mLocationLayer.addMarker(locationMarker);
}
//添加线
private void addLineMarker() {
//模拟线段的点数据
ArrayList<FMMapCoord> points = new ArrayList<FMMapCoord>() {
{
add(new FMMapCoord(12961602, 4861851.5, 56));
add(new FMMapCoord(12961625, 4861850.5, 56));
add(new FMMapCoord(12961625, 4861825.0, 56));
}
};
//线段的节点
ArrayList<FMSegment> segments = new ArrayList<>(1);
FMSegment segment = new FMSegment(mFMMap.getFocusGroupId(), points);
segments.add(segment);
FMLineMarker lineMarker = new FMLineMarker(segments);
mLineLayer.addMarker(lineMarker);
}
//添加多边形
private void addPolygonMarker() {
ArrayList<FMMapCoord> points = new ArrayList<FMMapCoord>() {
{
add(new FMMapCoord(1.2961583E7, 4861865.0, 0.0));
add(new FMMapCoord(1.2961644E7, 4861874.0, 0.0));
add(new FMMapCoord(1.2961680E7, 4861854.0, 0.0));
add(new FMMapCoord(1.2961637E7, 4861819.0, 0.0));
add(new FMMapCoord(1.2961590E7, 4861835.0, 0.0));
}
};
//创建PolygonMarker
FMPolygonMarker polygonMarker = new FMPolygonMarker(points);
polygonMarker.setGroupId(mFMMap.getFocusGroupId());
//设置偏移
polygonMarker.setFMPolygonMarkerOffsetMode(
FMPolygonMarker.FMPolygonMarkerOffsetMode.FMNODE_CUSTOM_HEIGHT);
polygonMarker.setCustomHeightOffset(5);
polygonMarker.setPolygonColor(Color.RED);
polygonMarker.setStrokeWidth(3f);
mPolygonLayer.addMarker(polygonMarker);
}
/**
* 添加圆
*/
private void addCircleMarker() {
FMMapCoord centerCoord = new FMMapCoord(1.296164E7, 4861845.0);//圆心坐标
float radius = 20f;//半径大小
int segments = 40;
FMPolygonMarker polygonMarker = new FMPolygonMarker(centerCoord, radius, segments);
polygonMarker.setGroupId(mFMMap.getFocusGroupId());
//设置偏移
polygonMarker.setFMPolygonMarkerOffsetMode(
FMPolygonMarker.FMPolygonMarkerOffsetMode.FMNODE_CUSTOM_HEIGHT);
polygonMarker.setCustomHeightOffset(5);
polygonMarker.setPolygonColor(Color.RED);
polygonMarker.setStrokeWidth(3f);
//添加圆形
mPolygonLayer.addMarker(polygonMarker);
}
@Override
public void onBackPressed() {
if (mFMMap != null) {
mFMMap.onDestroy();
mFMMap = null;
}
super.onBackPressed();
this.finish();
}
private FMMap mFMMap;
private FMSearchAnalyser mSearchAnalyser;
/**
* 加载地图数据
*/
private void openMap() {
FMMapView mapView = (FMMapView) findViewById(R.id.map_view);
mFMMap = mapView.getFMMap();
mFMMap.setOnFMMapInitListener(this);
//打开Fengmap服务器上的地图数据10347
String mapId = "10347";
mFMMap.openMapById(mapId, true);
}
@Override
public void onMapInitSuccess(String path) {
//得到搜索分析器
try {
mSearchAnalyser = FMSearchAnalyser.getFMSearchAnalyserByPath(path);
} catch (FileNotFoundException pE) {
pE.printStackTrace();
} catch (FMObjectException pE) {
pE.printStackTrace();
}
}
//根据类型搜索公共设施
void searchFacilityByType() {
//groupIds为地图楼层id集合
int[] groupIds = mFMMap.getMapGroupIds();
//查找type=170006公共设施
int type = 170006; //type为公共设施类型
FMSearchFacilityByTypeRequest request = new FMSearchFacilityByTypeRequest(groupIds, type);
ArrayList<FMSearchResult> results = mSearchAnalyser.executeFMSearchRequest(request);
for (FMSearchResult result : results) {
int eid = (int) result.get("eid");
int groupId = (int) result.get("groupId");
//返回公共设施坐标
FMMapCoord mapCoord = mSearchAnalyser.getFacilityCoord(groupId, eid);
}
}
//根据类型搜索模型
void searchModelByType() {
//groupIds为地图楼层id集合
int[] groupIds = mFMMap.getMapGroupIds();
//查找type=170000模型
int type = 170000; //type为模型类型
FMSearchModelByTypeRequest request = new FMSearchModelByTypeRequest(groupIds, type);
ArrayList<FMSearchResult> results = mSearchAnalyser.executeFMSearchRequest(request);
for (FMSearchResult result : results) {
String fid = (String) result.get("FID");
FMModel model = mFMMap.getFMLayerProxy().queryFMModelByFid(fid);
}
}
//根据关键字搜索模型
void searchModelByKeyword() {
//groupIds为地图楼层id集合
int[] groupIds = mFMMap.getMapGroupIds();
//查找蛋糕关键字模型
FMSearchModelByKeywordRequest request = new FMSearchModelByKeywordRequest(groupIds, "蛋糕");
//获取查询返回结果数据
ArrayList<FMSearchResult> results = mSearchAnalyser.executeFMSearchRequest(request);
for (FMSearchResult result : results) {
String fid = (String) result.get("FID");
FMModel model = mFMMap.getFMLayerProxy().queryFMModelByFid(fid);
}
}
@Override
public void onBackPressed() {
if (mFMMap != null) {
mFMMap.onDestroy();
mFMMap = null;
}
super.onBackPressed();
this.finish();
}
private FMMap mFMMap;
private FMLineLayer mLineLayer;
private FMNaviAnalyser mNaviAnalyser;
/**
* 加载地图数据
*/
private void openMap() {
FMMapView mapView = (FMMapView) findViewById(R.id.map_view);
mFMMap = mapView.getFMMap();
mFMMap.setOnFMMapInitListener(this);
//打开Fengmap服务器上的地图数据10347
String mapId = "10347";
mFMMap.openMapById(mapId, true);
}
@Override
public void onMapInitSuccess(String path) {
//得到路径分析器
try {
mNaviAnalyser = FMNaviAnalyser.getFMNaviAnalyserByPath(path);
} catch (FileNotFoundException pE) {
pE.printStackTrace();
} catch (FMObjectException pE) {
pE.printStackTrace();
}
//添加线图层
mLineLayer = mFMMap.getFMLayerProxy().getFMLineLayer();
mFMMap.addLayer(mLineLayer);
//模拟导航需要的起始点坐标和起始点楼层id
int stGroupId = 1;
FMMapCoord stCoord = new FMMapCoord(12961573.57171745, 4861851.492463955);
int endGroupId = 1;
FMMapCoord endCoord = new FMMapCoord(12961699.79823795, 4861826.46384646);
analyzeNavigation(stGroupId, stCoord, endGroupId, endCoord);
}
/**
* 根据起始点坐标和起始点楼层id,路径分析,并根据结果绘制路径线。
*
* @param stGroupId 起点层id
* @param stCoord 起点坐标
* @param endGroupId 终点层id
* @param endCoord 终点坐标
*/
void analyzeNavigation(int stGroupId, FMMapCoord stCoord, int endGroupId, FMMapCoord endCoord) {
int type = mNaviAnalyser.analyzeNavi(stGroupId, stCoord, endGroupId, endCoord,
FMNaviAnalyser.FMNaviModule.MODULE_SHORTEST);
if (type == FMNaviAnalyser.FMRouteCalcuResult.ROUTE_SUCCESS) {
ArrayList<FMNaviResult> results = mNaviAnalyser.getNaviResults();
// 构建线数据
ArrayList segments = new ArrayList<>();
for (FMNaviResult r : results) {
int groupId = r.getGroupId();
FMSegment s = new FMSegment(groupId, r.getPointList());
segments.add(s);
}
//添加LineMarker
FMLineMarker lineMarker = new FMLineMarker(segments);
mLineLayer.addMarker(lineMarker);
}
}