简体   繁体   English

在Bing地图上使用一组Lat Long Create TURF

[英]Using set of Lat Long Create TURF on Bing Map

I have area wise set of Latitude and Longitude and want to create TURF territory on Bing Map like showing on below image. 我按纬度和经度设置了区域,想要在Bing地图上创建TURF领土,如下图所示。 I don't know what are ways to create/draw TURF on map. 我不知道在地图上创建/绘制TURF的方法是什么。 I am not sure about any feature or function which is available in Bing MAP SDK to create TURF with event and cetroid pushpin. 我不确定Bing MAP SDK中可用于使用事件和十六进制图钉创建TURF的任何功能。

I tried polygon function but didn't help to create TURF. 我尝试了多边形函数,但没有帮助创建TURF。

https://www.bing.com/api/maps/sdk/mapcontrol/isdk/wktwritetowkt#TS https://www.bing.com/api/maps/sdk/mapcontrol/isdk/wktwritetowkt#TS

    var myGeoJson = {
        "type": "Polygon",
        "coordinates": [[
                [-122.12901, 47.64178],
                [-122.12901, 47.64226],
                [-122.12771, 47.64226],
                [-122.12771, 47.64178],
                [-122.12901, 47.64178]
        ]]
    };
    //Load the GeoJson Module.
    Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {
        //Parse the GeoJson object into a Bing Maps shape.
        var shape = Microsoft.Maps.GeoJson.read(myGeoJson, {
            polygonOptions: {
                fillColor: 'rgba(255,0,0,0.5)',
                strokeColor: 'white',
                strokeThickness: 5
            }
        });
        //Add the shape to the map.
        map.entities.push(shape);
    });

I want to achieve something like shown in attached image. 我想要实现如所附图片所示的效果。

在此处输入图片说明

UPDATE : SDK code added. 更新:SDK代码已添加。

https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/geojsonreadobject#TS https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/geojsonreadobject#TS

    import { ViewContainerRef, Component, ElementRef, OnInit, ViewChild, NgZone } from '@angular/core';
