Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
许航嘉
geojson-vt-LSGlobe
Commits
7ac6a17a
Commit
7ac6a17a
authored
10 years ago
by
Vladimir Agafonkin
Browse files
Options
Download
Email Patches
Plain Diff
nicer logging and cleanup
parent
685caef3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
53 deletions
+43
-53
debug/debug.js
debug/debug.js
+3
-13
src/clip.js
src/clip.js
+10
-15
src/convert.js
src/convert.js
+4
-9
src/index.js
src/index.js
+26
-16
No files found.
debug/debug.js
View file @
7ac6a17a
var
geojsonvt
=
require
(
'
../src/index.js
'
);
console
.
time
(
'
load
'
);
var
data
=
require
(
'
./data/h
sa
.json
'
);
console
.
timeEnd
(
'
load
'
);
console
.
time
(
'
load
data
'
);
var
data
=
require
(
'
./data/h
rr
.json
'
);
console
.
timeEnd
(
'
load
data
'
);
var
tileIndex
=
geojsonvt
(
data
,
14
);
console
.
log
(
tileIndex
.
stats
);
// tileIndex.maxZoom = 14;
// tileIndex.getTile(14, 4100, 6200);
// console.log(tileIndex.stats);
// tileIndex.getTile(14, 4100, 6000);
// console.log(tileIndex.stats);
var
keys
=
Object
.
keys
(
tileIndex
.
tiles
);
console
.
log
(
'
total tiles
'
,
keys
.
length
);
This diff is collapsed.
Click to expand it.
src/clip.js
View file @
7ac6a17a
...
...
@@ -11,23 +11,19 @@ module.exports = clip;
function
clip
(
features
,
scale
,
k1
,
k2
,
axis
,
intersect
)
{
var
clipped
=
[];
k1
/=
scale
;
k2
/=
scale
;
var
clipped
=
[];
for
(
var
i
=
0
;
i
<
features
.
length
;
i
++
)
{
var
geometry
=
features
[
i
].
geometry
,
type
=
features
[
i
].
type
,
slices
;
if
(
type
===
1
)
{
slices
=
clipPoints
(
geometry
,
k1
,
k2
,
axis
);
type
=
features
[
i
].
type
;
}
else
{
slices
=
clipGeometry
(
geometry
,
k1
,
k2
,
axis
,
intersect
,
type
===
3
);
}
var
slices
=
type
===
1
?
clipPoints
(
geometry
,
k1
,
k2
,
axis
)
:
clipGeometry
(
geometry
,
k1
,
k2
,
axis
,
intersect
,
type
===
3
);
if
(
slices
.
length
)
{
clipped
.
push
({
...
...
@@ -42,15 +38,14 @@ function clip(features, scale, k1, k2, axis, intersect) {
}
function
clipPoints
(
geometry
,
k1
,
k2
,
axis
)
{
var
slice
=
[];
for
(
var
i
=
0
,
a
,
ak
;
i
<
geometry
.
length
;
i
++
)
{
a
=
geometry
[
i
];
ak
=
a
[
axis
];
for
(
var
i
=
0
;
i
<
geometry
.
length
;
i
++
)
{
var
a
=
geometry
[
i
],
ak
=
a
[
axis
];
if
(
ak
>=
k1
&&
ak
<=
k2
)
slice
.
push
(
a
);
}
return
slice
;
}
...
...
This diff is collapsed.
Click to expand it.
src/convert.js
View file @
7ac6a17a
...
...
@@ -13,16 +13,11 @@ function convert(feature, tolerance) {
tags
=
feature
.
properties
,
i
,
j
,
rings
;
if
(
type
===
'
Point
'
)
{
return
create
(
tags
,
1
,
[
projectPoint
(
coords
)]);
if
(
type
===
'
Point
'
)
return
create
(
tags
,
1
,
[
projectPoint
(
coords
)]);
else
if
(
type
===
'
MultiPoint
'
)
return
create
(
tags
,
1
,
project
(
coords
));
else
if
(
type
===
'
LineString
'
)
return
create
(
tags
,
2
,
[
project
(
coords
,
tolerance
)]);
}
else
if
(
type
===
'
MultiPoint
'
)
{
return
create
(
tags
,
1
,
project
(
coords
));
}
else
if
(
type
===
'
LineString
'
)
{
return
create
(
tags
,
2
,
[
project
(
coords
,
tolerance
)]);
}
else
if
(
type
===
'
MultiLineString
'
||
type
===
'
Polygon
'
)
{
else
if
(
type
===
'
MultiLineString
'
||
type
===
'
Polygon
'
)
{
rings
=
[];
for
(
i
=
0
;
i
<
coords
.
length
;
i
++
)
{
rings
.
push
(
project
(
coords
[
i
],
tolerance
));
...
...
This diff is collapsed.
Click to expand it.
src/index.js
View file @
7ac6a17a
...
...
@@ -26,22 +26,32 @@ function GeoJSONVT(data, maxZoom) {
this
.
maxZoom
=
maxZoom
;
this
.
maxPoints
=
100
;
if
(
debug
)
console
.
time
(
'
preprocess features
'
);
if
(
debug
)
console
.
time
(
'
preprocess data
'
);
var
features
=
[],
z2
=
Math
.
pow
(
2
,
maxZoom
)
;
z2
=
1
<<
maxZoom
;
for
(
var
i
=
0
;
i
<
data
.
features
.
length
;
i
++
)
{
var
feature
=
convert
(
data
.
features
[
i
],
tolerance
/
z2
);
if
(
feature
)
features
.
push
(
feature
);
}
if
(
debug
)
console
.
timeEnd
(
'
preprocess features
'
);
this
.
tiles
=
{};
this
.
stats
=
{};
if
(
debug
)
console
.
time
(
'
generate tiles
'
);
if
(
debug
)
{
console
.
timeEnd
(
'
preprocess data
'
);
console
.
time
(
'
generate tiles
'
);
this
.
stats
=
{};
this
.
total
=
0
;
}
this
.
splitTile
(
features
,
0
,
0
,
0
);
if
(
debug
)
console
.
timeEnd
(
'
generate tiles
'
);
if
(
debug
)
{
console
.
timeEnd
(
'
generate tiles
'
);
console
.
log
(
'
%d tiles generated:
'
,
this
.
total
);
console
.
log
(
this
.
stats
);
}
}
GeoJSONVT
.
prototype
.
splitTile
=
function
(
features
,
z
,
x
,
y
,
cz
,
cx
,
cy
)
{
...
...
@@ -65,11 +75,12 @@ GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
if
(
debug
)
{
if
(
debug2
)
{
console
.
log
(
'
tile z
'
+
z
+
'
-
'
+
x
+
'
-
'
+
y
+
'
(features:
'
+
tile
.
numFeatures
+
'
, points:
'
+
tile
.
numPoints
+
'
, simplified:
'
+
tile
.
numSimplified
+
'
)
'
);
console
.
log
(
'
tile z
%d-%d-%d (features: %d, points: %d, simplified: %d)
'
,
z
,
x
,
y
,
tile
.
numFeatures
,
tile
.
numPoints
,
tile
.
numSimplified
);
console
.
timeEnd
(
'
creation
'
);
}
this
.
stats
[
z
]
=
(
this
.
stats
[
z
]
||
0
)
+
1
;
this
.
total
++
;
}
}
...
...
@@ -125,7 +136,7 @@ GeoJSONVT.prototype.getTile = function (z, x, y) {
var
id
=
toID
(
z
,
x
,
y
);
if
(
this
.
tiles
[
id
])
return
this
.
tiles
[
id
];
if
(
debug
)
console
.
log
(
'
drilling down to
'
,
z
,
x
,
y
);
if
(
debug
)
console
.
log
(
'
drilling down to
z%d-%d-%d
'
,
z
,
x
,
y
);
var
z0
=
z
,
x0
=
x
,
...
...
@@ -139,14 +150,13 @@ GeoJSONVT.prototype.getTile = function (z, x, y) {
parent
=
this
.
tiles
[
toID
(
z0
,
x0
,
y0
)];
}
if
(
debug
)
{
console
.
log
(
'
parent tile
'
,
z0
,
x0
,
y0
,
parent
.
source
&&
parent
.
source
.
length
);
console
.
time
(
'
drilling down
'
);
}
if
(
debug
)
console
.
log
(
'
found parent tile z%d-%d-%d
'
,
z0
,
x0
,
y0
);
if
(
parent
.
source
)
this
.
splitTile
(
parent
.
source
,
z0
,
x0
,
y0
,
z
,
x
,
y
);
if
(
debug
)
console
.
timeEnd
(
'
drilling down
'
);
if
(
parent
.
source
)
{
if
(
debug
)
console
.
time
(
'
drilling down
'
);
this
.
splitTile
(
parent
.
source
,
z0
,
x0
,
y0
,
z
,
x
,
y
);
if
(
debug
)
console
.
timeEnd
(
'
drilling down
'
);
}
return
this
.
tiles
[
id
];
};
...
...
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