none
DrawingTools how to add metadata = {customId : int(unique id)} at drawingEnded RRS feed

  • Question

  • Hello

    I am using bing map v8, Web Controls DrawingTools

    I would like to add metadata to the shape when client create it at drawingEnded

    When I load a recorded shape from DB , I am able to add this info polygon.metadata = {customID:int(id from DB)}

    just before drawingManager.add(polygon);

    I need to add this info to the shapes for better identification and management and i would prefer to avoid to record it in DB adding this customId then clear() and reload() my shapes from DB

    Thanks for your light

    Wednesday, March 22, 2017 11:55 AM

Answers

  • Thursday, March 23, 2017 2:22 AM
  • I think i found solution

    I Cut Paste the shapes and in the middle I add the metadata

    I do not know if this solution is the best one but working

    var shapes = drawingManager.getPrimitives();
                
            if (shapes && shapes.length > 0) {
                alert('Retrieved ' + shapes.length + ' from the drawing manager.');
                
                for(i=0; i<shapes.length; i++ )
                {
                     
                    if (!shapes[i].metadata)
                    {
                        
                        alert(shapes[i].getRings()+' ---  no data');

    var customid = Number(new Date());

                         copyShape = new Microsoft.Maps.Polygon(shapes[i].getRings());

                        copyShape.metadata = {
                        customID: customid
                    };
                    drawingManager.remove(shapes[i]);
                    drawingManager.add(copyShape);

           
                    }
                    else
                    {
                        alert(shapes[i].getRings()+' --- '+shapes[i].metadata.customID);
                    }
                    
                }


    • Edited by Stef519 Thursday, March 23, 2017 9:21 AM
    • Proposed as answer by Ricky_Brundritt Thursday, March 23, 2017 5:24 PM
    • Marked as answer by Ricky_Brundritt Thursday, March 23, 2017 5:24 PM
    Thursday, March 23, 2017 8:14 AM

All replies

  • Thursday, March 23, 2017 2:22 AM
  • hello Thanks
    but this is not exactly what I need , I want to put metadata when i create polygon with the tools bar

    at least a time stamp as default, in your sample the shape is created then you add it in drawingtools

    but when you create a new one there is no metadata...

    Is there any possibility or i have to use the DrawingTools_CustomToolbar.html to achive it ?

    function drawPolygon() {
    if (setMode('polygon')){
    //Create a new polygon.

    tools.create(Microsoft.Maps.DrawingTools.ShapeType.polygon, function (s) {

    s.metadata = { customId : timestamp };

    s.setOptions(style);
    currentShape = s;
    });
    }
    }

    thanks

    BR

     
    Thursday, March 23, 2017 7:11 AM
  • I think i found solution

    I Cut Paste the shapes and in the middle I add the metadata

    I do not know if this solution is the best one but working

    var shapes = drawingManager.getPrimitives();
                
            if (shapes && shapes.length > 0) {
                alert('Retrieved ' + shapes.length + ' from the drawing manager.');
                
                for(i=0; i<shapes.length; i++ )
                {
                     
                    if (!shapes[i].metadata)
                    {
                        
                        alert(shapes[i].getRings()+' ---  no data');

    var customid = Number(new Date());

                         copyShape = new Microsoft.Maps.Polygon(shapes[i].getRings());

                        copyShape.metadata = {
                        customID: customid
                    };
                    drawingManager.remove(shapes[i]);
                    drawingManager.add(copyShape);

           
                    }
                    else
                    {
                        alert(shapes[i].getRings()+' --- '+shapes[i].metadata.customID);
                    }
                    
                }


    • Edited by Stef519 Thursday, March 23, 2017 9:21 AM
    • Proposed as answer by Ricky_Brundritt Thursday, March 23, 2017 5:24 PM
    • Marked as answer by Ricky_Brundritt Thursday, March 23, 2017 5:24 PM
    Thursday, March 23, 2017 8:14 AM