import { Router } from '@angular/router';
import { MapService } from '../../services/map.service';
import { CookieService } from 'ngx-cookie';
import { Config } from '../../config/config';
import { NguiAutoCompleteModule } from '@ngui/auto-complete/dist';
import * as io from 'socket.io-client';
import { CommonUtils } from './../../shared/CommonUtils';
import { fail, throws } from 'assert';
import { Toast, ToastsManager } from 'ng2-toastr/ng2-toastr';
import { OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks';
import { DeviceDetectorService } from 'ngx-device-detector';

declare const Microsoft: any;
declare const Bing;
declare const GeoJson: any;
declare var jQuery: any;
declare var $: any;

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit, OnDestroy {
  connection;
  map: any;
  infobox: any;
  dataLayer: any;
  heatGradientData: any;

  @ViewChild('mapElement') someInput: ElementRef;
  myMap = document.querySelector('#myMap');
  socket: any = null;
  socketURL: string;

  constructor(private mapService: MapService,
    private router: Router, private config: Config,
    private utils: CommonUtils,
    private cookieService: CookieService,
    public toastr: ToastsManager, vRef: ViewContainerRef,
    private deviceService: DeviceDetectorService,
    private zone: NgZone) {
    this.toastr.setRootViewContainerRef(vRef);
  }

  ngOnInit() {

    if (document.readyState != 'complete') {
      document.onreadystatechange = () => {
        if (document.readyState === 'complete') {
          this.loadMapView(this.config.getConstants('mapTypeRoad'));
          this.ReadGeoJson();
        } else {
          this.ngOnInit();
        }
      }
    } else {
      if (document.readyState === 'complete') {
        this.loadMapView(this.config.getConstants('mapTypeRoad'));
        this.ReadGeoJson();
      }
    }

  }

  loadMapView(type: String) {

    var location = new Microsoft.Maps.Location(53.32, -110.29);

    this.map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
      credentials: this.config.get('BingMapKey'),
      center: location,
      mapTypeId: type == this.config.getConstants('mapTypeSatellite') ? Microsoft.Maps.MapTypeId.aerial : Microsoft.Maps.MapTypeId.road,
      zoom: 5,
      liteMode: true,
      enableClickableLogo: false,
      showLogo: false,
      showTermsLink: false,
      showMapTypeSelector: false,
      showTrafficButton: true,
      enableSearchLogo: false,
      showCopyright: false
    });

    //Load the Animation Module
    Microsoft.Maps.loadModule('AnimationModule', function () {
    });

    //Store some metadata with the pushpin
    this.infobox = new Microsoft.Maps.Infobox(this.map.getCenter(), {
      visible: false
    });

    this.infobox.setMap(this.map);

    // Load the Spatial Math module.
    Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () { });

    //Create a layer to add the GeoJSON data to.
    this.dataLayer = new Microsoft.Maps.Layer();
    this.map.layers.insert(this.dataLayer);

  }

  ReadGeoJson() {
    Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {
      var featureCollection = Microsoft.Maps.GeoJson.read(this.getSouthAfricaGeoJson(), { polygonOptions: { fillColor: 'rgba(0, 255, 255, 0.3)' } });
      for (var i = 0; i < featureCollection.length; i++) {
        this.map.entities.push(featureCollection[i]);
      }
    });
  }

  getSouthAfricaGeoJson() {
    return { 'type': 'FeatureCollection', 'features': [{ 'type': 'Feature', 'id': 'ZAF', 'properties': { 'name': 'South Africa' }, 'geometry': { 'type': 'Polygon', 'coordinates': [[[31.521001, -29.257387], [31.325561, -29.401978], [30.901763, -29.909957], [30.622813, -30.423776], [30.055716, -31.140269], [28.925553, -32.172041], [28.219756, -32.771953], [27.464608, -33.226964], [26.419452, -33.61495], [25.909664, -33.66704], [25.780628, -33.944646], [25.172862, -33.796851], [24.677853, -33.987176], [23.594043, -33.794474], [22.988189, -33.916431], [22.574157, -33.864083], [21.542799, -34.258839], [20.689053, -34.417175], [20.071261, -34.795137], [19.616405, -34.819166], [19.193278, -34.462599], [18.855315, -34.444306], [18.424643, -33.997873], [18.377411, -34.136521], [18.244499, -33.867752], [18.25008, -33.281431], [17.92519, -32.611291], [18.24791, -32.429131], [18.221762, -31.661633], [17.566918, -30.725721], [17.064416, -29.878641], [17.062918, -29.875954], [16.344977, -28.576705], [16.824017, -28.082162], [17.218929, -28.355943], [17.387497, -28.783514], [17.836152, -28.856378], [18.464899, -29.045462], [19.002127, -28.972443], [19.894734, -28.461105], [19.895768, -24.76779], [20.165726, -24.917962], [20.758609, -25.868136], [20.66647, -26.477453], [20.889609, -26.828543], [21.605896, -26.726534], [22.105969, -26.280256], [22.579532, -25.979448], [22.824271, -25.500459], [23.312097, -25.26869], [23.73357, -25.390129], [24.211267, -25.670216], [25.025171, -25.71967], [25.664666, -25.486816], [25.765849, -25.174845], [25.941652, -24.696373], [26.485753, -24.616327], [26.786407, -24.240691], [27.11941, -23.574323], [28.017236, -22.827754], [29.432188, -22.091313], [29.839037, -22.102216], [30.322883, -22.271612], [30.659865, -22.151567], [31.191409, -22.25151], [31.670398, -23.658969], [31.930589, -24.369417], [31.752408, -25.484284], [31.837778, -25.843332], [31.333158, -25.660191], [31.04408, -25.731452], [30.949667, -26.022649], [30.676609, -26.398078], [30.685962, -26.743845], [31.282773, -27.285879], [31.86806, -27.177927], [32.071665, -26.73382], [32.83012, -26.742192], [32.580265, -27.470158], [32.462133, -28.301011], [32.203389, -28.752405], [31.521001, -29.257387]], [[28.978263, -28.955597], [28.5417, -28.647502], [28.074338, -28.851469], [27.532511, -29.242711], [26.999262, -29.875954], [27.749397, -30.645106], [28.107205, -30.545732], [28.291069, -30.226217], [28.8484, -30.070051], [29.018415, -29.743766], [29.325166, -29.257387], [28.978263, -28.955597]]] } }] };
  }


  stringifyJson(data) {
    return JSON.stringify(data);
  }

  parseToJson(data) {
    return JSON.parse(data);
  }

  stringifyBodyJson(data) {
    return JSON.parse(data['_body']);
  }

  ngOnDestroy() {
    if (this.connection !== undefined) {
      this.connection.unsubscribe();
    }
  }

}

