none
GeoDataAPI - getBoundary - shape styling RRS feed

  • Question

  • Hi everybody,

    how is it possible to set the Default style for the boundaries?

    I have a function like:

    function getBoundaries2() {
        Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
            Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(map2.getCenter(), geoDataRequestOptions, map2, function (data) {
                if (data.results && data.results.length > 0) {
                    map2.entities.push(data.results[0].Polygons);
                }
            });
        });
    }

    Sure, it is possible to set the style like this:

    var boundary = new Microsoft.Maps.Polygon(<whatComesInHere?>, {
        fillColor: 'rgba(0,0,255,0.5)',
        strokeColor: 'blue',
        strokeThickness: 2
    });

    But what "rings" do I have to set in for the <whatComesInHere?> to get the Polygons from the boundary-query and where do I have to define it?

    Thanks a lot for your help!

    Monday, September 19, 2016 1:14 PM

Answers

  • The getBoundary function returns an array of Polygon objects, you do not need to create new polygons, simply set the style you want on them like so:

    for(var i=0,len=data.results[0].Polygons.length;i<len;i++){
    	data.results[0].Polygons[i].setOptions({
    		fillColor: 'rgba(0,0,255,0.5)',
    		strokeColor: 'blue',
    		strokeThickness: 2
    	 });
    }


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, September 20, 2016 12:31 AM
    • Marked as answer by Gedl77 Tuesday, September 20, 2016 6:51 AM
    Tuesday, September 20, 2016 12:31 AM

All replies

  • The getBoundary function returns an array of Polygon objects, you do not need to create new polygons, simply set the style you want on them like so:

    for(var i=0,len=data.results[0].Polygons.length;i<len;i++){
    	data.results[0].Polygons[i].setOptions({
    		fillColor: 'rgba(0,0,255,0.5)',
    		strokeColor: 'blue',
    		strokeThickness: 2
    	 });
    }


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Tuesday, September 20, 2016 12:31 AM
    • Marked as answer by Gedl77 Tuesday, September 20, 2016 6:51 AM
    Tuesday, September 20, 2016 12:31 AM
  • Hi Ricky,

    thanks a lot for your help! That works fine.

    Tuesday, September 20, 2016 6:52 AM