简体   繁体   English

Azure 地图绘图模块打破悬停风格

[英]Azure maps drawing module breaks hover style

Using the samples, I have the simple case of setting the cursor to pointer when the user hovers over a pin on the map;使用示例,我有一个简单的例子,当用户将鼠标悬停在地图上的一个大头针上时,将光标设置为指针; something akin to:类似于:

 this.map.events.add('mouseover', layer, () => this.map.getCanvasContainer().style.cursor = 'pointer');

And a similar mouseout event for putting it back to grab.还有一个类似的 mouseout 事件,用于将其重新抓取。 This works, no problems.这行得通,没有问题。

However, when I load the drawing module, this no longer works.但是,当我加载绘图模块时,这不再有效。 If I inspect the elements, I can see the style is still switching between pointer and grab as I hover in the DOM, but it has no effect on the pointer at all any more...如果我检查元素,当我悬停在 DOM 中时,我可以看到样式仍在指针和抓取之间切换,但它对指针不再有任何影响......

Drawing module is loaded with something similar to:绘图模块加载了类似于:

 this.drawingManager = new azDrawing.drawing.DrawingManager(this.map, {...});

The drawing stuff itself works fine.绘图的东西本身工作正常。 Though, actually, 'fine' is an operative word, because whist I'm drawing a polygon, the line rendering between the point and the cursor doesn't actually render properly.虽然,实际上,'fine' 是一个有效的词,因为当我绘制一个多边形时,点和光标之间的线渲染实际上并没有正确渲染。 It doesn't update and render until I stop moving the mouse.在我停止移动鼠标之前,它不会更新和渲染。 The samples have it nice and smooth and clearly rendering and following the mouse as it moves, but my implementation doesn't render that line until I stop moving the mouse.这些示例在鼠标移动时呈现出漂亮、平滑和清晰的渲染和跟随,但我的实现在停止移动鼠标之前不会渲染那条线。

I programmatically enter drawing mode with the simple:我以简单的方式以编程方式进入绘图模式:

 this.drawingManager.setOptions({
         mode: azDrawing.drawing.DrawingMode.drawPolygon
     });

Omitted from the above module loading are just the options for enabling dragging and rotation that I have turned on.上面模块加载中省略的只是我打开的启用拖动和旋转的选项。

It's a fairly simple setup, but there seem to be side effects and I don't really know where to look for what might be causing them to fix them.这是一个相当简单的设置,但似乎有副作用,我真的不知道在哪里寻找可能导致他们修复它们的原因。

Oh, additional version information... This is using an Angular (12) SPA, and the following map imports in my index:哦,附加版本信息...这是使用 Angular (12) SPA,并且在我的索引中导入以下地图:

<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.css" type="text/css" />
<script type="text/javascript" src="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.js" async defer></script>

Any ideas on where I can look and/or more information required?关于我可以在哪里查看和/或需要更多信息的任何想法?

Thanks.谢谢。

I went through and managed to reproduce your issue with the mouse cursor.我通过并设法用鼠标光标重现了您的问题。 Digging into this I eventually found the issue.深入研究这个我最终发现了这个问题。 The drawing manager sets the cursor on the map canvas element, while in most samples and your code, the cursor is set on the map container for the canvas (DIV element that the canvas is inside of).绘图管理器将光标设置在地图画布元素上,而在大多数示例和您的代码中,光标设置在画布的地图容器上(画布所在的 DIV 元素)。 As such, the drawing manager sets the cursor to it's default state on the canvas when loaded, and that cursor takes priority over the parent map container.因此,绘图管理器在加载时将光标设置为画布上的默认状态,并且该光标优先于父地图容器。 The solution if fairly simple, use map.getCanvas() instead of map.getCanvasContainer() .如果解决方案相当简单,请使用map.getCanvas()而不是map.getCanvasContainer() So the following should work:所以以下应该工作:

 this.map.events.add('mouseover', layer, () => this.map.getCanvas().style.cursor = 'pointer');

However, I did find that this ends up overriding the drawing managers behavior.但是,我确实发现这最终会覆盖绘图管理器的行为。 With this in mind a solution is to check to see if the drawing manager is actively being used to draw.考虑到这一点,一个解决方案是检查绘图管理器是否正在积极地用于绘图。 If it is, then don't set the cursor.如果是,则不要设置光标。 Here is a sample that demonstrates this.这是一个演示这一点的示例。

//Create an instance of the drawing manager and display the drawing toolbar.
drawingManager = new atlas.drawing.DrawingManager(map, {
    toolbar: new atlas.control.DrawingToolbar({ position: 'top-right' })
});

//Load some source data.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);

datasource.importDataFromUrl('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson');

//Create a layer.
layer = new atlas.layer.SymbolLayer(datasource);
map.layers.add(layer);

//Add mouse events to power hover experience.
map.events.add('mouseover', layer, () => {
    if(drawingManager.getOptions().mode === 'idle'){
        map.getCanvas().style.cursor = 'pointer';
    }
}); 

map.events.add('mouseout', layer, () => {
    if(drawingManager.getOptions().mode === 'idle'){
        map.getCanvas().style.cursor = 'grab';
    }
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM