对于构建Blazor应用程序,我仍然比较陌生,并且发现很难将ArcGIS .NET API指南转换为可工作的Blazor应用程序。我找到的唯一方法就是使用javascript查看我的地图。
有谁知道在哪里可以找到一个很好的教程来实现ArcGIS .NET到Blazor应用程序,而不必使用IJSRuntime呢?
目前正在使用它,而且它正在工作,但是我更希望能够使用Blazor进行操作;然而,ArcGIS .NET指南使用xaml,这似乎不太适合Blazor。
Map.razor:
@page "/maps"
@inject IJSRuntime JS
@using Microsoft.JSInterop
<h3>Map</h3>
<div id="viewDiv" style="padding: 0; margin: 0; height: 1000px; width: 100%"></div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeVoidAsync("initializeMap", null);
StateHasChanged();
}
}
}wwwroot/map.js
function initializeMap() {
require([
"esri/WebMap",
"esri/views/MapView",
"esri/widgets/Legend",
"esri/widgets/ScaleBar",
"esri/layers/GraphicsLayer",
"esri/widgets/Sketch",
"esri/widgets/CoordinateConversion"
], function (WebMap, MapView, Legend, ScaleBar, GraphicsLayer, Sketch, CoordinateConversion) {
var webmap = new WebMap({
portalItem: {
//add your map id
id: "**Omitted**",
layers: [graphicsLayer]
}
});
var view = new MapView({
container: "viewDiv",
map: webmap,
});
var legend = new Legend({
view: view
});
view.ui.add(legend, "top-right");
var scalebar = new ScaleBar({
view: view
});
view.ui.add(scalebar, "bottom-left");
var graphicsLayer = new GraphicsLayer();
webmap.add(graphicsLayer);
var sketch = new Sketch({
view: view,
layer: graphicsLayer
});
view.ui.add(sketch, "top-right");
var coordsWidget = document.createElement("div");
coordsWidget.id = "coordsWidget";
coordsWidget.className = "esri-widget esri-component";
coordsWidget.style.padding = "7px 15px 5px";
view.ui.add(coordsWidget, "bottom-right");
function showCoordinates(pt) {
var coords = "Lat/Lon " + pt.latitude.toFixed(3) + " " + pt.longitude.toFixed(3) +
" | Scale 1:" + Math.round(view.scale * 1) / 1 +
" | Zoom " + view.zoom;
coordsWidget.innerHTML = coords;
}
view.watch("stationary", function (isStationary) {
showCoordinates(view.center);
});
view.on("pointer-move", function (evt) {
showCoordinates(view.toMap({ x: evt.x, y: evt.y }));
});
var coordinateConversionWidget = new CoordinateConversion({
view: view
});
view.ui.add(coordinateConversionWidget, "bottom-right");
});
}发布于 2021-10-31 09:50:24
恭喜,现在问题解决了。
您可以迁移到MAUI,并且很容易地使用XAML来使用ArcGIS。埃斯里还表示,它将很快提供一个版本,用于在毛伊岛使用地理信息系统。
但除此之外,您还可以很容易地在ArcGIS服务器上使用.NET运行时API和.Net ArcObjects SDK。
https://stackoverflow.com/questions/65297439
复制相似问题