There is a lot of different ways in which you can render data on top of the map. 您可以使用多种不同的方法在地图顶部呈现数据。 GeoJSON is the primary data format used, but it doesn't have to be a file, it can be a locally create GeoJSON object as well. GeoJSON是使用的主要数据格式,但不必一定是文件,它也可以是本地创建的GeoJSON对象。 Here are a bunch of examples of rendering data in Azure Maps: https://azuremapscodesamples.azurewebsites.net/ 这是一堆在Azure Maps中渲染数据的示例: https : //azuremapscodesamples.azurewebsites.net/

Update : Sorry for the confusion. 更新 :很抱歉造成混乱。 I'm on the Azure Maps team at Microsoft and forgot you were asking about Bing Maps. 我在Microsoft的Azure Maps团队工作,却忘记了您在询问Bing Maps。 For Bing Maps, you can use GeoJSON, or KML/GeoRSS/GPX, or create shapes locally using JavaScript. 对于Bing地图,您可以使用GeoJSON或KML / GeoRSS / GPX,也可以使用JavaScript在本地创建形状。 You can find some code samples on Bing Maps here: https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk 您可以在Bing Maps上找到一些代码示例: https : //www.bing.com/api/maps/sdkrelease/mapcontrol/isdk

All that said, I highly recommend you take a look at Azure Maps as it is Microsoft's latest enterprise mapping platform. 综上所述,我强烈建议您看一下Azure Maps,因为它是Microsoft最新的企业级地图平台。

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

相关问题 使用 lat 和 long 在地图上放置位置时如何使用 zoomToMapObject - How to use zoomToMapObject when using lat and long for putting locations on map GeoBson无法使用Bing Map在Angular中工作 - GeoJson is not working in Angular using Bing Map 角谷歌地图在组件加载时变得不确定 - Angular google map getting undefined lat long on components load PrimeNG GMap 组件在从变量传递 lat 和 long 时未显示 map - PrimeNG GMap component is not showing map when passing lat and long from variable Esri Map 在 Angular 页面点击不再加载到纬度? Object.b.locationToAddress 处 null 的“toJSON” - Esri Map in Angular page click no longer loading to lat long? 'toJSON' of null at Object.b.locationToAddress 我如何从外部传递 lat,long 以创建 leaflet 标记 angular - how can i pass lat,long from outside to create a leaflet marker angular 将标头传递给 bing 地图 API - Passing headers to bing map API 如何在 leaflet map 上显示起点到终点的路线,所有标记都从 api 在 agular13 - how to show start point to end point route on leaflet map with all marker which lat long commung from api in agular13 从 angular 中的给定 lat 和 long 列表中检测边界 lat long - detect boundary lat longs from given list of lat and long in angular 角度-无法使用Bing Map图钉单击重定向到另一个组件 - Angular - Not able to redirect to another component using Bing Map push pin click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM