Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2.14 KB

File metadata and controls

63 lines (44 loc) · 2.14 KB

Add isoline routing using isoline of the Routing API

Add the following code before </script> tag

        
            var myLoc = myPos.lat + ',' + myPos.lng;
            var routingParams = {
                'mode': 'fastest;car;',
                'start': myLoc,
                'range': '600', // 10 (10x60secs) minutes of driving 
                'rangetype': 'time'
            };

            // Define a callback function to process the isoline response.

            var onResult = function(result) {
                var center = new H.geo.Point(
                    result.response.center.latitude,
                    result.response.center.longitude),
                isolineCoords = result.response.isoline[0].component[0].shape,
                linestring = new H.geo.LineString(),
                isolinePolygon,
                isolineCenter;

                // Add the returned isoline coordinates to a linestring:

                isolineCoords.forEach(function(coords) {
                    linestring.pushLatLngAlt.apply(linestring, coords.split(','))
                })

                // Create a polygon and a marker representing the isoline:

                isolinePolygon = new H.map.Polygon(linestring);
                
                // Add the polygon and marker to the map:

                map.addObject(isolinePolygon);

                // Center and zoom the map so that the whole isoline polygon is
                // in the viewport:

                map.getViewModel().setLookAtData({bounds: isolinePolygon.getBoundingBox()});
            }

            // Get an instance of the routing service: 

            var router = platform.getRoutingService();

            // Call the Routing API to calculate an isoline:

            router.calculateIsoline(
                routingParams,
                onResult,
                function(error) {
                    alert(error.message)
                }
            );


Double-click on saved file to view on browser

Foo