Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
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
ReactWeb5
wisdom-components
Commits
61fff4c1
Commit
61fff4c1
authored
Dec 24, 2020
by
邹绪超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 去除web4相关依赖
parent
f6708838
Pipeline
#21136
passed with stages
in 2 minutes 40 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
189 additions
and
6 deletions
+189
-6
utils.js
packages/map/src/core/utils.js
+164
-0
createMap.jsx
packages/map/src/demos/createMap.jsx
+25
-6
index.js
packages/map/src/index.js
+0
-0
No files found.
packages/map/src/core/utils.js
View file @
61fff4c1
...
...
@@ -77,6 +77,170 @@ const mapUtils = {
}
return
{
scale
:
nearestScale
,
zoom
};
},
getCurrentMapWkid
(
view
,
baseMapId
)
{
let
id
=
baseMapId
?
baseMapId
:
view
.
map
.
basemap
.
id
;
let
inSR
=
102113
;
if
(
id
.
indexOf
(
'天地图'
)
!=
-
1
)
inSR
=
1021130
;
return
inSR
;
},
getAreaLevel
(
areaName
)
{
switch
(
areaName
.
charAt
(
areaName
.
length
-
1
))
{
case
'省'
:
return
'province'
;
case
'市'
:
return
'city'
;
case
'区'
:
case
'县'
:
case
'旗'
:
case
'盟'
:
return
'district'
;
default
:
return
'country'
;
}
},
gcj2wgs
(
point
)
{
var
ee
=
0.00669342162296594323
,
a
=
6378245.0
,
dLat
=
this
.
transformLat
(
point
.
Y
-
105.0
,
point
.
X
-
35.0
),
dLon
=
this
.
transformLon
(
point
.
Y
-
105.0
,
point
.
X
-
35.0
),
radLat
=
(
point
.
X
/
180.0
)
*
Math
.
PI
,
magic
=
Math
.
sin
(
radLat
),
magic
=
1
-
ee
*
magic
*
magic
;
var
sqrtMagic
=
Math
.
sqrt
(
magic
);
dLat
=
(
dLat
*
180.0
)
/
(((
a
*
(
1
-
ee
))
/
(
magic
*
sqrtMagic
))
*
Math
.
PI
);
dLon
=
(
dLon
*
180.0
)
/
((
a
/
sqrtMagic
)
*
Math
.
cos
(
radLat
)
*
Math
.
PI
);
var
mgLat
=
point
.
X
-
dLat
;
var
mgLon
=
point
.
Y
-
dLon
;
var
loc
=
{
X
:
mgLat
,
Y
:
mgLon
,
};
return
loc
;
},
transformLat
(
lat
,
lon
)
{
var
ret
=
-
100.0
+
2.0
*
lat
+
3.0
*
lon
+
0.2
*
lon
*
lon
+
0.1
*
lat
*
lon
+
0.2
*
Math
.
sqrt
(
Math
.
abs
(
lat
));
ret
+=
((
20.0
*
Math
.
sin
(
6.0
*
lat
*
Math
.
PI
)
+
20.0
*
Math
.
sin
(
2.0
*
lat
*
Math
.
PI
))
*
2.0
)
/
3.0
;
ret
+=
((
20.0
*
Math
.
sin
(
lon
*
Math
.
PI
)
+
40.0
*
Math
.
sin
((
lon
/
3.0
)
*
Math
.
PI
))
*
2.0
)
/
3.0
;
ret
+=
((
160.0
*
Math
.
sin
((
lon
/
12.0
)
*
Math
.
PI
)
+
320
*
Math
.
sin
((
lon
*
Math
.
PI
)
/
30.0
))
*
2.0
)
/
3.0
;
return
ret
;
},
transformLon
(
lat
,
lon
)
{
var
ret
=
300.0
+
lat
+
2.0
*
lon
+
0.1
*
lat
*
lat
+
0.1
*
lat
*
lon
+
0.1
*
Math
.
sqrt
(
Math
.
abs
(
lat
));
ret
+=
((
20.0
*
Math
.
sin
(
6.0
*
lat
*
Math
.
PI
)
+
20.0
*
Math
.
sin
(
2.0
*
lat
*
Math
.
PI
))
*
2.0
)
/
3.0
;
ret
+=
((
20.0
*
Math
.
sin
(
lat
*
Math
.
PI
)
+
40.0
*
Math
.
sin
((
lat
/
3.0
)
*
Math
.
PI
))
*
2.0
)
/
3.0
;
ret
+=
((
150.0
*
Math
.
sin
((
lat
/
12.0
)
*
Math
.
PI
)
+
300.0
*
Math
.
sin
((
lat
/
30.0
)
*
Math
.
PI
))
*
2.0
)
/
3.0
;
return
ret
;
},
lonLat2WebMercator
(
point
)
{
var
mercator
=
{},
x
=
(
point
.
lng
*
20037508.34
)
/
180
,
y
=
Math
.
log
(
Math
.
tan
(((
90
+
point
.
lat
)
*
Math
.
PI
)
/
360
))
/
(
Math
.
PI
/
180
);
y
=
(
y
*
20037508.34
)
/
180
;
mercator
.
x
=
x
;
mercator
.
y
=
y
;
return
mercator
;
},
webMercator2lonLat
(
point
)
{
var
lonLat
=
{},
x
=
(
point
.
X
/
20037508.34
)
*
180
;
y
=
(
point
.
Y
/
20037508.34
)
*
180
;
y
=
(
180
/
Math
.
PI
)
*
(
2
*
Math
.
atan
(
Math
.
exp
((
y
*
Math
.
PI
)
/
180
))
-
Math
.
PI
/
2
);
lonLat
.
X
=
x
;
lonLat
.
Y
=
y
;
return
lonLat
;
},
getProcessPoints
(
points
,
tolerance
)
{
if
(
!
points
.
length
)
{
//当points不是数组或没有值时,直接返回一个空数组
return
[];
}
if
(
points
.
length
<
3
)
return
points
;
//小于3个点时不抽稀,因为1个或2个点无法进行抽稀
var
firstPoint
=
0
,
lastPoint
=
points
.
length
-
1
;
//取开始点与结束点的下标
var
pointIndexsToKeep
=
[];
//保存需要点下标的数组
pointIndexsToKeep
.
push
(
firstPoint
);
pointIndexsToKeep
.
push
(
lastPoint
);
//开始与结束不进行处理,直接保留
while
(
points
[
firstPoint
][
0
]
==
points
[
lastPoint
][
0
]
&&
points
[
firstPoint
][
1
]
==
points
[
lastPoint
][
1
]
)
{
//处理闭合情况,闭合时,强制断开
lastPoint
--
;
}
this
.
reduce
(
points
,
firstPoint
,
lastPoint
,
tolerance
,
pointIndexsToKeep
);
//抽稀
var
resultPoints
=
[];
//返回的点数组
pointIndexsToKeep
.
sort
(
function
(
a
,
b
)
{
//排序,这个可排可不排
return
a
-
b
;
});
for
(
var
i
=
0
;
i
<
pointIndexsToKeep
.
length
;
i
++
)
{
resultPoints
.
push
(
points
[
pointIndexsToKeep
[
i
]]);
}
return
resultPoints
;
},
reduce
(
points
,
firstPoint
,
lastPoint
,
tolerance
,
pointIndexsToKeep
)
{
var
maxDis
=
0
,
idxFarthest
=
0
;
//定义最大长度及最远点的下标
for
(
var
i
=
firstPoint
,
dis
;
i
<
lastPoint
;
i
++
)
{
dis
=
this
.
perpendicularDistance
(
points
[
firstPoint
],
points
[
lastPoint
],
points
[
i
]);
//获取当前点到起点与
if
(
dis
>
maxDis
)
{
//保存最远距离
maxDis
=
dis
;
idxFarthest
=
i
;
}
}
if
(
maxDis
>
tolerance
&&
idxFarthest
!=
0
)
{
//如果最远距离大于临界值
pointIndexsToKeep
.
push
(
idxFarthest
);
this
.
reduce
(
points
,
firstPoint
,
idxFarthest
,
tolerance
,
pointIndexsToKeep
);
this
.
reduce
(
points
,
idxFarthest
,
lastPoint
,
tolerance
,
pointIndexsToKeep
);
}
},
perpendicularDistance
(
beginPoint
,
endPoint
,
comparePoint
)
{
var
area
=
Math
.
abs
(
0.5
*
(
beginPoint
[
0
]
*
endPoint
[
1
]
+
endPoint
[
0
]
*
comparePoint
[
1
]
+
comparePoint
[
0
]
*
beginPoint
[
1
]
-
endPoint
[
0
]
*
beginPoint
[
1
]
-
comparePoint
[
0
]
*
endPoint
[
1
]
-
beginPoint
[
0
]
*
comparePoint
[
1
]),
);
var
bottom
=
Math
.
sqrt
(
Math
.
pow
(
beginPoint
[
0
]
-
endPoint
[
0
],
2
)
+
Math
.
pow
(
beginPoint
[
1
]
-
endPoint
[
1
],
2
),
);
var
height
=
(
area
/
bottom
)
*
2
;
return
height
;
},
getBounds
(
mapType
)
{
let
bounds
;
switch
(
mapType
)
{
default
:
bounds
=
[
[
-
4710.6852773055
,
-
43700.69435362797
],
[
-
4710.6852773055
,
10065103.18739793
],
[
20070490.956488788
,
10065103.18739793
],
[
20070490.956488788
,
-
43700.69435362797
],
[
-
4710.6852773055
,
-
43700.69435362797
],
];
break
;
}
return
bounds
;
},
};
export
{
layerOperation
,
urlUtils
,
loadUtilMapModules
,
geomUtils
,
mapUtils
};
packages/map/src/demos/createMap.jsx
View file @
61fff4c1
...
...
@@ -5,12 +5,12 @@ export default class CreateMap extends React.Component {
constructor
(
props
)
{
super
(
props
);
this
.
mapManganerRef
=
React
.
createRef
();
if
(
!
window
.
_config
)
{
window
.
_config
=
{
site
:
''
,
useCoverMap
:
true
,
};
}
//
if (!window._config) {
//
window._config = {
//
site: '',
//
useCoverMap: true,
//
};
//
}
}
state
=
{
...
...
@@ -24,6 +24,7 @@ export default class CreateMap extends React.Component {
.
then
((
data
)
=>
data
.
json
())
.
then
((
response
)
=>
{
let
data
=
response
[
0
][
'mapsettings'
];
this
.
handleData
(
data
);
this
.
setState
({
mapsettings
:
data
,
loaded
:
true
,
...
...
@@ -34,6 +35,24 @@ export default class CreateMap extends React.Component {
});
}
handleData
=
(
data
)
=>
{
let
areasettings
=
data
.
areasettings
;
let
layer
=
data
.
layers
&&
data
.
layers
[
0
];
if
(
layer
)
{
areasettings
.
areaName
=
layer
.
areaName
?
layer
.
areaName
:
areasettings
.
areaName
;
areasettings
.
backgroundColor
=
layer
.
backgroundColor
?
layer
.
backgroundColor
:
areasettings
.
backgroundColor
;
areasettings
.
backgroundOpacity
=
layer
.
backgroundOpacity
?
layer
.
backgroundOpacity
:
areasettings
.
backgroundOpacity
;
areasettings
.
boundColor
=
layer
.
boundColor
?
layer
.
boundColor
:
areasettings
.
boundColor
;
areasettings
.
boundWidth
=
layer
.
boundWidth
?
layer
.
boundWidth
:
areasettings
.
boundWidth
;
areasettings
.
extent
=
layer
.
extent
?
layer
.
extent
:
areasettings
.
extent
;
data
.
basemaps
=
layer
.
basemaps
?
layer
.
basemaps
:
data
.
basemaps
;
}
};
render
()
{
const
{
loaded
,
mapsettings
}
=
this
.
state
;
return
(
...
...
packages/map/src/index.js
View file @
61fff4c1
This diff is collapsed.
Click to expand it.
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