-
Notifications
You must be signed in to change notification settings - Fork 510
fix Geometry cursor Not working properly #2149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9640d05
fix Geometry cursor Not working properly
deyihu 2b0c631
spec
deyihu a5207dd
delete isGeometryListening
deyihu da8226e
add pickutil for gllayer pick performance
deyihu a22695d
updates
deyihu c7c5c4d
Merge branch 'master' into 2148
deyihu 5f6329d
Merge branch 'master' into 2148
deyihu 3723643
Merge branch 'master' into 2148
fuzhenn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* | ||
* layer pick utils | ||
* can use by PointLayer,LineStringLayer,PolygonLayer,VectorTileLayer,Geo3DTilesLayer,GLTFLayer etc | ||
* | ||
* @returns | ||
*/ | ||
import Canvas from '../Canvas'; | ||
|
||
export function isGLRenderLayer(layer) { | ||
if (!layer) { | ||
return false; | ||
} | ||
const renderer = layer.getRenderer && layer.getRenderer(); | ||
return !!(renderer && renderer.gl); | ||
} | ||
|
||
export function checkCanvasSize(targetCanvas, sourceCanvas) { | ||
if (!targetCanvas || !sourceCanvas) { | ||
return null; | ||
} | ||
const { width, height, style } = sourceCanvas; | ||
if (targetCanvas.width !== width || targetCanvas.height !== height) { | ||
targetCanvas.width = width; | ||
targetCanvas.height = height; | ||
} | ||
if (targetCanvas.style.width !== style.width || targetCanvas.style.height !== style.height) { | ||
targetCanvas.style.width = style.width; | ||
targetCanvas.style.height = style.height; | ||
} | ||
return targetCanvas; | ||
} | ||
|
||
export function clearCanvas(canvas) { | ||
if (!canvas) { | ||
return null; | ||
} | ||
const ctx = Canvas.getCanvas2DContext(canvas); | ||
Canvas.clearRect(ctx, 0, 0, canvas.width, canvas.height); | ||
return ctx; | ||
} | ||
|
||
let tempCanvas; | ||
export function layerIsBlankInPoint(layer, containerPoint, tolerance = 1) { | ||
if (!layer || !containerPoint) { | ||
return true; | ||
} | ||
const renderer = layer.getRenderer && layer.getRenderer(); | ||
if (!renderer || !renderer.canvas) { | ||
return true; | ||
} | ||
const map = layer.getMap(); | ||
if (!map) { | ||
return true; | ||
} | ||
if (!tempCanvas) { | ||
tempCanvas = Canvas.createCanvas(1, 1); | ||
// document.body.appendChild(tempCanvas); | ||
} | ||
tempCanvas = checkCanvasSize(tempCanvas, renderer.canvas); | ||
if (!tempCanvas) { | ||
return true; | ||
} | ||
const ctx = clearCanvas(tempCanvas); | ||
if (!ctx) { | ||
return true; | ||
} | ||
tolerance = Math.max(layer.options.geometryEventTolerance || 1, tolerance); | ||
tolerance = Math.abs(Math.round(tolerance)); | ||
tolerance = Math.max(1, tolerance); | ||
const r = map.getDevicePixelRatio(); | ||
const { x, y } = containerPoint; | ||
let left = x - tolerance, top = y - tolerance; | ||
left = Math.round(left * r); | ||
top = Math.round(top * r); | ||
left = Math.max(0, left); | ||
top = Math.max(0, top); | ||
const size = tolerance * 2; | ||
let imageData; | ||
try { | ||
ctx.drawImage(renderer.canvas, 0, 0); | ||
imageData = ctx.getImageData(left, top, size, size); | ||
} catch (error) { | ||
console.warn('hit detect failed with tainted canvas, some geometries have external resources in another domain:\n', error); | ||
} | ||
if (!imageData) { | ||
return false; | ||
} | ||
const data = imageData.data; | ||
for (let i = 0, len = data.length; i < len; i += 4) { | ||
const A = data[i + 3]; | ||
if (A > 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个判断有点宽泛了,感觉最合理的做法是判断当前点是否于geometry的containerExtent相交,只有相交才return true,尽量避免该查询
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有道理,不过:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个倒是不会,geometry的bbox计算不咋耗性能,比webgl图层去read pixel要好很多
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
经过测试,改方法不可行,太耗时了,改用地图画布颜色检测,即地图画布的全局图形法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
刚试了下,不行,因为地图画布可能一直不是空的,比如有tilelayer的情况下,永远有颜色值的
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
经过验证还是要通过判断图层的颜色值是否为空来完成,参考VectorLayer的实现
@fuzhenn