Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!