none
Bug with WKT MULTIPOLYGON setOptions({ visible: true }); ? RRS feed

  • Question

  • Hey everyone!

    Like many others I'm sure, I'm porting a V7 map implementation over to V8 and I believe I've run into a bug, which is a bit of a showstopper for us.

    I've isolated it as much as I can and it involves using the setOptions to make a shape using a WKT MULTIPOLYGON either visible or non, either straight from the page or fired from an event.  If I take out the setOptions it will draw and display the shape just fine, but, as I invoke the setOptions, it will bomb on that line.  Nor will it take effect if I trigger it from an event.  If I use a plain WKT POLYGON, voila, it starts working properly like it did in V7.

    Here's the function:



       function GetMap() {

           Microsoft.Maps.loadModule("Microsoft.Maps.WellKnownText");

           var bingMap = new Microsoft.Maps.Map(document.getElementById("MyTestMap"), {

               credentials: "ABC123",
               center: new Microsoft.Maps.Location(33.146190241986119, -86.482209833117281),
               zoom: 9,
               showDashboard: true,
               mapTypeId: Microsoft.Maps.MapTypeId.auto,
               showMapTypeSelector: true,
               showScalebar: true,
               enableSearchLogo: false
           });

           var someplace = new Microsoft.Maps.Location(33.146190241986119, -86.482209833117281);
           var pushpin = new Microsoft.Maps.Pushpin(someplace, null);

           bingMap.entities.push(pushpin);

           var _options = {
               pushpinOptions: { 
               },
               polylineOptions: {
                   strokeColor: new Microsoft.Maps.Color(100, 0, 255, 0),
                   strokeThickness: 1
               },
               polygonOptions: {
                   fillColor: new Microsoft.Maps.Color(145, 0, 0, 128),
                   strokeColor: new Microsoft.Maps.Color(200, 128, 0, 0),
                   strokeThickness: 1
               }
           };

           var Bridge_String = "POLYGON ((" +
                    "-86.536241 33.078286, " +
                    "-86.531821 33.077028, " +
                    "-86.530222 33.076556, " +
                    "-86.529729 33.077580, " +
                    "-86.531435 33.077275, " +
                    "-86.533345 33.078084, " +
                    "-86.535587 33.078776))";

           var Zone_String = "MULTIPOLYGON (((-86.482209833117281 33.146190241986119, -86.491937420175759 33.146222870289307, -86.501384890000622 33.146287269841707, -86.501346739860139 33.144216579931253, -86.501086719776254 33.143054979603676, -86.500876360255802 33.1421316303705, -86.500766230177362 33.138808110206185, -86.509321149851132 33.138715610437146, -86.509814790420194 33.138984299985509,

    /* Truncated for brevity */

    33.141556059764412, -86.479281959794548 33.143216930417054, -86.480644890449298 33.144285830426782, -86.482023176128621 33.145860519047744, -86.482155079693143 33.146011220241689, -86.482209833117281 33.146190241986119)))";

           var shape = Microsoft.Maps.WellKnownText.read(Zone_String, _options);  // this geometry is not working!
           //var shape = Microsoft.Maps.WellKnownText.read(Bridge_String, _options);   // this geometry works fine though!

           //shape.setOptions({ visible: false });  //this is the line that kills it for the MULTIPOLY

           bingMap.entities.push(shape);

           Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', function () {
               shape.setOptions({ visible: true });  //nor do these work with the MULTIPOLY
           });
           Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', function () {
               shape.setOptions({ visible: false }); //nor do these work with the MULTIPOLY
           });

           alert("done!");
       }

    Is there something I'm missing?

    -Austin

    Thursday, June 22, 2017 10:54 PM

Answers

  • Bing maps does not support multi-shapes natitively, as such the well know text module returns an array of polygons when parsing a multipolygon string. An array doesn't have the setOptions function that a polygon class has. You have to loop through the polygons in the array to access them individually to set their options.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Thursday, June 22, 2017 11:39 PM
    • Unproposed as answer by Austin_KPS Friday, June 23, 2017 5:13 PM
    • Marked as answer by Austin_KPS Wednesday, June 28, 2017 5:05 PM
    Thursday, June 22, 2017 11:39 PM

All replies

  • Bing maps does not support multi-shapes natitively, as such the well know text module returns an array of polygons when parsing a multipolygon string. An array doesn't have the setOptions function that a polygon class has. You have to loop through the polygons in the array to access them individually to set their options.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Thursday, June 22, 2017 11:39 PM
    • Unproposed as answer by Austin_KPS Friday, June 23, 2017 5:13 PM
    • Marked as answer by Austin_KPS Wednesday, June 28, 2017 5:05 PM
    Thursday, June 22, 2017 11:39 PM
  • Except the WKT module is not returning an array. It's returning a single object for the multipolygon.

    I'm looking at the code at ( https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk#wktWriteToWkt+JS ) and it's showing a geometrycollection as its example. I haven't executed it here, but it demonstrates that it does return an array just as you explained, but in my example using a multipolygon it's not returning an array.

    The line: 

    var shape = Microsoft.Maps.WellKnownText.read(Zone_String, _options);

    returns the object shape with the property length of 1.  Now this object does not have the setOptions, so I think we're on the right track here, but if I put in some code like this:

    if (shape.length > 1) {
               for (var x = 0; x < shape.length; x++) {
                   var singleshape = shape[x];

    obviously, with the length being equal to 1, it will never hit it, but, in theory, that should work, correct?


    Friday, June 23, 2017 4:37 PM
  • Ok, so I layed off the crack for a bit and came to terms with this multipolygon not being multi at all and only returning an array element of one, and I've now got this part of our implementation working with the new version!

    As an aside, what is everyone using to check for this possible array?  Array.isArray() is what I went with, but I'm not sure if it's the go-to solution for determining just what the WKT module is returning. I could parse the WKT string beforehand, but that doesn't seem efficient. 

    Wednesday, June 28, 2017 5:05 PM
  • I usually us the instanceof check. For example:

    if(shape instanceof Array){
        //shapes is an array
    }


    [Blog] [twitter] [LinkedIn]

    Wednesday, June 28, 2017 6:29 PM