Like others here, I to have found myself upgrading an existing project from your previous AngularMaps to the new Terratype maps.
The issue I have is that the previous coders have a bunch of code in the App_code folder that creates a large JSON file containing lots of coordinates based upon (previously) Angular Maps locations.
The existing code simply used "GetPropertyValue" to retun the laat and lng in the string format "xxxxxx,yyyyyyy".
Terratype, however doesn't support this return and I can see in a Visual Studio watch that it is returning a type of "Terratype.Models.Model".
The trouble is, I cannot seem to work out what code I need in place to be able to get at all of the enhanced properties inside this from the "App_Code" folder.
This is my really hacky temporary fix until I get some help from someone who knows how to do this the correct way.
I think that I need to import/use something or perhaps describe the TerraType model in some way, but when I use the model from the excellent documentation, I have lots of errors. I'm sure that this is because my code is in the App_Code folder and not within a view.
Please help! :)
Cheers,
Splinx
private string GetCoordinates(object terraTypeMap)
{
Type t = terraTypeMap.GetType();
PropertyInfo[] pia = t.GetProperties();
//string message = "";
foreach (PropertyInfo b in pia)
{
if (b.Name == "Position")
{
return b.GetValue(terraTypeMap).ToString();
}
//message += String.Format("Name : {0}, Value : {1}\r\n", b.Name, b.GetValue(coords, null));
}
return null;
}
So, you see, this code would have pulled back the simple coordinates previously from the Google Angular Maps.
With the new TerraType map object, these values (amongst many other useful pieces of data) are all hidden within properties of the object.
The trouble is, I do not understand how to get at them because my code simply doesn't understand what the TerraType object is :(
I have tried using syntax from the documentation and other coders posts but everything I try fails simple because I don't have access to content.Model and the Terratype object.
I basically want to know what the syntax is (and any using statements) required to get at the properties here:
Please accept my apologies in advance if I'm just being an idiot ;)
I've tried to include the Terratype.Models.Model within my custom class (which resides in the App_Code folder) but I fear that I'm heading in the wrong direction here as I just get more type unknown errors from the Terratype model itself.
I'm certain that this is more of a .Net C# experience thing than any issue with the excellent plugin - I just can't figure this one out!
Using Descendants is an expensive call on as it loads the whole site into memory whereas the above uses XPath and only loads the resulting OfficeDocType
Thanks for coming back to me Matt, I reallyappreciate it.
I'm certain that your code is right as it matches to many examples in the Umbraco documentation and forum posts... the issue is that I cannot seem to use this format in the app_Code folder in the classes set up by the previous developers.
I have previously attempted to get the Terratype object as you have given in your example but "Terratype" is highlighted by intellisense with the error: The type of namespace "Terratype" could not be found....
Am I missing something really basic here?
Thanks for the tip on the TypedContentAtXPath. I thought that I could not get this working at first (since there was a typo in your example (lowercase "p" in TypedContentAtXpath). I edited my initial reply accordingly.
Some further insight that may help reveal my mistake...
I tried to see if I could describe the Terratype model manually by creating models for it based on the source code.
This had the effect of allowing me to use the statement you provided of
var terraTypeCoords2 = myOffice.GetPropertyValue<Terratype.Models.Model>("officeLocation");
BUT...
then resulted in the compiler error below:
Compiler Error Message: CS0433: The type 'Terratype.Models.Model' exists in both '...\AppData\Local\Temp\Temporary ASP.NET Files\vs\a63db768\d29af7a0\assembly\dl3\e9aebd0f\6ff579f2_63b4d301\UmbracoCMS.DLL' and '...\AppData\Local\Temp\Temporary ASP.NET Files\vs\a63db768\d29af7a0\assembly\dl3\e8173b13\007242ec_6d94d301\Terratype.DLL'
I'm thinking that I need to reference the Terratype DLL somehow, right?
It's in the project (imported using nuget):
...but, I cannot get a using statement to this at the top of my class :(
This must be something I have (or perhaps haven't done) or a complete misunderstanding of .Net.
Accessing Terratype.Models from App_Code folder
Firstly, thank you for an amazing plugin.
Like others here, I to have found myself upgrading an existing project from your previous AngularMaps to the new Terratype maps.
The issue I have is that the previous coders have a bunch of code in the App_code folder that creates a large JSON file containing lots of coordinates based upon (previously) Angular Maps locations.
The existing code simply used "GetPropertyValue" to retun the laat and lng in the string format "xxxxxx,yyyyyyy".
Terratype, however doesn't support this return and I can see in a Visual Studio watch that it is returning a type of "Terratype.Models.Model".
The trouble is, I cannot seem to work out what code I need in place to be able to get at all of the enhanced properties inside this from the "App_Code" folder.
Could a kindly soul please help me out here.
Thanks in advance, Splinx
Hi Guys,
This is my really hacky temporary fix until I get some help from someone who knows how to do this the correct way.
I think that I need to import/use something or perhaps describe the TerraType model in some way, but when I use the model from the excellent documentation, I have lots of errors. I'm sure that this is because my code is in the App_Code folder and not within a view.
Please help! :)
Cheers, Splinx
Hey,
What errors are you getting?
Matt
Hey Matt,
The code I am upgrading previoulsy had a line like this:
Where o is an item from:
So, you see, this code would have pulled back the simple coordinates previously from the Google Angular Maps.
With the new TerraType map object, these values (amongst many other useful pieces of data) are all hidden within properties of the object.
The trouble is, I do not understand how to get at them because my code simply doesn't understand what the TerraType object is :(
I have tried using syntax from the documentation and other coders posts but everything I try fails simple because I don't have access to content.Model and the Terratype object.
I basically want to know what the syntax is (and any using statements) required to get at the properties here:
Please accept my apologies in advance if I'm just being an idiot ;)
Cheers, Splinx
To clarify...
I've gone through the documentation here: https://github.com/Joniff/Terratype/blob/master/docs/manual.pdf
I've tried to include the Terratype.Models.Model within my custom class (which resides in the App_Code folder) but I fear that I'm heading in the wrong direction here as I just get more type unknown errors from the Terratype model itself.
I'm certain that this is more of a .Net C# experience thing than any issue with the excellent plugin - I just can't figure this one out!
Cheers, Splinx
This should return the correct model.
Also one side note is
could be faster using
Using Descendants is an expensive call on as it loads the whole site into memory whereas the above uses XPath and only loads the resulting OfficeDocType
Hope this helps
Matt
Thanks for coming back to me Matt, I reallyappreciate it.
I'm certain that your code is right as it matches to many examples in the Umbraco documentation and forum posts... the issue is that I cannot seem to use this format in the app_Code folder in the classes set up by the previous developers.
I have previously attempted to get the Terratype object as you have given in your example but "Terratype" is highlighted by intellisense with the error: The type of namespace "Terratype" could not be found....
Am I missing something really basic here?
Thanks for the tip on the TypedContentAtXPath. I thought that I could not get this working at first (since there was a typo in your example (lowercase "p" in TypedContentAtXpath). I edited my initial reply accordingly.
Thanks again buddy, Splinx
Some further insight that may help reveal my mistake...
I tried to see if I could describe the Terratype model manually by creating models for it based on the source code.
This had the effect of allowing me to use the statement you provided of
BUT...
then resulted in the compiler error below:
I'm thinking that I need to reference the Terratype DLL somehow, right?
It's in the project (imported using nuget):
...but, I cannot get a using statement to this at the top of my class :(
This must be something I have (or perhaps haven't done) or a complete misunderstanding of .Net.
Cheers,
Splinx
Okay.... I think I have a solution but I'm not sure that I am knowledgeable enough to understand how....
My fix was to...
Everything now works and now this is easy to get working from here!
:-)
Is it possible that there's something wrong with 1.0.16 or is this just something screwy with my local environment or install process?
Cheers,
Splinx
is working on a reply...