Question

These are the errors:

Error   1   Cannot implicitly convert type 'Plantool.xRoute.Point' to 'Plantool.xMap.Point' 
Error   2   Cannot implicitly convert type 'Plantool.xRoute.Point' to 'Plantool.xMap.Point' 
Error   3   Cannot implicitly convert type 'Plantool.xRoute.LineString' to 'Plantool.xMap.LineString'

I have this code which comes with a namespace.

using Plantool; //Contains xMap, xServer, xLocate

And this is the function in question.

    /* createMap()
     * Input: WaypointDesc[], Route
     * Output: string mapURL
     * Edited 21/12/12 - Davide Nguyen
     */
    private static string createMap(xRoute.WaypointDesc[] waypointDesc, xRoute.Route route)
    {
        #region boundingBox
        // Set boundingBox fand use corners from the calculated route
        xMap.BoundingBox boundingBox = new xMap.BoundingBox();
        boundingBox.leftTop = route.totalRectangle.rightTop;
        boundingBox.rightBottom = route.totalRectangle.leftBottom;
        #endregion

        #region mapParams
        // Build mapParams
        xMap.MapParams mapParams = new xMap.MapParams();
        mapParams.showScale = true;
        mapParams.useMiles = false;
        #endregion

        #region imageInfo
        // Create imageInfo and set the frame size and image format. NOTE: 1052; 863
        xMap.ImageInfo imageInfo = new xMap.ImageInfo();
        imageInfo.format = xMap.ImageFileFormat.PNG;
        imageInfo.height = 1052;
        imageInfo.width = 863;
        imageInfo.imageParameter = "";
        #endregion

        #region layers
        // Create a line from the calculated route
        xMap.LineString[] lineStrings = new xMap.LineString[] { route.polygon };
        xMap.Lines[] lines = new xMap.Lines[1];
        xMap.LineOptions options = new xMap.LineOptions();
        xMap.LinePartOptions partoptions = new xMap.LinePartOptions();
        partoptions.color = new xMap.Color();
        partoptions.visible = true;
        partoptions.width = -10;
        options.mainLine = partoptions;

        lines[0] = new xMap.Lines();
        lines[0].wrappedLines = lineStrings;
        lines[0].options = options;

        // Define customLayer that contains the object lines and set layers.
        xMap.CustomLayer customLayer = new xMap.CustomLayer();
        customLayer.visible = true;
        customLayer.drawPriority = 100;
        customLayer.wrappedLines = lines;
        customLayer.objectInfos = xMap.ObjectInfoType.NONE;
        customLayer.centerObjects = true;
        xMap.Layer[] layers = new xMap.Layer[] { customLayer };
        #endregion

        #region includeImageInResponse
        // Set argument includeImageInResponse to false (default).
        Boolean includeImageInResponse = false;
        #endregion

        // Return object map using the following method.
        xMap.Map map = xMapClient.renderMapBoundingBox(boundingBox, mapParams, imageInfo, layers, includeImageInResponse, null);

        // Retrieve the image
        string result = "http://" + map.image.url;

        // Return the drawn map
        return result;
    }

The problem lies with the boundingBox object and the lineString object. route.totalRectangle contains a Point object from the xRoute namespace which is identical to that of xMap. Is there anyway to copy or convert it?

This issue does not seem to happen in java examples, but it does in C#. I am sure that if I can solve this error, the other ones will be solved aswell. I have searched my ass off on the API, but it may help you:

Still digging myself.

Was it helpful?

Solution

In C# you cannot convert from one type to another, even if they are for all purposes identical, without copying all the properites, etc. unless an implicit conversion exists.

So you can either write a implicit conversion opertor as shown in link above or you could use a tool like AutoMapper to copy between the two objects

OTHER TIPS

I have found another solution for this issue in the meanwhile whilst randomly playing with the code and the API and this is a partial solution for two of the errors by copying over the well known text values from one object to another. Hopefully I can do the same for the linestring part. I am posting this just incase anyone else comes across this and finds it a usefull solution. New code region below.

        // Set boundingBox fand use corners from the calculated route
        xMap.BoundingBox boundingBox = new xMap.BoundingBox();
        xMap.Point rightTop = new xMap.Point();
        rightTop.wkt = route.totalRectangle.rightTop.wkt;
        xMap.Point leftBottom = new xMap.Point();
        leftBottom.wkt = route.totalRectangle.leftBottom.wkt;
        boundingBox.leftTop = rightTop;
        boundingBox.rightBottom = leftBottom;

EDIT: Same solution for the linestrings.

        // Solution: Cannot implicitly conver ttype xRoute.LineString to xMap.LineString
        xMap.LineString maproute = new xMap.LineString();
        maproute.wkt = route.polygon.wkt;

        // Create a line from the calculated route
        xMap.LineString[] lineStrings = new xMap.LineString[] { maproute };

Thanks for the help, I hope someone might find this solution usefull aswell.

Review this for your own purposes... but one option is to use a JSON Parser to serialize one class into JSON, then to deserialize it back into a different class. Short and simple answer, but if all you are looking for is to grab properties from Contoso.Project.UrMom, and transfer them directly to Albiet.Project.UrMom, it works well.

I've found this other alternative that is based on serialization of the objects. As far as I'm concerned it has the disadvantage of accessing the disk.

How did you create the client classes from the WSDL's? I prefer to create them via command line:

WSDL /sharetypes /out:"XServer.cs" /namespace:"Plantool"
"https://xroute-eu-n-test.cloud.ptvgroup.com/xlocate/ws/XLocate?WSDL"
"https://xroute-eu-n-test.cloud.ptvgroup.com/xroute/ws/XRoute?WSDL"
"https://xroute-eu-n-test.cloud.ptvgroup.com/xtour/ws/XTour?WSDL"

/sharetypes ensures that classes such as Point will be merged intoa single shared class

This also works fine with the xServer2 API and it's WSDLs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top