How to set Dynamic zoom level based on Geofence Polygon coordinates RRS feed

  • Question

  • Hi Team,

    We are binding the geofence polygons in the map and grid.

    On selecting each grid row, we need to show the respective geofence polygon.

    Note: Each polygon geofence contains list of lat/long coordinates.

    Here is my code on grid row click:

    static ShowSelectedGeofence(selectedRow: any) {
            var dataItem = null;
            for (var i = 0; i < GeofencesData.length; i++) {
                if (GeofencesData[i].Name.toString() == selectedRow.Name.toString()) {
                    dataItem = GeofencesData[i];

            if (pinInfobox != null) {
                pinInfobox.setOptions({ visible: false });

            var exteriorRing = dataItem.FormatedCoordinates; // list of polygon coordinates
            var polygon = new Microsoft.Maps.Polygon(exteriorRing, null);

            var center = Microsoft.Maps.SpatialMath.Geometry.centroid(polygon);
            var popOffset = new Microsoft.Maps.Point(-4, 100);
            var identityCode = GenerateAlphaNumericCode(6);
            /* InfoBox Code Starts     */
            var description = '<div id=' + identityCode + ' class="tab-infobox"></div>';
            var DescElement = React.createElement(MapCallouts.PinInfoboxFenceLocation, { selectedPin: dataItem, divid: identityCode, source: "GeofenceMgmt" });
            RCUtils.RenderChildComponent(identityCode, DescElement);
            // Create the infobox for the pushpin
                maxHeight: 80,
                maxWidth: 540,
                showPointer: true,
                description: description,
                location: new Microsoft.Maps.Location(center.latitude, center.longitude),
                visible: true, offset: popOffset,
                showCloseButton: true

                center: center,
                zoom: 12
            });       // setting static zoom level as 12


    In the above code, geofenceMap.setView zoom level is applied static value 12.

    Based on the polygon coordinates, do we have an option to view the polygon without setting the static zoom level?

    Please suggest.

    Thanks & Regards

    Friday, March 20, 2020 6:27 AM

All replies