Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
app-FounderMap
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
常超
app-FounderMap
Commits
95981ce8
Commit
95981ce8
authored
Jul 12, 2020
by
Luosp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加地图绘制功能
parent
e914d4cf
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1208 additions
and
12 deletions
+1208
-12
app/src/main/java/cn/com/founder/arcgisserver/MainActivity.java
+5
-3
arcgislib/proguard-rules.pro
+3
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/ArcGisFounder.java
+43
-1
arcgislib/src/main/java/cn/com/founder/arcgislib/common/Variable.java
+3
-1
arcgislib/src/main/java/cn/com/founder/arcgislib/option/IOption.java
+6
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisClusterView.java
+2
-2
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisDrawView.java
+251
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisLocationView.java
+5
-5
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisMapView.java
+25
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawEntity.java
+65
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawLayer.java
+622
-0
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawView.java
+162
-0
arcgislib/src/main/res/values/colors.xml
+3
-0
arcgislib/src/main/res/values/dimens.xml
+1
-0
arcgislib/src/main/res/values/strings.xml
+12
-0
No files found.
app/src/main/java/cn/com/founder/arcgisserver/MainActivity.java
View file @
95981ce8
...
...
@@ -29,6 +29,7 @@ public class MainActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
naviBt
=
findViewById
(
R
.
id
.
bt_navi
);
naviBt
.
setVisibility
(
View
.
GONE
);
ArcGisBaseView
arcGisBaseView
=
findViewById
(
R
.
id
.
main_arc_gis_base_view
);
//集成Activity
...
...
@@ -52,10 +53,11 @@ public class MainActivity extends AppCompatActivity {
.
setDefaultArcGisLocation
()
//设置默认定位
.
setDefaultArcGisZoom
()
//设置默认缩放
.
setDefaultArcGisCompass
()
//设置默认罗盘
.
setOpenNavi
()
//开启导航
.
setOpenSearch
()
//开启搜索
//
.setOpenNavi()//开启导航
//
.setOpenSearch()//开启搜索
// .setOpenHotPots()//开启热力图
.
setOpenCluster
()
//开启聚合
// .setOpenCluster()//开启聚合
.
setOpenDraw
()
//开启绘制
.
createArcGisFounder
();
//创建ArcGisFounder地图实例
IArcGisZoomOption
iArcGisZoomOption
=
arcGisFounder
.
arcGisZoomOption
();
...
...
arcgislib/proguard-rules.pro
View file @
95981ce8
...
...
@@ -190,11 +190,14 @@
-keep class cn.com.founder.arcgislib.navi.option.
*
*{ *; }
-keep class cn.com.founder.arcgislib.cluster.listener.
*
*{ *; }
-keep class cn.com.founder.arcgislib.cluster.option.
*
*{ *; }
-keep class cn.com.founder.arcgislib.draw.listener.
*
*{ *; }
-keep class cn.com.founder.arcgislib.draw.option.
*
*{ *; }
-keep class cn.com.founder.arcgislib.hotpots.option.
*
*{ *; }
-keep class cn.com.founder.arcgislib.model.
*
*{ *; }
-keep class cn.com.founder.arcgislib.view.
*
*{ *; }
-keep class cn.com.founder.arcgislib.widget.
*
*{ *; }
-keep class cn.com.founder.arcgislib.widget.cluster.
*
*{ *; }
-keep class cn.com.founder.arcgislib.widget.draw.
*
*{ *; }
-keep class cn.com.founder.arcgislib.widget.navi.
*
*{ *; }
-keep class cn.com.founder.arcgislib.widget.popup.
*
*{ *; }
...
...
arcgislib/src/main/java/cn/com/founder/arcgislib/ArcGisFounder.java
View file @
95981ce8
...
...
@@ -18,6 +18,8 @@ import cn.com.founder.arcgislib.cluster.ArcGisCluster;
import
cn.com.founder.arcgislib.cluster.option.IArcGisClusterOption
;
import
cn.com.founder.arcgislib.compass.ArcGisCompass
;
import
cn.com.founder.arcgislib.compass.option.IArcGisCompassOption
;
import
cn.com.founder.arcgislib.draw.ArcGisDraw
;
import
cn.com.founder.arcgislib.draw.option.IArcGisDrawOption
;
import
cn.com.founder.arcgislib.hotpots.ArcGisHotPots
;
import
cn.com.founder.arcgislib.hotpots.option.IArcGisHotPotsOption
;
import
cn.com.founder.arcgislib.location.ArcGisLocation
;
...
...
@@ -35,6 +37,7 @@ import cn.com.founder.arcgislib.source.XFragmentSource;
import
cn.com.founder.arcgislib.utils.ToolUtil
;
import
cn.com.founder.arcgislib.view.ArcGisBaseView
;
import
cn.com.founder.arcgislib.view.ArcGisClusterView
;
import
cn.com.founder.arcgislib.view.ArcGisDrawView
;
import
cn.com.founder.arcgislib.view.ArcGisHotPotsView
;
import
cn.com.founder.arcgislib.view.ArcGisLocationView
;
import
cn.com.founder.arcgislib.view.ArcGisMapCompassView
;
...
...
@@ -175,6 +178,11 @@ public class ArcGisFounder implements IOption {
return
mArcGisFounderBuilder
.
mIArcGisClusterOption
;
}
@Override
public
IArcGisDrawOption
arcGisDrawOption
()
{
return
mArcGisFounderBuilder
.
mIArcGisDrawOption
;
}
/**
* 外面暴露ArcGisLib相关方法,利用builder模式
*/
...
...
@@ -229,6 +237,10 @@ public class ArcGisFounder implements IOption {
*/
private
ArcGisClusterView
mArcGisClusterView
;
/**
* {@link ArcGisDrawView}
*/
private
ArcGisDrawView
mArcGisDrawView
;
/**
* {@link IArcGisZoomOption}
*/
private
IArcGisZoomOption
mIArcGisZoomOption
;
...
...
@@ -253,10 +265,14 @@ public class ArcGisFounder implements IOption {
*/
private
IArcGisHotPotsOption
mIArcGisHotPotsOption
;
/**
* {@link IArcGis
HotPots
Option}
* {@link IArcGis
Cluster
Option}
*/
private
IArcGisClusterOption
mIArcGisClusterOption
;
/**
* {@link IArcGisDrawOption}
*/
private
IArcGisDrawOption
mIArcGisDrawOption
;
/**
* 地图网格背景
*/
private
int
mBackgroundGridColor
=
-
1
;
...
...
@@ -377,6 +393,15 @@ public class ArcGisFounder implements IOption {
}
/**
* @return 开启绘制功能,默认不开启
*/
public
ArcGisFounderBuilder
setOpenDraw
()
{
this
.
mArcGisDrawView
=
new
PreCustomView
(
this
).
getArcGisDrawView
();
this
.
mIArcGisDrawOption
=
new
PreCommonMapOption
(
this
).
defaultArcGisDrawOption
();
return
this
;
}
/**
* @return {@link PreArcGisFounder}
*/
public
ArcGisFounder
createArcGisFounder
()
{
...
...
@@ -457,6 +482,13 @@ public class ArcGisFounder implements IOption {
return
new
ArcGisClusterView
(
mArcGisFounderBuilder
.
mSource
.
getContext
(),
mArcGisFounderBuilder
.
mArcGisMapView
,
mArcGisFounderBuilder
.
mArcGisLocationView
);
}
/**
* @return {@link ArcGisDrawView}
*/
ArcGisDrawView
getArcGisDrawView
()
{
return
new
ArcGisDrawView
(
mArcGisFounderBuilder
.
mSource
.
getContext
(),
mArcGisFounderBuilder
.
mArcGisMapView
,
mArcGisFounderBuilder
.
mArcGisLocationView
);
}
}
/**
...
...
@@ -514,6 +546,10 @@ public class ArcGisFounder implements IOption {
mArcGisFounderBuilder
.
mArcGisBaseView
.
addView
(
mArcGisFounderBuilder
.
mArcGisClusterView
);
}
if
(
mArcGisFounderBuilder
.
mArcGisDrawView
!=
null
)
{
mArcGisFounderBuilder
.
mArcGisBaseView
.
addView
(
mArcGisFounderBuilder
.
mArcGisDrawView
);
}
if
(!
ToolUtil
.
isNetWorkAvailable
(
mArcGisFounderBuilder
.
mSource
.
getContext
()))
{
Toast
.
makeText
(
mArcGisFounderBuilder
.
mSource
.
getContext
(),
mArcGisFounderBuilder
.
mSource
.
getContext
().
getString
(
R
.
string
.
string_net
),
Toast
.
LENGTH_LONG
).
show
();
mArcGisFounderBuilder
.
mArcGisBaseView
.
setVisibility
(
View
.
GONE
);
...
...
@@ -582,6 +618,12 @@ public class ArcGisFounder implements IOption {
IArcGisClusterOption
defaultArcGisClusterOption
()
{
return
new
ArcGisCluster
(
mArcGisFounderBuilder
.
mArcGisClusterView
);
}
/**
* @return {@link IArcGisDrawOption}
*/
IArcGisDrawOption
defaultArcGisDrawOption
()
{
return
new
ArcGisDraw
(
mArcGisFounderBuilder
.
mArcGisDrawView
);
}
}
}
...
...
arcgislib/src/main/java/cn/com/founder/arcgislib/common/Variable.java
View file @
95981ce8
...
...
@@ -15,7 +15,9 @@ public class Variable {
TEXT
,
POINT
,
LINE
,
POLYGON
;
POLYGON
,
ORTHOGON
,
CIRCLE
;
}
public
static
enum
GraphType
{
LINE
,
...
...
arcgislib/src/main/java/cn/com/founder/arcgislib/option/IOption.java
View file @
95981ce8
...
...
@@ -2,6 +2,7 @@ package cn.com.founder.arcgislib.option;
import
cn.com.founder.arcgislib.cluster.option.IArcGisClusterOption
;
import
cn.com.founder.arcgislib.compass.option.IArcGisCompassOption
;
import
cn.com.founder.arcgislib.draw.option.IArcGisDrawOption
;
import
cn.com.founder.arcgislib.hotpots.option.IArcGisHotPotsOption
;
import
cn.com.founder.arcgislib.location.option.IArcGisLocationOption
;
import
cn.com.founder.arcgislib.navi.option.IArcGisNaviOption
;
...
...
@@ -52,5 +53,10 @@ public interface IOption {
*/
IArcGisClusterOption
arcGisClusterOption
();
/**
* 绘制操作
*/
IArcGisDrawOption
arcGisDrawOption
();
}
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisClusterView.java
View file @
95981ce8
...
...
@@ -252,7 +252,7 @@ public class ArcGisClusterView extends LinearLayout implements View.OnClickListe
isFirstCreate
=
false
;
if
(
mArcGisLocationView
!=
null
){
mArcGisLocationView
.
isUseCluster
=
true
;
mArcGisLocationView
.
preventClick
=
true
;
}
}
});
...
...
@@ -342,7 +342,7 @@ public class ArcGisClusterView extends LinearLayout implements View.OnClickListe
public
void
onSingleTap
(
MotionEvent
motionEvent
)
{
if
(
clusterLayer
==
null
){
if
(
mArcGisLocationView
!=
null
){
mArcGisLocationView
.
isUseCluster
=
false
;
mArcGisLocationView
.
preventClick
=
false
;
}
return
;
}
...
...
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisDrawView.java
0 → 100644
View file @
95981ce8
package
cn
.
com
.
founder
.
arcgislib
.
view
;
import
android.content.Context
;
import
android.util.AttributeSet
;
import
android.view.Gravity
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
import
androidx.annotation.Nullable
;
import
com.esri.arcgisruntime.mapping.view.MapView
;
import
cn.com.founder.arcgislib.R
;
import
cn.com.founder.arcgislib.common.Variable
;
import
cn.com.founder.arcgislib.widget.draw.DrawEntity
;
import
cn.com.founder.arcgislib.widget.draw.DrawLayer
;
import
cn.com.founder.arcgislib.widget.draw.DrawView
;
/**
* Copyright: 方正国际软件有限公司
* Author:luo_shaopeng
* Date:2020/7/3 10:42
* EMail:luo_shaopeng@founder.com.cn
* Description:绘制
*/
public
class
ArcGisDrawView
extends
LinearLayout
implements
View
.
OnClickListener
,
ArcGisMapView
.
MyTouchDrawListener
{
protected
static
ArcGisDrawView
instance
;
/**
* {@link Context}
*/
private
Context
mContext
;
/**
* 绘制根布局
*/
private
RelativeLayout
mDrawTotalLayout
;
/**
* 绘制图片布局
*/
protected
RelativeLayout
mDrawIvLayout
;
/**
* 绘制图片
*/
protected
ImageView
mDrawIv
;
/**
* 绘制操作内容
*/
private
LinearLayout
mDrawContentLayout
;
/**
* 绘制线
*/
private
LinearLayout
mDrawLineLayout
;
/**
* 绘制圆
*/
private
LinearLayout
mDrawCircleLayout
;
/**
* 绘制矩形
*/
private
LinearLayout
mDrawOrthogonLayout
;
/**
* 绘制多边形
*/
private
LinearLayout
mDrawPolygonLayout
;
/**
* 撤销
*/
private
LinearLayout
mDrawPrevLayout
;
/**
* 恢复
*/
private
LinearLayout
mDrawNextLayout
;
/**
* 清除
*/
private
LinearLayout
mDrawClearLayout
;
/**
* 完成
*/
private
LinearLayout
mDrawEndLayout
;
/**
* {@link ArcGisMapView}
*/
private
ArcGisMapView
mArcGisMapView
;
private
ArcGisLocationView
mArcGisLocationView
;
/**
* {@link MapView}
*/
private
MapView
mMapView
;
/**
* {@link DrawLayer}
*/
private
DrawView
mDrawView
;
private
Variable
.
DrawType
drawType
=
null
;
private
Variable
.
Measure
measureLengthType
=
Variable
.
Measure
.
M
;
private
Variable
.
Measure
measureAreaType
=
Variable
.
Measure
.
M2
;
public
ArcGisDrawView
(
Context
context
,
ArcGisMapView
arcGisMapView
,
ArcGisLocationView
arcGisLocationView
)
{
this
(
context
);
this
.
mContext
=
context
;
this
.
mArcGisMapView
=
arcGisMapView
;
this
.
mMapView
=
mArcGisMapView
.
getMapView
();
this
.
mArcGisLocationView
=
arcGisLocationView
;
if
(
mArcGisLocationView
!=
null
){
mArcGisLocationView
.
preventClick
=
true
;
}
arcGisMapView
.
setMyTouchDrawListener
(
this
);
mDrawView
=
new
DrawView
(
context
,
mMapView
);
}
private
ArcGisDrawView
(
Context
context
)
{
this
(
context
,
null
,
0
);
}
private
ArcGisDrawView
(
Context
context
,
@Nullable
AttributeSet
attrs
)
{
this
(
context
,
attrs
,
0
);
}
private
ArcGisDrawView
(
Context
context
,
@Nullable
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
inflate
(
context
,
R
.
layout
.
layout_draw
,
this
);
instance
=
this
;
mDrawTotalLayout
=
findViewById
(
R
.
id
.
draw_layout
);
mDrawIvLayout
=
findViewById
(
R
.
id
.
draw_iv_layout
);
mDrawIv
=
findViewById
(
R
.
id
.
draw_iv
);
mDrawContentLayout
=
findViewById
(
R
.
id
.
draw_content_layout
);
mDrawLineLayout
=
findViewById
(
R
.
id
.
draw_line_layout
);
mDrawCircleLayout
=
findViewById
(
R
.
id
.
draw_circle_layout
);
mDrawOrthogonLayout
=
findViewById
(
R
.
id
.
draw_orthogon_layout
);
mDrawPolygonLayout
=
findViewById
(
R
.
id
.
draw_polygon_layout
);
mDrawPrevLayout
=
findViewById
(
R
.
id
.
draw_prev_layout
);
mDrawNextLayout
=
findViewById
(
R
.
id
.
draw_next_layout
);
mDrawClearLayout
=
findViewById
(
R
.
id
.
draw_clear_layout
);
mDrawEndLayout
=
findViewById
(
R
.
id
.
draw_end_layout
);
mDrawIv
.
setOnClickListener
(
this
);
mDrawLineLayout
.
setOnClickListener
(
this
);
mDrawCircleLayout
.
setOnClickListener
(
this
);
mDrawOrthogonLayout
.
setOnClickListener
(
this
);
mDrawPolygonLayout
.
setOnClickListener
(
this
);
mDrawPrevLayout
.
setOnClickListener
(
this
);
mDrawNextLayout
.
setOnClickListener
(
this
);
mDrawClearLayout
.
setOnClickListener
(
this
);
mDrawEndLayout
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
if
(
view
.
getId
()
==
R
.
id
.
draw_iv
)
{
if
(
mDrawContentLayout
.
getVisibility
()
==
View
.
VISIBLE
)
{
mDrawContentLayout
.
setVisibility
(
View
.
GONE
);
}
else
{
mDrawContentLayout
.
setVisibility
(
View
.
VISIBLE
);
}
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_line_layout
)
{
//线
drawType
=
Variable
.
DrawType
.
LINE
;
mDrawView
.
endMeasure
();
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_circle_layout
)
{
//圆
drawType
=
Variable
.
DrawType
.
CIRCLE
;
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_orthogon_layout
)
{
//矩形
drawType
=
Variable
.
DrawType
.
ORTHOGON
;
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_polygon_layout
)
{
//多边形
drawType
=
Variable
.
DrawType
.
POLYGON
;
mDrawView
.
endMeasure
();
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_prev_layout
)
{
//撤销
boolean
hasPrev
=
mDrawView
.
prevDraw
();
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_next_layout
)
{
//恢复
boolean
hasNext
=
mDrawView
.
nextDraw
();
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_clear_layout
)
{
//清除
drawType
=
null
;
DrawEntity
draw
=
mDrawView
.
clearMeasure
();
}
else
if
(
view
.
getId
()
==
R
.
id
.
draw_end_layout
)
{
//完成
drawType
=
null
;
DrawEntity
draw
=
mDrawView
.
endMeasure
();
}
}
/**
* @param isShow boolean-是否显示绘制布局
* 默认显示
*/
public
void
setShowDrawLayout
(
boolean
isShow
)
{
if
(
isShow
)
{
mDrawTotalLayout
.
setVisibility
(
VISIBLE
);
}
else
{
mDrawTotalLayout
.
setVisibility
(
GONE
);
}
}
/**
* @param location {@link Variable.ViewLocation } DrawView显示位置
*/
public
void
setDrawViewLocation
(
Variable
.
ViewLocation
location
)
{
switch
(
location
)
{
case
LEFT_TOP:
mDrawIvLayout
.
setGravity
(
Gravity
.
LEFT
|
Gravity
.
TOP
);
break
;
case
RIGHT_TOP:
mDrawIvLayout
.
setGravity
(
Gravity
.
RIGHT
|
Gravity
.
TOP
);
break
;
case
CENTER:
mDrawIvLayout
.
setGravity
(
Gravity
.
CENTER
);
break
;
case
LEFT_BOTTOM:
mDrawIvLayout
.
setGravity
(
Gravity
.
LEFT
|
Gravity
.
BOTTOM
);
break
;
case
RIGHT_BOTTOM:
mDrawIvLayout
.
setGravity
(
Gravity
.
RIGHT
|
Gravity
.
BOTTOM
);
break
;
}
}
/**
* @param drawImage int(资源ID)-绘制图片
*/
public
void
setDrawImage
(
int
drawImage
)
{
mDrawIv
.
setImageDrawable
(
getResources
().
getDrawable
(
drawImage
));
}
@Override
public
void
onMapSingleTapUp
(
MotionEvent
e
)
{
if
(
drawType
==
Variable
.
DrawType
.
LINE
)
{
mDrawView
.
startMeasuredLength
(
e
.
getX
(),
e
.
getY
());
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
mDrawView
.
startMeasuredArea
(
e
.
getX
(),
e
.
getY
());
}
else
if
(
drawType
==
Variable
.
DrawType
.
CIRCLE
){
mDrawView
.
drawCircle
(
e
.
getX
(),
e
.
getY
());
}
else
if
(
drawType
==
Variable
.
DrawType
.
ORTHOGON
){
mDrawView
.
drawBox
(
e
.
getX
(),
e
.
getY
());
}
}
}
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisLocationView.java
View file @
95981ce8
...
...
@@ -223,9 +223,9 @@ public class ArcGisLocationView extends LinearLayout implements View.OnClickList
private
double
distance
=
0.1
;
/**
*
使用聚合时使用此字段
*
阻止点击
*/
protected
boolean
isUseCluster
=
false
;
protected
boolean
preventClick
=
false
;
public
ArcGisLocationView
(
Context
context
,
ArcGisMapView
arcGisMapView
)
{
this
(
context
);
...
...
@@ -1061,7 +1061,7 @@ public class ArcGisLocationView extends LinearLayout implements View.OnClickList
@Override
public
void
onUp
(
Variable
.
TouchUp
touchUp
,
MotionEvent
motionEvent
)
{
if
(
isUseCluster
)
if
(
preventClick
)
return
;
if
(
touchUp
==
Variable
.
TouchUp
.
UP
&&
mFollowMapGetCenterPoint
)
{
final
android
.
graphics
.
Point
screenPoint
=
new
android
.
graphics
.
Point
(
...
...
@@ -1120,7 +1120,7 @@ public class ArcGisLocationView extends LinearLayout implements View.OnClickList
@Override
public
void
onSingleTap
(
MotionEvent
motionEvent
)
{
if
(
isUseCluster
)
if
(
preventClick
)
return
;
switch
(
currSearchType
)
{
case
SEARCH:
...
...
@@ -1134,7 +1134,7 @@ public class ArcGisLocationView extends LinearLayout implements View.OnClickList
@Override
public
void
onLongPress
(
MotionEvent
motionEvent
)
{
if
(
isUseCluster
)
if
(
preventClick
)
return
;
switch
(
currSearchType
)
{
case
SEARCH:
...
...
arcgislib/src/main/java/cn/com/founder/arcgislib/view/ArcGisMapView.java
View file @
95981ce8
...
...
@@ -240,6 +240,14 @@ public class ArcGisMapView extends LinearLayout {
}
@Override
public
boolean
onSingleTapUp
(
MotionEvent
e
)
{
if
(
myTouchDrawListener
!=
null
)
{
myTouchDrawListener
.
onMapSingleTapUp
(
e
);
}
return
super
.
onSingleTapUp
(
e
);
}
@Override
public
void
onLongPress
(
MotionEvent
motionEvent
)
{
super
.
onLongPress
(
motionEvent
);
mLongPressEvent
=
motionEvent
;
...
...
@@ -265,6 +273,7 @@ public class ArcGisMapView extends LinearLayout {
private
MyTouchLocationListener
myTouchLocationListener
;
private
MyTouchCompassListener
myTouchCompassListener
;
private
MyTouchClusterListener
myTouchClusterListener
;
private
MyTouchDrawListener
myTouchDrawListener
;
protected
void
setMyTouchLocationListener
(
MyTouchLocationListener
touchListener
)
{
this
.
myTouchLocationListener
=
touchListener
;
...
...
@@ -278,6 +287,10 @@ public class ArcGisMapView extends LinearLayout {
this
.
myTouchClusterListener
=
touchListener
;
}
protected
void
setMyTouchDrawListener
(
MyTouchDrawListener
touchListener
)
{
this
.
myTouchDrawListener
=
touchListener
;
}
/**
* 位置触摸监听类
*/
...
...
@@ -346,4 +359,16 @@ public class ArcGisMapView extends LinearLayout {
void
onSingleTap
(
MotionEvent
motionEvent
);
}
/**
* 绘制触摸监听类
*/
interface
MyTouchDrawListener
{
/**
* 单击并抬起
*
* @param motionEvent 移动事件
*/
void
onMapSingleTapUp
(
MotionEvent
motionEvent
);
}
}
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawEntity.java
0 → 100644
View file @
95981ce8
package
cn
.
com
.
founder
.
arcgislib
.
widget
.
draw
;
import
com.esri.arcgisruntime.geometry.Point
;
import
com.esri.arcgisruntime.mapping.view.GraphicsOverlay
;
import
java.util.List
;
public
class
DrawEntity
{
private
List
<
GraphicsOverlay
>
textGraphic
=
null
;
//文字集合
private
List
<
GraphicsOverlay
>
polygonGraphic
=
null
;
//面集合
private
List
<
GraphicsOverlay
>
lineGraphic
=
null
;
//线集合
private
List
<
GraphicsOverlay
>
pointGraphic
=
null
;
//点集合
private
List
<
List
<
Point
>>
pointGroup
=
null
;
//绘制点的集合的集合
public
DrawEntity
(
List
<
GraphicsOverlay
>
textGraphic
,
List
<
GraphicsOverlay
>
polygonGraphic
,
List
<
GraphicsOverlay
>
lineGraphic
,
List
<
GraphicsOverlay
>
pointGraphic
,
List
<
List
<
Point
>>
pointGroup
)
{
this
.
textGraphic
=
textGraphic
;
this
.
polygonGraphic
=
polygonGraphic
;
this
.
lineGraphic
=
lineGraphic
;
this
.
pointGraphic
=
pointGraphic
;
this
.
pointGroup
=
pointGroup
;
}
public
DrawEntity
(){
}
public
List
<
GraphicsOverlay
>
getTextGraphic
()
{
return
textGraphic
;
}
public
void
setTextGraphic
(
List
<
GraphicsOverlay
>
textGraphic
)
{
this
.
textGraphic
=
textGraphic
;
}
public
List
<
GraphicsOverlay
>
getPolygonGraphic
()
{
return
polygonGraphic
;
}
public
void
setPolygonGraphic
(
List
<
GraphicsOverlay
>
polygonGraphic
)
{
this
.
polygonGraphic
=
polygonGraphic
;
}
public
List
<
GraphicsOverlay
>
getLineGraphic
()
{
return
lineGraphic
;
}
public
void
setLineGraphic
(
List
<
GraphicsOverlay
>
lineGraphic
)
{
this
.
lineGraphic
=
lineGraphic
;
}
public
List
<
GraphicsOverlay
>
getPointGraphic
()
{
return
pointGraphic
;
}
public
void
setPointGraphic
(
List
<
GraphicsOverlay
>
pointGraphic
)
{
this
.
pointGraphic
=
pointGraphic
;
}
public
List
<
List
<
Point
>>
getPointGroup
()
{
return
pointGroup
;
}
public
void
setPointGroup
(
List
<
List
<
Point
>>
pointGroup
)
{
this
.
pointGroup
=
pointGroup
;
}
}
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawLayer.java
0 → 100644
View file @
95981ce8
package
cn
.
com
.
founder
.
arcgislib
.
widget
.
draw
;
import
android.content.Context
;
import
android.graphics.Color
;
import
androidx.core.content.ContextCompat
;
import
com.esri.arcgisruntime.geometry.GeodeticCurveType
;
import
com.esri.arcgisruntime.geometry.GeometryEngine
;
import
com.esri.arcgisruntime.geometry.Point
;
import
com.esri.arcgisruntime.geometry.Polygon
;
import
com.esri.arcgisruntime.geometry.PolygonBuilder
;
import
com.esri.arcgisruntime.geometry.PolylineBuilder
;
import
com.esri.arcgisruntime.geometry.SpatialReference
;
import
com.esri.arcgisruntime.mapping.view.Graphic
;
import
com.esri.arcgisruntime.mapping.view.GraphicsOverlay
;
import
com.esri.arcgisruntime.mapping.view.MapView
;
import
com.esri.arcgisruntime.symbology.SimpleFillSymbol
;
import
com.esri.arcgisruntime.symbology.SimpleLineSymbol
;
import
com.esri.arcgisruntime.symbology.SimpleMarkerSymbol
;
import
com.esri.arcgisruntime.symbology.TextSymbol
;
import
java.util.ArrayList
;
import
java.util.List
;
import
cn.com.founder.arcgislib.R
;
import
cn.com.founder.arcgislib.common.Variable
;
import
cn.com.founder.arcgislib.utils.ToolUtil
;
/**
* Copyright: 方正国际软件有限公司
* Author:luo_shaopeng
* Date:2020/7/3 10:33
* EMail:luo_shaopeng@founder.com.cn
* Description:绘制图层
*/
public
class
DrawLayer
{
private
Context
context
;
private
MapView
mapView
;
private
SpatialReference
spatialReference
;
private
GraphicsOverlay
drawTextGraphicOverlay
=
null
;
//绘制面板
private
GraphicsOverlay
drawPointGraphicOverlay
=
null
;
private
GraphicsOverlay
drawLineGraphicOverlay
=
null
;
private
GraphicsOverlay
drawPolygonGraphicOverlay
=
null
;
private
GraphicsOverlay
drawOrthogonGraphicOverlay
=
null
;
private
List
<
GraphicsOverlay
>
textGraphic
=
null
;
//文字集合
private
List
<
GraphicsOverlay
>
polygonGraphic
=
null
;
//面集合
private
List
<
GraphicsOverlay
>
lineGraphic
=
null
;
//线集合
private
List
<
GraphicsOverlay
>
pointGraphic
=
null
;
//点集合
private
List
<
Graphic
>
circleGraphicList
=
null
;
private
List
<
Graphic
>
orthogonGraphicList
=
null
;
private
List
<
Graphic
>
pointGraphicList
=
null
;
private
TextSymbol
textSymbol
=
null
;
//标注样式
private
SimpleMarkerSymbol
pointSymbol
=
null
;
//点样式
private
SimpleLineSymbol
lineSymbol
=
null
;
//线样式
private
SimpleFillSymbol
polygonSymbol
=
null
;
//面样式
private
List
<
List
<
Point
>>
pointGroup
=
null
;
//绘制点的集合的集合
private
List
<
Point
>
circlePointList
;
private
List
<
Point
>
pointList
=
null
;
//每次绘制点的集合
private
List
<
Point
>
tmpPointList
=
null
;
//撤销、恢复临时点集合
private
List
<
TextSymbol
>
textList
=
null
;
//每次绘制文字的集合
private
List
<
TextSymbol
>
tmpTextList
=
null
;
//撤销、恢复临时文字集合
private
List
<
Graphic
>
textPointList
=
null
;
//每次绘制文字的集合
private
List
<
Graphic
>
tmpTextPointList
=
null
;
//撤销、恢复临时文字集合
private
Variable
.
DrawType
drawType
=
null
;
//绘制类型
private
boolean
isNext
=
false
,
isPrev
=
false
;
//是否在恢复或者撤销
private
Variable
.
Measure
measureAreaType
=
Variable
.
Measure
.
M2
;
public
DrawLayer
(
Context
context
,
MapView
mapView
){
this
.
context
=
context
;
this
.
mapView
=
mapView
;
init
();
}
private
void
init
(){
pointList
=
new
ArrayList
<>();
tmpPointList
=
new
ArrayList
<>();
textList
=
new
ArrayList
<>();
tmpTextList
=
new
ArrayList
<>();
textPointList
=
new
ArrayList
<>();
tmpTextPointList
=
new
ArrayList
<>();
textGraphic
=
new
ArrayList
<>();
polygonGraphic
=
new
ArrayList
<>();
lineGraphic
=
new
ArrayList
<>();
pointGraphic
=
new
ArrayList
<>();
pointGroup
=
new
ArrayList
<>();
circleGraphicList
=
new
ArrayList
<>();
orthogonGraphicList
=
new
ArrayList
<>();
pointGraphicList
=
new
ArrayList
<>();
circlePointList
=
new
ArrayList
<>();
pointSymbol
=
new
SimpleMarkerSymbol
(
SimpleMarkerSymbol
.
Style
.
CIRCLE
,
Color
.
GRAY
,
8
);
lineSymbol
=
new
SimpleLineSymbol
(
SimpleLineSymbol
.
Style
.
SOLID
,
Color
.
RED
,
2
);
//lineSymbol.setMarkerStyle(SimpleLineSymbol.MarkerStyle.ARROW);
polygonSymbol
=
new
SimpleFillSymbol
(
SimpleFillSymbol
.
Style
.
SOLID
,
Color
.
argb
(
40
,
0
,
0
,
0
),
null
);
textSymbol
=
new
TextSymbol
(
12
,
""
,
R
.
color
.
color_F05B48
,
TextSymbol
.
HorizontalAlignment
.
LEFT
,
TextSymbol
.
VerticalAlignment
.
BOTTOM
);
}
protected
void
startPoint
(){
drawType
=
Variable
.
DrawType
.
POINT
;
}
protected
void
startLine
(){
drawType
=
Variable
.
DrawType
.
LINE
;
}
protected
void
startPolygon
(){
drawType
=
Variable
.
DrawType
.
POLYGON
;
}
protected
void
setSpatialReference
(
SpatialReference
spatialReference
)
{
this
.
spatialReference
=
spatialReference
;
}
private
SpatialReference
getSpatialReference
()
{
if
(
spatialReference
==
null
){
return
mapView
.
getSpatialReference
();
}
return
spatialReference
;
}
protected
Object
drawByScreenPoint
(
android
.
graphics
.
Point
point
){
if
(
drawType
==
Variable
.
DrawType
.
POINT
){
return
drawPointByScreenPoint
(
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
return
drawLineByScreenPoint
(
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
return
drawPolygonByScreenPoint
(
point
);
}
return
null
;
}
protected
Object
drawByGisPoint
(
Point
point
){
if
(
drawType
==
Variable
.
DrawType
.
POINT
){
return
drawPointByGisPoint
(
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
return
drawLineByGisPoint
(
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
return
drawPolygonByGisPoint
(
point
);
}
return
null
;
}
protected
Object
drawByScreenXY
(
float
x
,
float
y
){
if
(
drawType
==
Variable
.
DrawType
.
POINT
){
return
drawPointByScreenXY
(
x
,
y
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
return
drawLineByScreenXY
(
x
,
y
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
return
drawPolygonByScreenXY
(
x
,
y
);
}
return
null
;
}
protected
void
drawPointByGisXY
(
float
x
,
float
y
){
if
(
drawType
==
Variable
.
DrawType
.
POINT
){
drawPointByGisXY
(
x
,
y
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
drawLineByGisXY
(
x
,
y
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
drawPolygonByGisXY
(
x
,
y
);
}
}
private
void
drawText
(
Point
point
){
if
(
drawTextGraphicOverlay
==
null
){
drawTextGraphicOverlay
=
new
GraphicsOverlay
();
mapView
.
getGraphicsOverlays
().
add
(
drawTextGraphicOverlay
);
textGraphic
.
add
(
drawTextGraphicOverlay
);
}
Graphic
pointGraphic
=
new
Graphic
(
point
,
textSymbol
);
drawTextGraphicOverlay
.
getGraphics
().
add
(
pointGraphic
);
if
(!
isPrev
)
{
textList
.
add
(
textSymbol
);
}
if
(!
isNext
&&
!
isPrev
)
{
tmpTextList
.
clear
();
tmpTextList
.
addAll
(
textList
);
}
}
private
void
drawPoint
(
Point
point
){
if
(
drawOrthogonGraphicOverlay
==
null
){
drawOrthogonGraphicOverlay
=
new
GraphicsOverlay
();
mapView
.
getGraphicsOverlays
().
add
(
drawOrthogonGraphicOverlay
);
pointGraphic
.
add
(
drawOrthogonGraphicOverlay
);
}
Graphic
pointGraphic
=
new
Graphic
(
point
,
pointSymbol
);
drawOrthogonGraphicOverlay
.
getGraphics
().
add
(
pointGraphic
);
pointList
.
add
(
point
);
if
(!
isNext
)
{
tmpPointList
.
clear
();
tmpPointList
.
addAll
(
pointList
);
}
}
public
void
drawBox
(
float
x
,
float
y
)
{
Point
point
=
screenXYtoPpoint
(
x
,
y
);
circlePointList
.
add
(
point
);
drawPoint
(
point
);
if
(
circlePointList
.
size
()==
2
){
drawBox
(
circlePointList
.
get
(
0
),
circlePointList
.
get
(
1
));
circlePointList
.
clear
();
removeGraphics
(
pointGraphicList
);
}
}
public
void
drawBox
(
Point
point1
,
Point
point2
)
{
PolygonBuilder
polygonGeometry
=
new
PolygonBuilder
(
getSpatialReference
());
polygonGeometry
.
addPoint
(
point1
);
polygonGeometry
.
addPoint
(
new
Point
(
point1
.
getX
(),
point2
.
getY
()));
polygonGeometry
.
addPoint
(
point2
);
polygonGeometry
.
addPoint
(
new
Point
(
point2
.
getX
(),
point1
.
getY
()));
orthogonGraphicList
.
add
(
drawPolygon
(
polygonGeometry
));
}
public
void
drawCircle
(
float
x
,
float
y
)
{
Point
point
=
screenXYtoPpoint
(
x
,
y
);
circlePointList
.
add
(
point
);
drawPoint
(
point
);
if
(
circlePointList
.
size
()==
2
){
drawCircle
(
circlePointList
.
get
(
0
),
circlePointList
.
get
(
1
));
circlePointList
.
clear
();
removeGraphics
(
pointGraphicList
);
}
}
public
void
drawCircle
(
Point
point1
,
Point
point2
)
{
double
radius
=
0
;
double
x
=
(
point2
.
getX
()
-
point1
.
getX
());
double
y
=
(
point2
.
getY
()
-
point1
.
getY
());
radius
=
Math
.
sqrt
(
Math
.
pow
(
x
,
2
)
+
Math
.
pow
(
y
,
2
));
drawCircle
(
point1
,
radius
);
}
public
void
drawCircle
(
Point
point
,
double
radius
)
{
Point
[]
points
=
getCirclePoints
(
point
,
radius
);
PolygonBuilder
polygonGeometry
=
new
PolygonBuilder
(
getSpatialReference
());
for
(
Point
p
:
points
)
{
polygonGeometry
.
addPoint
(
p
);
}
circleGraphicList
.
add
(
drawPolygon
(
polygonGeometry
));
}
public
Graphic
drawPolygon
(
PolygonBuilder
polygonGeometry
){
Polygon
polygon
=
polygonGeometry
.
toGeometry
();
SimpleLineSymbol
lineSymbol
=
new
SimpleLineSymbol
(
SimpleLineSymbol
.
Style
.
SOLID
,
Color
.
RED
,
2.0f
);
// SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 2.0f);
// SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.argb(40,0,0,0), 1.0f);
// SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol);
SimpleFillSymbol
simpleFillSymbol
=
new
SimpleFillSymbol
(
SimpleFillSymbol
.
Style
.
SOLID
,
Color
.
argb
(
40
,
0
,
0
,
0
),
lineSymbol
);
Graphic
graphic
=
new
Graphic
(
polygon
,
simpleFillSymbol
);
drawOrthogonGraphicOverlay
.
getGraphics
().
add
(
graphic
);
double
area
=
GeometryEngine
.
areaGeodetic
(
polygonGeometry
.
toGeometry
(),
null
,
GeodeticCurveType
.
SHAPE_PRESERVING
);
String
s
=
ToolUtil
.
forMatDouble
(
Math
.
abs
(
ToolUtil
.
areaChange
(
area
,
measureAreaType
)));
drawText
(
polygonGeometry
.
toGeometry
().
getExtent
().
getCenter
(),
s
+
ToolUtil
.
lengthEnameToCname
(
measureAreaType
),
true
);
return
graphic
;
}
private
static
Point
[]
getCirclePoints
(
Point
center
,
double
radius
)
{
Point
[]
points
=
new
Point
[
50
];
double
sin
;
double
cos
;
double
x
;
double
y
;
for
(
double
i
=
0
;
i
<
50
;
i
++)
{
sin
=
Math
.
sin
(
Math
.
PI
*
2
*
i
/
50
);
cos
=
Math
.
cos
(
Math
.
PI
*
2
*
i
/
50
);
x
=
center
.
getX
()
+
radius
*
sin
;
y
=
center
.
getY
()
+
radius
*
cos
;
points
[(
int
)
i
]
=
new
Point
(
x
,
y
);
}
return
points
;
}
private
PolylineBuilder
drawLine
(
Point
point1
,
Point
point2
){
//绘制面板为空,说明重新绘制一个line,在地图和线集合里添加一个新line
if
(
drawLineGraphicOverlay
==
null
){
drawLineGraphicOverlay
=
new
GraphicsOverlay
();
mapView
.
getGraphicsOverlays
().
add
(
drawLineGraphicOverlay
);
lineGraphic
.
add
(
drawLineGraphicOverlay
);
}
PolylineBuilder
lineGeometry
=
new
PolylineBuilder
(
getSpatialReference
());
lineGeometry
.
addPoint
(
point1
);
lineGeometry
.
addPoint
(
point2
);
Graphic
lineGraphic
=
new
Graphic
(
lineGeometry
.
toGeometry
(),
lineSymbol
);
drawLineGraphicOverlay
.
getGraphics
().
add
(
lineGraphic
);
return
lineGeometry
;
}
private
PolygonBuilder
drawPolygon
(){
//绘制面板为空,说明重新绘制一个Polyline,在地图和面集合里添加一个新Polyline
if
(
drawPolygonGraphicOverlay
==
null
){
drawPolygonGraphicOverlay
=
new
GraphicsOverlay
();
mapView
.
getGraphicsOverlays
().
add
(
drawPolygonGraphicOverlay
);
polygonGraphic
.
add
(
drawPolygonGraphicOverlay
);
}
PolygonBuilder
polygonGeometry
=
new
PolygonBuilder
(
getSpatialReference
());
for
(
Point
point:
pointList
){
polygonGeometry
.
addPoint
(
point
);
}
drawPolygonGraphicOverlay
.
getGraphics
().
clear
();
Graphic
polygonGraphic
=
new
Graphic
(
polygonGeometry
.
toGeometry
(),
polygonSymbol
);
drawPolygonGraphicOverlay
.
getGraphics
().
add
(
polygonGraphic
);
return
polygonGeometry
;
}
private
Point
drawPointByScreenPoint
(
android
.
graphics
.
Point
point
){
Point
center
=
mapView
.
screenToLocation
(
point
);
this
.
drawPoint
(
center
);
return
center
;
}
private
Point
drawPointByGisPoint
(
Point
point
){
this
.
drawPoint
(
point
);
return
point
;
}
private
Point
drawPointByScreenXY
(
float
x
,
float
y
){
android
.
graphics
.
Point
point
=
new
android
.
graphics
.
Point
(
Math
.
round
(
x
),
Math
.
round
(
y
));
Point
center
=
mapView
.
screenToLocation
(
point
);
this
.
drawPoint
(
center
);
return
center
;
}
private
Point
drawPointByGisXY
(
double
x
,
double
y
){
Point
center
=
new
Point
(
x
,
y
);
this
.
drawPoint
(
center
);
return
center
;
}
private
PolylineBuilder
drawLineByScreenPoint
(
android
.
graphics
.
Point
point
){
Point
nextPoint
=
this
.
drawPointByScreenPoint
(
point
);
if
(
getPointSize
()>
1
)
{
Point
prvPoint
=
getLastPoint
();
return
this
.
drawLine
(
prvPoint
,
nextPoint
);
}
return
null
;
}
private
PolylineBuilder
drawLineByGisPoint
(
Point
point
){
Point
nextPoint
=
this
.
drawPointByGisPoint
(
point
);
if
(
getPointSize
()>
1
)
{
Point
prvPoint
=
getLastPoint
();
return
this
.
drawLine
(
prvPoint
,
nextPoint
);
}
return
null
;
}
private
PolylineBuilder
drawLineByGisPoint
(
Point
point1
,
Point
point2
){
return
this
.
drawLine
(
point1
,
point2
);
}
private
PolylineBuilder
drawLineByScreenXY
(
float
x
,
float
y
){
Point
nextPoint
=
this
.
drawPointByScreenXY
(
x
,
y
);
if
(
getPointSize
()>
1
)
{
Point
prvPoint
=
getLastPoint
();
return
this
.
drawLine
(
prvPoint
,
nextPoint
);
}
return
null
;
}
private
PolylineBuilder
drawLineByGisXY
(
double
x
,
double
y
){
Point
nextPoint
=
this
.
drawPointByGisXY
(
x
,
y
);
if
(
getPointSize
()>
1
)
{
Point
prvPoint
=
getLastPoint
();
return
this
.
drawLine
(
prvPoint
,
nextPoint
);
}
return
null
;
}
private
PolygonBuilder
drawPolygonByScreenXY
(
float
x
,
float
y
){
drawLineByScreenXY
(
x
,
y
);
if
(
getPointSize
()>=
3
)
{
return
drawPolygon
();
}
return
null
;
}
private
PolygonBuilder
drawPolygonByScreenPoint
(
android
.
graphics
.
Point
point
){
drawLineByScreenPoint
(
point
);
if
(
getPointSize
()>=
3
)
{
return
drawPolygon
();
}
return
null
;
}
private
PolygonBuilder
drawPolygonByGisXY
(
double
x
,
double
y
){
drawLineByGisXY
(
x
,
y
);
if
(
getPointSize
()>=
3
)
{
return
drawPolygon
();
}
return
null
;
}
private
PolygonBuilder
drawPolygonByGisPoint
(
Point
point
){
drawLineByGisPoint
(
point
);
if
(
getPointSize
()>=
3
)
{
return
drawPolygon
();
}
return
null
;
}
protected
Point
screenXYtoPpoint
(
float
x
,
float
y
){
android
.
graphics
.
Point
point
=
new
android
.
graphics
.
Point
(
Math
.
round
(
x
),
Math
.
round
(
y
));
return
mapView
.
screenToLocation
(
point
);
}
protected
void
drawText
(
Point
point
,
String
text
,
boolean
replaceOld
){
textSymbol
=
getTextSymbol
();
if
(
replaceOld
)
{
textSymbol
.
setHorizontalAlignment
(
TextSymbol
.
HorizontalAlignment
.
CENTER
);
if
(
drawTextGraphicOverlay
!=
null
)
drawTextGraphicOverlay
.
getGraphics
().
clear
();
}
textSymbol
.
setText
(
text
);
drawText
(
point
);
}
protected
boolean
prevDraw
(){
if
(
pointList
.
size
()>
1
){
pointList
.
remove
(
pointList
.
size
()-
1
);
if
(
textList
.
size
()>
0
)
{
textList
.
remove
(
textList
.
size
()
-
1
);
}
removePrevGraphics
(
drawPointGraphicOverlay
);
removePrevGraphics
(
drawLineGraphicOverlay
);
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
removePrevGraphics
(
drawTextGraphicOverlay
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
if
(
textList
.
size
()>
1
)
{
textSymbol
=
tmpTextList
.
get
(
textList
.
size
()
-
1
);
}
PolygonBuilder
pb
=
drawPolygon
();
isPrev
=
true
;
if
(
drawTextGraphicOverlay
!=
null
)
drawTextGraphicOverlay
.
getGraphics
().
clear
();
if
(
pointList
.
size
()>
2
)
{
drawText
(
pb
.
toGeometry
().
getExtent
().
getCenter
());
}
isPrev
=
false
;
}
}
return
pointList
.
size
()>
1
?
true
:
false
;
}
protected
boolean
nextDraw
(){
isNext
=
true
;
if
(
pointList
.
size
()>
0
&&
pointList
.
size
()<
tmpPointList
.
size
()){
int
index
=
pointList
.
size
();
// textSymbol=tmpTextList.get(textList.size());
if
(
drawType
==
Variable
.
DrawType
.
LINE
)
{
drawLineByGisPoint
(
tmpPointList
.
get
(
index
));
drawText
(
tmpPointList
.
get
(
index
));
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
PolygonBuilder
pb
=
drawPolygonByGisPoint
(
tmpPointList
.
get
(
index
));
if
(
drawTextGraphicOverlay
!=
null
)
drawTextGraphicOverlay
.
getGraphics
().
clear
();
if
(
pointList
.
size
()>
2
)
{
drawText
(
pb
.
toGeometry
().
getExtent
().
getCenter
());
}
}
}
isNext
=
false
;
return
(
pointList
.
size
()>
0
&&
pointList
.
size
()<
tmpPointList
.
size
())?
true
:
false
;
}
protected
DrawEntity
endDraw
(){
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
)
{
if
(
getPointSize
()
>=
3
)
{
this
.
drawLineByGisPoint
(
getEndPoint
(),
getFristPoint
());
}
}
if
(
pointList
.
size
()>
0
)
{
pointGroup
.
add
(
pointList
);
}
DrawEntity
de
=
allDraw
();
drawType
=
null
;
drawPolygonGraphicOverlay
=
null
;
drawLineGraphicOverlay
=
null
;
drawPointGraphicOverlay
=
null
;
drawTextGraphicOverlay
=
null
;
pointList
=
new
ArrayList
<>();
return
de
;
}
protected
DrawEntity
clear
(){
DrawEntity
de
=
allDraw
();
removeAllGraphics
(
lineGraphic
);
removeAllGraphics
(
polygonGraphic
);
removeAllGraphics
(
pointGraphic
);
removeAllGraphics
(
textGraphic
);
removeGraphics
(
circleGraphicList
);
removeGraphics
(
pointGraphicList
);
removeGraphics
(
orthogonGraphicList
);
drawPolygonGraphicOverlay
=
null
;
drawLineGraphicOverlay
=
null
;
drawPointGraphicOverlay
=
null
;
drawTextGraphicOverlay
=
null
;
drawOrthogonGraphicOverlay
=
null
;
drawType
=
null
;
pointGroup
.
clear
();
pointList
.
clear
();
lineGraphic
.
clear
();
pointGraphic
.
clear
();
textGraphic
.
clear
();
pointGroup
=
new
ArrayList
<>();
pointList
=
new
ArrayList
<>();
lineGraphic
=
new
ArrayList
<>();
textGraphic
=
new
ArrayList
<>();
pointGraphic
=
new
ArrayList
<>();
return
de
;
}
private
DrawEntity
allDraw
(){
DrawEntity
de
=
new
DrawEntity
();
de
.
setLineGraphic
(
lineGraphic
);
de
.
setPointGraphic
(
pointGraphic
);
de
.
setTextGraphic
(
textGraphic
);
de
.
setPolygonGraphic
(
polygonGraphic
);
de
.
setPointGroup
(
pointGroup
);
return
de
;
}
private
void
removeGraphics
(
List
<
Graphic
>
go
){
drawOrthogonGraphicOverlay
.
getGraphics
().
removeAll
(
go
);
}
private
void
removeAllGraphics
(
List
<
GraphicsOverlay
>
go
){
if
(
go
.
size
()>
0
){
for
(
GraphicsOverlay
graphics:
go
){
mapView
.
getGraphicsOverlays
().
remove
(
graphics
);
}
}
}
private
void
removePrevGraphics
(
GraphicsOverlay
gho
){
if
(
gho
!=
null
){
boolean
isEmpty
=
gho
.
getGraphics
()
==
null
||
gho
.
getGraphics
().
isEmpty
();
if
(!
isEmpty
){
gho
.
getGraphics
().
remove
(
gho
.
getGraphics
().
size
()-
1
);
}
}
}
/*protected void prevDraw(){
if(pointGraphic.size()==0 && textGraphic.size()==0 && lineGraphic.size()==0){
endDraw();
return;
}
removePrevGraphics(pointGraphic,Variable.DrawType.POINT);
removePrevGraphics(textGraphic,Variable.DrawType.TEXT);
removePrevGraphics(lineGraphic,Variable.DrawType.LINE);
if(pointList.size()>0){
if (pointList.size() > 0) {
pointList.remove(pointList.size() - 1);
}
}else if(pointGroup.size()>0) {
pointList=pointGroup.get(pointGroup.size()-1);
pointGroup.remove(pointGroup.size()-1);
}
if(drawType==Variable.DrawType.POLYGON){
drawPolygon();
}
}
private void removePrevGraphics(List<GraphicsOverlay> gos, Variable.DrawType type){
if(gos.size()>0) {
GraphicsOverlay go=gos.get(gos.size()-1);
List<Graphic> tg=go.getGraphics();
if (tg.size() > 0) {
tg.remove(tg.size() - 1);
}
if (tg.size() == 0){
mapView.getGraphicsOverlays().remove(gos.get(gos.size()-1));
gos.remove(gos.size()-1);
if(drawType==Variable.DrawType.LINE && type==Variable.DrawType.LINE){
removePrevGraphics(pointGraphic,Variable.DrawType.POINT);
}
if(drawType==Variable.DrawType.LINE && type==Variable.DrawType.POINT){
pointList.clear();
}
if(gos.size()>0) {
if (type == Variable.DrawType.LINE) {
drawLineGraphicOverlay = gos.get(gos.size() - 1);
} else if (type == Variable.DrawType.POINT) {
drawPointGraphicOverlay = gos.get(gos.size() - 1);
} else if (type == Variable.DrawType.TEXT) {
drawTextGraphicOverlay = gos.get(gos.size() - 1);
}
}else{
if (type == Variable.DrawType.LINE) {
drawLineGraphicOverlay = null;
} else if (type == Variable.DrawType.POINT) {
drawPointGraphicOverlay = null;
} else if (type == Variable.DrawType.TEXT) {
drawTextGraphicOverlay = null;
}
}
}
}
}*/
private
TextSymbol
getTextSymbol
(){
TextSymbol
textSymbol
=
new
TextSymbol
(
12
,
""
,
Color
.
BLACK
,
TextSymbol
.
HorizontalAlignment
.
LEFT
,
TextSymbol
.
VerticalAlignment
.
BOTTOM
);
textSymbol
.
setColor
(
Color
.
WHITE
);
textSymbol
.
setHaloColor
(
Color
.
WHITE
);
textSymbol
.
setHaloWidth
(
1
);
textSymbol
.
setOutlineColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
color_444444
));
textSymbol
.
setOutlineWidth
(
1
);
return
textSymbol
;
}
private
int
getPointSize
(){
return
pointList
.
size
();
}
public
Point
getEndPoint
(){
int
index
=
getPointSize
()>
1
?
getPointSize
()-
1
:
0
;
Point
point
=
pointList
.
get
(
index
);
return
point
;
}
private
Point
getLastPoint
(){
int
index
=
getPointSize
()>
1
?
getPointSize
()-
2
:
0
;
Point
point
=
pointList
.
get
(
index
);
return
point
;
}
private
Point
getFristPoint
(){
if
(
getPointSize
()==
0
)
return
null
;
Point
point
=
pointList
.
get
(
0
);
return
point
;
}
}
arcgislib/src/main/java/cn/com/founder/arcgislib/widget/draw/DrawView.java
0 → 100644
View file @
95981ce8
package
cn
.
com
.
founder
.
arcgislib
.
widget
.
draw
;
import
android.content.Context
;
import
com.esri.arcgisruntime.geometry.GeodeticCurveType
;
import
com.esri.arcgisruntime.geometry.GeometryEngine
;
import
com.esri.arcgisruntime.geometry.Point
;
import
com.esri.arcgisruntime.geometry.PolygonBuilder
;
import
com.esri.arcgisruntime.geometry.PolylineBuilder
;
import
com.esri.arcgisruntime.geometry.SpatialReference
;
import
com.esri.arcgisruntime.mapping.view.MapView
;
import
java.util.ArrayList
;
import
java.util.List
;
import
cn.com.founder.arcgislib.common.Variable
;
import
cn.com.founder.arcgislib.utils.ToolUtil
;
/**
* Copyright: 方正国际软件有限公司
* Author:luo_shaopeng
* Date:2020/7/3 17:33
* EMail:luo_shaopeng@founder.com.cn
* Description:绘制
*/
public
class
DrawView
extends
DrawLayer
{
private
Context
context
;
private
MapView
mapView
;
private
Variable
.
DrawType
drawType
=
null
;
private
Variable
.
Measure
measureLengthType
=
Variable
.
Measure
.
M
;
private
Variable
.
Measure
measureAreaType
=
Variable
.
Measure
.
M2
;
private
double
lineLength
=
0
;
private
List
<
Double
>
lengthList
;
private
List
<
Double
>
tmpLengthList
;
public
DrawView
(
Context
context
,
MapView
mapView
)
{
super
(
context
,
mapView
);
this
.
context
=
context
;
this
.
mapView
=
mapView
;
lengthList
=
new
ArrayList
<>();
tmpLengthList
=
new
ArrayList
<>();
}
public
void
startMeasuredLength
(
float
screenX
,
float
screenY
){
if
(
drawType
==
null
)
{
super
.
startLine
();
drawType
=
Variable
.
DrawType
.
LINE
;
}
drawScreenXY
(
screenX
,
screenY
);
}
public
void
startMeasuredLength
(
android
.
graphics
.
Point
screenPoint
){
if
(
drawType
==
null
)
{
super
.
startLine
();
drawType
=
Variable
.
DrawType
.
LINE
;
}
drawScreenPoint
(
screenPoint
);
}
public
void
startMeasuredArea
(
float
screenX
,
float
screenY
){
if
(
drawType
==
null
)
{
super
.
startPolygon
();
drawType
=
Variable
.
DrawType
.
POLYGON
;
}
drawScreenXY
(
screenX
,
screenY
);
}
public
void
startMeasuredArea
(
android
.
graphics
.
Point
screenPoint
){
if
(
drawType
==
null
)
{
super
.
startPolygon
();
drawType
=
Variable
.
DrawType
.
POLYGON
;
}
drawScreenPoint
(
screenPoint
);
}
public
boolean
prevDraw
(){
if
(
lengthList
.
size
()>
1
)
{
lengthList
.
remove
(
lengthList
.
size
()
-
1
);
lineLength
=
lengthList
.
get
(
lengthList
.
size
()-
1
);
}
else
{
lengthList
.
clear
();
lineLength
=
0
;
}
return
super
.
prevDraw
();
}
public
boolean
nextDraw
(){
if
(
lengthList
.
size
()>
0
&&
lengthList
.
size
()<
tmpLengthList
.
size
())
{
lengthList
.
add
(
tmpLengthList
.
get
(
lengthList
.
size
()));
lineLength
=
lengthList
.
get
(
lengthList
.
size
()-
1
);
}
return
super
.
nextDraw
();
}
public
DrawEntity
endMeasure
(){
drawType
=
null
;
lineLength
=
0
;
tmpLengthList
.
clear
();
lengthList
.
clear
();
return
super
.
endDraw
();
}
public
DrawEntity
clearMeasure
(){
drawType
=
null
;
lineLength
=
0
;
tmpLengthList
.
clear
();
lengthList
.
clear
();
return
super
.
clear
();
}
public
void
setSpatialReference
(
SpatialReference
spatialReference
)
{
super
.
setSpatialReference
(
spatialReference
);
}
public
void
setLengthType
(
Variable
.
Measure
type
){
this
.
measureLengthType
=
type
;
}
public
void
setAreaType
(
Variable
.
Measure
type
){
this
.
measureAreaType
=
type
;
}
private
void
drawScreenXY
(
float
x
,
float
y
){
Point
point
=
super
.
screenXYtoPpoint
(
x
,
y
);
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
PolylineBuilder
line
=(
PolylineBuilder
)
super
.
drawByGisPoint
(
point
);
showLength
(
line
,
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
PolygonBuilder
polygon
=(
PolygonBuilder
)
super
.
drawByGisPoint
(
point
);
showArea
(
polygon
);
}
}
private
void
drawScreenPoint
(
android
.
graphics
.
Point
screenPoint
){
Point
point
=
super
.
screenXYtoPpoint
(
screenPoint
.
x
,
screenPoint
.
y
);
if
(
drawType
==
Variable
.
DrawType
.
LINE
){
PolylineBuilder
line
=(
PolylineBuilder
)
super
.
drawByScreenPoint
(
screenPoint
);
showLength
(
line
,
point
);
}
else
if
(
drawType
==
Variable
.
DrawType
.
POLYGON
){
PolygonBuilder
polygon
=(
PolygonBuilder
)
super
.
drawByScreenPoint
(
screenPoint
);
showArea
(
polygon
);
}
}
private
void
showLength
(
PolylineBuilder
line
,
Point
point
){
if
(
line
!=
null
)
{
//double length = GeometryEngine.length(line.toGeometry());
double
length
=
GeometryEngine
.
lengthGeodetic
(
line
.
toGeometry
(),
null
,
GeodeticCurveType
.
SHAPE_PRESERVING
);
lineLength
+=
length
;
lengthList
.
add
(
lineLength
);
tmpLengthList
.
clear
();
tmpLengthList
.
addAll
(
lengthList
);
String
s
=
ToolUtil
.
forMatDouble
(
Math
.
abs
(
ToolUtil
.
lengthChange
(
lineLength
,
measureLengthType
)));
super
.
drawText
(
point
,
s
+
ToolUtil
.
lengthEnameToCname
(
measureLengthType
),
false
);
}
}
private
void
showArea
(
PolygonBuilder
polygon
){
if
(
polygon
!=
null
)
{
//double area = GeometryEngine.area(polygon.toGeometry());
double
area
=
GeometryEngine
.
areaGeodetic
(
polygon
.
toGeometry
(),
null
,
GeodeticCurveType
.
SHAPE_PRESERVING
);
String
s
=
ToolUtil
.
forMatDouble
(
Math
.
abs
(
ToolUtil
.
areaChange
(
area
,
measureAreaType
)));
super
.
drawText
(
polygon
.
toGeometry
().
getExtent
().
getCenter
(),
s
+
ToolUtil
.
lengthEnameToCname
(
measureAreaType
),
true
);
}
}
}
arcgislib/src/main/res/values/colors.xml
View file @
95981ce8
...
...
@@ -12,8 +12,11 @@
<color
name=
"color_CCCCCC"
>
#CCCCCC
</color>
<color
name=
"color_E6E6E6"
>
#E6E6E6
</color>
<color
name=
"color_BFBFBF"
>
#BFBFBF
</color>
<color
name=
"color_444444"
>
#444444
</color>
<color
name=
"color_13227A"
>
#13227A
</color>
<color
name=
"color_1A34BC"
>
#1A34BC
</color>
<color
name=
"color_F05B48"
>
#F05B48
</color>
<color
name=
"color_515151"
>
#515151
</color>
...
...
arcgislib/src/main/res/values/dimens.xml
View file @
95981ce8
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name=
"dimen_block_35"
>
35dp
</dimen>
<dimen
name=
"dimen_block_30"
>
30dp
</dimen>
<dimen
name=
"dimen_block_25"
>
25dp
</dimen>
<dimen
name=
"dimen_block_20"
>
20dp
</dimen>
...
...
arcgislib/src/main/res/values/strings.xml
View file @
95981ce8
...
...
@@ -36,4 +36,16 @@
<string
name=
"string_hotpots_end_time"
>
结束时间
</string>
<string
name=
"string_hotpots_input_hint"
>
请选择
</string>
<string
name=
"string_hotpots_finish"
>
完成
</string>
<!--绘制-->
<string
name=
"string_draw_line"
>
线
</string>
<string
name=
"string_draw_circle"
>
圆
</string>
<string
name=
"string_draw_orthogon"
>
矩形
</string>
<string
name=
"string_draw_polygon"
>
多边形
</string>
<string
name=
"string_draw_prev"
>
撤销
</string>
<string
name=
"string_draw_next"
>
恢复
</string>
<string
name=
"string_draw_clear"
>
清除
</string>
<string
name=
"string_draw_end"
>
完成
</string>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment