Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

how to solve nativescript-google-maps-sdk issue with NS 7 and Angular 10

is there any way to fix it? I am using Nativescript 7 with angular 10.

ERROR Error: Uncaught (in promise): TypeError: Class constructor View cannot be invoked without 'new' JS: TypeError: Class constructor View cannot be invoked without 'new' JS: at MapViewBase [as constructor] (file: node_modules/nativescript-google-maps-sdk/map-view-common.js:128:0) JS: at new MapView (file: node_modules/nativescript-google-maps-sdk/map-view.android.js:14:0) JS: at ViewUtil.createView (file: node_modules/@nativescript/angular/fesm2015/nativescript-angular.js:2583:0) JS: at EmulatedRenderer.createElement (file: node_modules/@nativescript/angular/fesm2015/nativescript-angular.js:2783:0) JS: at EmulatedRenderer.createElement (file: node_modules/@nativescript/angular/fesm2015/nativescript-angular.js:3000:0) JS: at elementCreate (file: node_modules/@angular/core/fesm2015/core.js:7143:0) JS: at Module.??elementStart (file: node_modules/@angular/core/fesm2015/core.js:14774:0)

question from:https://stackoverflow.com/questions/65601568/how-to-solve-nativescript-google-maps-sdk-issue-with-ns-7-and-angular-10

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There might be an issue in google-map-sdk library. I hope it will be fixed ASAP. Until then, we can copy and paste the code below to /node_modules/nativescript-google-maps-sdk/map-view.ios.js file.

import { MapViewBase, BoundsBase, CircleBase, MarkerBase, PolygonBase, PolylineBase, ProjectionBase, PositionBase, latitudeProperty, VisibleRegionBase, longitudeProperty, bearingProperty, zoomProperty, tiltProperty, getColorHue } from "./map-view-common";
import { GC, layout } from "@nativescript/core/utils";
import { Image, ImageSource } from "@nativescript/core";
export * from "./map-view-common";
var IndoorDisplayDelegateImpl = /** @class */ (function (_super) {
    __extends(IndoorDisplayDelegateImpl, _super);
    function IndoorDisplayDelegateImpl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    IndoorDisplayDelegateImpl.initWithOwner = function (owner) {
        var handler = IndoorDisplayDelegateImpl.new();
        handler._owner = owner;
        return handler;
    };
    IndoorDisplayDelegateImpl.prototype.didChangeActiveBuilding = function (indoorBuilding) {
        var owner = this._owner.get();
        if (owner) {
            var data = null;
            if (indoorBuilding) {
                var levels = [];
                var count = 0;
                while (count < indoorBuilding.levels.count) {
                    levels.push({
                        name: indoorBuilding.levels[count].name,
                        shortName: indoorBuilding.levels[count].shortName,
                    });
                    count += 1;
                }
                data = {
                    defaultLevelIndex: indoorBuilding.defaultLevelIndex,
                    levels: levels,
                    isUnderground: indoorBuilding.underground,
                };
            }
            owner.notifyBuildingFocusedEvent(data);
        }
    };
    IndoorDisplayDelegateImpl.prototype.didChangeActiveLevel = function (activateLevel) {
        var owner = this._owner.get();
        if (owner) {
            var data = null;
            if (activateLevel) {
                data = {
                    name: activateLevel.name,
                    shortName: activateLevel.shortName,
                };
            }
            owner.notifyIndoorLevelActivatedEvent(data);
        }
    };
    IndoorDisplayDelegateImpl.ObjCProtocols = [GMSIndoorDisplayDelegate];
    return IndoorDisplayDelegateImpl;
}(NSObject));
var MapViewDelegateImpl = /** @class */ (function (_super) {
    __extends(MapViewDelegateImpl, _super);
    function MapViewDelegateImpl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MapViewDelegateImpl.initWithOwner = function (owner) {
        var handler = MapViewDelegateImpl.new();
        handler._owner = owner;
        return handler;
    };
    MapViewDelegateImpl.prototype.mapViewIdleAtCameraPosition = function (mapView, cameraPosition) {
        var owner = this._owner.get();
        if (owner) {
            owner._processingCameraEvent = true;
            var cameraChanged = false;
            if (owner.latitude != cameraPosition.target.latitude) {
                cameraChanged = true;
                latitudeProperty.nativeValueChange(owner, cameraPosition.target.latitude);
            }
            if (owner.longitude != cameraPosition.target.longitude) {
                cameraChanged = true;
                longitudeProperty.nativeValueChange(owner, cameraPosition.target.longitude);
            }
            if (owner.bearing != cameraPosition.bearing) {
                cameraChanged = true;
                bearingProperty.nativeValueChange(owner, cameraPosition.bearing);
            }
            if (owner.zoom != cameraPosition.zoom) {
                cameraChanged = true;
                zoomProperty.nativeValueChange(owner, cameraPosition.zoom);
            }
            if (owner.tilt != cameraPosition.viewingAngle) {
                cameraChanged = true;
                tiltProperty.nativeValueChange(owner, cameraPosition.viewingAngle);
            }
            if (cameraChanged) {
                owner.notifyCameraEvent(MapViewBase.cameraChangedEvent, {
                    latitude: cameraPosition.target.latitude,
                    longitude: cameraPosition.target.longitude,
                    zoom: cameraPosition.zoom,
                    bearing: cameraPosition.bearing,
                    tilt: cameraPosition.viewingAngle
                });
            }
            owner._processingCameraEvent = false;
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidChangeCameraPosition = function (mapView, cameraPosition) {
        var owner = this._owner.get();
        owner.notifyCameraEvent(MapViewBase.cameraMoveEvent, {
            latitude: cameraPosition.target.latitude,
            longitude: cameraPosition.target.longitude,
            zoom: cameraPosition.zoom,
            bearing: cameraPosition.bearing,
            tilt: cameraPosition.viewingAngle
        });
    };
    MapViewDelegateImpl.prototype.mapViewDidTapAtCoordinate = function (mapView, coordinate) {
        var owner = this._owner.get();
        if (owner) {
            var position = Position.positionFromLatLng(coordinate.latitude, coordinate.longitude);
            owner.notifyPositionEvent(MapViewBase.coordinateTappedEvent, position);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidLongPressAtCoordinate = function (mapView, coordinate) {
        var owner = this._owner.get();
        if (owner) {
            var position = Position.positionFromLatLng(coordinate.latitude, coordinate.longitude);
            owner.notifyPositionEvent(MapViewBase.coordinateLongPressEvent, position);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidTapMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            if (marker) {
                owner.notifyMarkerTapped(marker);
            }
        }
        return false;
    };
    MapViewDelegateImpl.prototype.mapViewDidTapOverlay = function (mapView, gmsOverlay) {
        var owner = this._owner.get();
        if (owner) {
            var shape = owner.findShape(function (shape) { return shape.ios == gmsOverlay; });
            if (shape) {
                owner.notifyShapeTapped(shape);
            }
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidBeginDraggingMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            owner.notifyMarkerBeginDragging(marker);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidEndDraggingMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            owner.notifyMarkerEndDragging(marker);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidDragMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            owner.notifyMarkerDrag(marker);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidTapInfoWindowOfMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            owner.notifyMarkerInfoWindowTapped(marker);
        }
    };
    MapViewDelegateImpl.prototype.mapViewDidCloseInfoWindowOfMarker = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (owner) {
            var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
            owner.notifyMarkerInfoWindowClosed(marker);
        }
    };
    MapViewDelegateImpl.prototype.didTapMyLocationButtonForMapView = function (mapView) {
        var owner = this._owner.get();
        if (owner) {
            owner.notifyMyLocationTapped();
            // Should return false in order to center the map on user position
            return false;
        }
        return true;
    };
    MapViewDelegateImpl.prototype.mapViewMarkerInfoWindow = function (mapView, gmsMarker) {
        return null;
    };
    MapViewDelegateImpl.prototype.mapViewMarkerInfoContents = function (mapView, gmsMarker) {
        var owner = this._owner.get();
        if (!owner)
            return null;
        var marker = owner.findMarker(function (marker) { return marker.ios == gmsMarker; });
        var content = owner._getMarkerInfoWindowContent(marker);
        if (content) {
            var width = Number(content.width);
            if (Number.isNaN(width))
                width = null;
            var height = Number(content.height);
            if (Number.isNaN(height))
                height = null;
            if (!height || !width) {
                var bounds = UIScreen.mainScreen.bounds;
                width = width || (bounds.size.width * .7);
                height = height || (bounds.size.height * .4);
            }
            this._layoutRootView(content, CGRectMake(0, 0, width, height));
            return content.ios;
        }
        return null;
    };
    /*
        Replacement for _layoutRootView method removed in NativeScript 6
    */
    MapViewDelegateImpl.prototype._layoutRootView = function (rootView, parentBounds) {
        if (!rootView || !parentBounds) {
            return;
        }
        var size = parentBounds.size;
        var width = layout.toDevicePixels(size.width);
        var height = layout.toDevicePixels(size.height);
        var widthSpec = layout.makeMeasureSpec(width, layout.EXACTLY);
        var heightSpec = layout.makeMeasureSpec(height, layout.EXACTLY);
        rootView.measure(widthSpec, heightSpec);
        var origin = parentBounds.origin;
        var left = origin.x;
        var top = origin.y;
        rootView.layout(left, top, width, height);
    };
    MapViewDelegateImpl.ObjCProtocols = [GMSMapViewDelegate];
    return MapViewDelegateImpl;
}(NSObject));
export class MapView extends MapViewBase {
    constructor() {
        super();
        this._markers = new Array();
        this.nativeView = GMSMapView.mapWithFrameCamera(CGRectZero, this._createCameraPosition());
        this._delegate = MapViewDelegateImpl.initWithOwner(new WeakRef(this));
        this._indoorDelegate = IndoorDisplayDelegateImpl.initWithOwner(new WeakRef(this));
        this.updatePadding();
    }
    onLoaded() {
        super.onLoaded();
        this.nativeView.delegate = this._delegate;
        this.nativeView.indoorDisplay.delegate = this._indoorDelegate;
        this.notifyMapReady();
    }
    onUnloaded() {
        this.nativeView.delegate = null;
        this.nativeView.indoorDisplay.delegate = null;
        super.onUnloaded();
    }
    disposeNativeView() {
        this._markers = null;
        this._delegate = null;
        this._indoorDelegate = null;
        super.disposeNativeView();
        GC();
    }
    ;
    _createCameraPosition() {
        return GMSCameraPosition.cameraWithLatitudeLongitudeZoomBearingViewingAngle(this.latitude, this.longitude, this.zoom, this.bearing, this.tilt);
    }
    updateCamera() {

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...