Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Create Bingmap pushpins from shape name

I need to create pushpins for the below input.

var Countries = ["Austria", "Brazil", "India", "Germany", "USA", "Malaysia"];

Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(Countries, geoDataRequestOptions, map,
        (data) => {
            var value = data.location;
            if (data.results.length > 0 && data.results[0].Polygons !== null) {
                var polygons = data.results[0].Polygons;
                var dataBounds = Microsoft.Maps.LocationRect.fromShapes(data.results[0].Polygons);
                var loc = new Microsoft.Maps.Location(dataBounds.center.latitude, dataBounds.center.longitude);
                var pin = new Microsoft.Maps.Pushpin(loc, {
                        icon: svgIcon,
                        anchor: new Microsoft.Maps.Point(20 / 2, 20 / 2) 
                });
                map.entities.push(pin);
                locs.push(pin);
                map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 80 });  
            }
        });
}, 3000);

I am using GeoDataAPIManager to get the boundary polygons and get the center of the polygon to generate a pushpin. But when loading countries like Malaysia or USA, the pushpins are placed in the sea, as the getboundary() returns multiple polygons and getting the center of the polygon returns the center between the two boundaries which results in the pushpin placed in the sea.

Let me know if there is any alternate way to create the pushpin or to get the center of the polygon.

I already tried the spatial.Math module to get the center.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is a common occurrence when working with polygons as their shape can be such that their center is not within the actually geometry. There are several different ways to do this.

Method 1: This method will fall back to the nearest point to the calculated center that's on the edge of the polygon.

  • Calculate centroid/center either using math library or rough center by using bounding box center.
  • Check to see if the point intersects the polygon, if not, calculate the closest point on the edge of the polygon (shortest distance), then use that point as your center.

Method 2: Focus just on the largest polygon.

  • If the geometry is a MultiPolygon, calculate the area and grab the polygon with the largest area. For the USA, this would give you the polygon for the mainland which is likely desired.
  • Try method 1, using just the largest polygon.

Method 3: Attempt to calculate a visual center using external library.

  • Convert the polygon to GeoJSON using the GeoJSON module in Bing Maps: https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/geojsonwritetogeojson
  • Pass the geojson geometry into this library to calculate the visual center. https://github.com/mapbox/polylabel
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda