I have been working on this for a couple days now and have made very little progress so I thought I would see if I can get some help here.
Currently Bing Maps is sowing me zoomed all the way in the ocean off the left side of Africa(I believe this means I’m not doing something right)
This is the code behind getting the extent I want to show(the commented out code is what I used with Google maps and it worked fine)
**********************************************************************
*************** CODE BEHIND *****************************************
**********************************************************************
Dictionary<string, double> LastExtent = MappingServices.Jobs.MapDeliveryJobs.GetLastExtent(GrowerID, CropYear, User);
double inLeft = 0.0;
double inBottom = 0.0;
double inRight = 0.0;
double inTop = 0.0;
foreach (var Extent in LastExtent)
{
switch (Extent.Key)
{
case “Left”:
inLeft = Extent.Value;
break;
case “Bottom”:
inBottom = Extent.Value;
break;
case “Right”:
inRight = Extent.Value;
break;
case “Top”:
inTop = Extent.Value;
break;
}
}
double inCentralMeridian = (inLeft + inRight) / 2;
Proj4Projection tempProjection = new Proj4Projection(RCIS.Mapping.SharedLibrary.Common.CommonMethods.GetLatLonProjectionString, RCIS.Mapping.SharedLibrary.Common.CommonMethods.GetCCProjectionString(inCentralMeridian));
tempProjection.Open();
Vertex minVertex = tempProjection.ConvertToInternalProjection(inLeft, inBottom);
Vertex maxVertex = tempProjection.ConvertToInternalProjection(inRight, inTop);
tempProjection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
tempProjection.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
//RectangleShape bbox = new RectangleShape(minVertex.X,maxVertex.Y,maxVertex.X,minVertex.Y);
Vertex minFinalBox = tempProjection.ConvertToExternalProjection(inLeft, inBottom);
Vertex maxFinalBox = tempProjection.ConvertToExternalProjection(inRight, inTop);
tempProjection.Close();
double Latitude = inCentralMeridian;
double Longitude = (inTop + inBottom) / 2 ;
dynamic vl = new VertexList();
//vl.Left = minVertex.X.ToString();
//vl.Bottom = minVertex.Y.ToString();
//vl.Right = maxVertex.X.ToString();
//vl.Top = maxVertex.Y.ToString();
vl.Left = minFinalBox.X.ToString();
vl.Bottom = minFinalBox.Y.ToString();
vl.Right = maxFinalBox.X.ToString();
vl.Top = maxFinalBox.Y.ToString();
vl.Lat = Latitude.ToString();
vl.Lon = Longitude.ToString();
//JavaScriptSerializer s = new JavaScriptSerializer();
return Json(vl, JsonRequestBehavior.AllowGet);
**********************************************************************
*************** JAVASCRIPT *******************************************
**********************************************************************
var Top = msg.Top;
var Bottom = msg.Bottom;
var Right = msg.Right;
var Left = msg.Left;
extent = new OpenLayers.Bounds(Left, Bottom, Right, Top);
var options = {
projection: “EPSG:4326”,
minResolution: “auto”,
maxResolution: “auto”,
maxExtent: new OpenLayers.Bounds(Left, Bottom, Right, Top),
restrictedExtent: new OpenLayers.Bounds(Left, Bottom, Right, Top),//.transform(new OpenLayers.Projection(“EPSG:4326”), new OpenLayers.Projection(“EPSG:900913”)),
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher()
]
};
map = new OpenLayers.Map(‘divMap’,options);//, options
map.addControl(new OpenLayers.Control.LayerSwitcher());
var apiKey = “ApH0iiSTo5x4noXsrRzSAuwUsj5cqcvx_pquBecrT3htmE7pJ7kMTs4mOWGwlVkI”;
var road = new OpenLayers.Layer.Bing({
name: “Road”,
key: apiKey,
type: “Road”
});
var hybrid = new OpenLayers.Layer.Bing({
name: “Hybrid”,
key: apiKey,
type: “AerialWithLabels”
});
var aerial = new OpenLayers.Layer.Bing({
name: “Aerial”,
key: apiKey,
type: “Aerial”
});
layer = new OpenLayers.Layer.GML(“GeoJSON”, “geo.json”, {
projection: new OpenLayers.Projection(“EPSG:4326”),
format: OpenLayers.Format.GeoJSON
});
Polygon(function () {
var ZoomExtent = layer.getDataExtent();
map.addLayers([aerial, road, hybrid,layer]); //,layer
//map.setCenter(new OpenLayers.LonLat(msg.Lat, msg.Lon).transform(new OpenLayers.Projection(“EPSG:4326”)), 5);
map.zoomToExtent(ZoomExtent, true);
//var lat = (Number(Bottom) + Number(Left)) / 2;
//var lon = (Number(Right) + Number(Top)) / 2;
//map.setCenter(new OpenLayers.LonLat(msg.Lon, msg.Lat).transform(new OpenLayers.Projection(“EPSG:900913”),
//map.getProjectionObject()
// ), 5);
});
***********************************************************************************
************* JAVASCRIPT FUNCTION THAT GETS COLLECTION OF POLYGONS ***************
***********************************************************************************
function Polygon(OnSuccess) {
var GetJsonURL = GetGeoJsonFields;
var Grower = $("#Growers").val();
var CropYear = $("#CropYear").val();
$.ajax({
url: GetJsonURL,
data: { ‘GrowerID’: Grower, ‘CropYear’: CropYear },
success: function (msg) {
for (i = 0; i < msg.length; i++) {
if (msg[0] != “”) {
//alert(msg.FieldID);
//alert(msg.OuterRing);
var geojson_format = new OpenLayers.Format.GeoJSON();
layer.addFeatures(geojson_format.read(msg.OuterRing));
}
}
OnSuccess();
},
error: function (req, status, error) {
alert("Req: " + req);
alert("Status: " + status);
alert("Error: " + error);
}
});
};
Any help is greatly appreciated…THANKS!!!
Help with BING maps
Hi Robert,
Thanks for your post, but I am sorry to say that I am a little confused, the BingMapsLayer is not showing in the code, so, the setting on BingMapsLayer is unknown for a further debug, would you please tell us your senario, or the setting of the BingMapsLayer when the bug happens, or, if possible, a small self contained sample will be greatly appreciated.
Waiting for your further information
Summer
Sorry, I realized last night that my post wasn’t 100% ThinkGeo related…
I am trying to use ThinkGeo services with OpenLayers to display bing maps.
Does that make the code I posted clearer? I think there might be a projection problem but I’m not sure.
Hi Robert,
Thanks for your further information,I think you are right, it should be projection problem, if the bing map is going to be as baselayer then, the map projection should be 900913 rahter 4326.attahed should be helpful to narrowdown the bug location.
Hope it helps
Summer
Post11395.txt (2 KB)