Search code examples
here-api

Raster map doesn't work correct after 3.1 version


I'm updated Maps API for JavaScript to 3.1v. After that Raster map doesn't show correctly. After some zooms getting not a clear picture and problems with the font. Actual:

I've tried to put some different pixel ratio and another map types but it didn't help. Is there a bug?

This is how I init map:

var platform = new H.service.Platform({
            'apikey': apiKey,
        });

 $scope.defaultLayers = platform.createDefaultLayers({
            tileSize: pixelRatio === 1 ? 256 : 512,
            ppi: pixelRatio === 1 ? undefined : 320,
            pois: true
        });
        $scope.geocoder = platform.getGeocodingService();

        $scope.map = new H.Map(
            document.getElementById("here-map-canvas"),
            $scope.defaultLayers.raster.normal.map,
            {
                zoom: 12,
                center: { lat: officeLat, lng: officeLng }
            });

        $scope.markerGroup = new H.map.Group();

        $scope.map.addObject($scope.markerGroup);



        var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents($scope.map));                                                    //Step 3: make the map interactive

        $scope.ui = H.ui.UI.createDefault($scope.map, $scope.defaultLayers);    ```

**Please check imgs:**

Actual: https://i.sstatic.net/Vu17g.jpg
Expected: https://i.sstatic.net/Tcid8.jpg



<meta name="viewport" content="width=device-width, initial-scale=1.0">
Refs:
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css?dp-version=1549984893" />
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core-legacy.js"></script>
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service-legacy.js"></script>
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
        <script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>

Solution

  • Add pixelRatio parameter next to zoom & center:

    $scope.map = new H.Map(
        document.getElementById("here-map-canvas"),
        $scope.defaultLayers.raster.normal.map,
        {
            zoom: 12,
            center: { lat: officeLat, lng: officeLng },
            pixelRatio: window.devicePixelRatio || 1
        }
    );
    

    and disable fractional zoom on Behavior as well as ZoomControl UI (which is enabled by default in v3.1):

    behavior.disable(H.mapevents.Behavior.Feature.FRACTIONAL_ZOOM);
    
    $scope.ui.removeControl('zoom');
    $scope.ui.addControl('zoom', new H.ui.ZoomControl({
      fractionalZoom: false,
      alignment: H.ui.LayoutAlignment.RIGHT_BOTTOM
    }));
    

    For more details see documentation for map options: https://developer.here.com/documentation/maps/topics_api/h-map-options.html#h-map-options

    ZoomControl Options: https://developer.here.com/documentation/maps/topics_api/h-ui-zoomcontrol-options.html

    and Features to be disabled on Behavior: https://developer.here.com/documentation/maps/topics_api/h-mapevents-behavior-feature.html