Hemant Kabra
Hemant Kabra

Reputation: 11

How to plot shapefiles on Bing Map

How can I use shapefile(.shp) with bing maps without using any third party reference? I just want to use bing maps api library to perform this action. So suggest me how can i achieve this?

I have tried something with bing maps which is described below.. Here is my code :

$.ajax({
            type: "POST",
            url: "GISFunctions.asmx/GetShapeFileData",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, textStatus, jqXHR) {
                var response = data.d;
                for (var i = 0; i < response.length; i++) {
                    var polygonGeometry = response[i];
                    var vertices = new Array();
                    var numCoordinates = polygonGeometry.length;
                    for (var j = 0; j < numCoordinates; j++) {
                        var CoOrdinates = polygonGeometry[j];
                        var x = CoOrdinates[1];
                        var y = CoOrdinates[0];
                        vertices[j] = new Microsoft.Maps.Location(x, y);
                    }
                    var polygoncolor = new Microsoft.Maps.Color(100, 100, 0, 100);
                    var polygon = new Microsoft.Maps.Polygon(vertices, { fillColor: polygoncolor, strokeColor: polygoncolor });
                // Add the shape to the map
                    map.entities.push(polygon);
                }
            },
            error: function (xhr, status, error) {
                alert(xhr.responseText);
            }
        });

"GISFunctions.asmx/GetShapeFileData" is my web service method. It fetches data from shapefile. Reads shapefile's records one by one and fetches co-ordinates for each record's polygon. In above Jquery Ajax function, i have differentiated my data and created array which contains vertices for my polygon and then according to below link, i am trying to map these polygons on Bing Map

http://msdn.microsoft.com/en-us/library/gg427604.aspx

When i go through static data then i can easily plot one polygon on Bing Map.. But when i try to create these polygons dynamically then my above code doesn't work. It doesn't plot any polygon on map and also don't give my error..

I am new to GIS functions so kindly suggest me right direction..

Upvotes: 1

Views: 2992

Answers (1)

Related Questions