Trying to introduce html query string handling with our map. We are wanting to give out url addresses for users to link to our site and have our app automatically zoom to a specified area on the map.
example: URL.com?KEY=VALUE&KEY2=VALUE2
We want to give out that url and have our map zoom into and highlight the feature of VALUE. So if we have a subdivision with the id of 1234, we would like to give out the url URL.com?SUBDIVISION=1234. When the user clicks on the link they will be directed to that subdivision on the map.
Using window.location.search.substring(1) and some replace calls I can get the exact value I want (“1234”), but I’m having trouble getting the app to search for the subdivision in our db, return the location, and zoom into that location.
Any help would be much appreciated.
Using Query String Parameters
Hi Chad,
Do you mean that you want to find the feature and zoom into it? If so, please see the sample at samples.thinkgeo.com/MvcEdition/HowDoISamples/SpatialFunctions/ZoomInToAFeatureClicked/1,SpatialFunctions
Please let me know if I misunderstand something here.
Thanks,
Peter
Peter,
No. Not when the user clicks a feature. I mean I want the app to read an HTML URL address from the address bar in the browser. Then, if the query string parameters match a feature in our map, the app should zoom into that feature. I really don’t know how else to explain it.
User types URL.com?KEY=VALUE into their address bar in the browser. User gets directed to our website/map. Our application reads the URL address and recognizes the query string “KEY=VALUE”. The application will search for the feature named “KEY” with the id “VALUE”. The application then automatically zooms into that feature.
Hi Chad,
I think following statements is prefer to your scenario:
public ActionResult DisplayASimpleMap()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Map map = new Map("Map1",
new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage),
new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage));
… … …
string x = Request.QueryString["x"];
string y = Request.QueryString["y"];
if (!String.IsNullOrEmpty(x) && !String.IsNullOrEmpty(y))
{
PointShape point = new PointShape(double.Parse(x), double.Parse(y));
RectangleShape rect = point.Buffer(50, GeographyUnit.Meter, DistanceUnit.Meter).GetBoundingBox();
double scale = ExtentHelper.GetScale(rect, (float)map.Width.Value, GeographyUnit.Meter);
map.ZoomTo(new PointShape(double.Parse(x), double.Parse(y)), scale);
}
… … …
return View(map);
}
I see what you are trying to do here. I created a work around in JavaScript which seems to be working great so far. Thank you.
Hi Chad,
I’m glad to hear that, you are welcome, if you have any questions, please let me know.
Thanks,