Are there any examples around showing how to programmatically create a map and set the location info from the back office, I am working on an importer for some information, and have not been able to get this to successfully work.
The other solution would be to change the json yourself that Terratype stores - you can see this json by switching on debug mode when you create yourself a Terratype property type.
OK, I'll have a look at the unit test, I don't mind fiddling with JSON if needed, but would rather go a supported route.
Any chance for a release that would expose the private assessors, even if it were a helper class, I don't really want to mess around with reflection unless I have to.
As an alternative, is there a way to inject a longitude/latitude while rendering? I could keep the address data separate and just merge things while rendering the front end.
Any chance for a release that would expose the private assessors
I know it might sound like an oversight, but I was trying to stop people creating Terratypes configurations themselves and forcing them to only use the property type editor in the developer section.
The setters as are, allows you to create any old configuration including map abominations, 99% of the time would crash Terratype, so what I need to do is add to them is lots of checking code. I'm not against doing this, I just require a free bit of time, I will add this to the roadmap.
is there a way to inject a longitude/latitude while rendering
Yes. Using the Position property of the Option class.
@Html.Terratype(new Options { Position = new Terratype.CoordinateSystems.Wgs84("-51,-1") }, Model.Content.Map)
This is a follow on, of your request via twitter. And my response.
Recap: I have through this thread given you some different options on how to create Terratype properties;
Create a Terratype DataType (Currently can only do via private fields)
Set a Terratype Property Value (Need to set the json value yourself)
Override the values when Rendering (My previous post in this thread)
I feel I should expand on item 2: how to do set a Terratype Property Value in json using code.
Obviously you would have executed some of these steps already, but I will repeat here, to cover everything.
Install Umbraco
Install Terratype with at least one Terratype provider
Create a Terratype Datatype of your choosing in the developer section. Pick the style, icons and default values you require.
Create a doctype in the settings section. For easy of example, The alias of this doctype will be 'mydoctype'
Add the Terratype datatype that we created in step 3, to this doctype. The alias of this property will be 'mymap'. Feel free to add other properties but this example will not discuss them.
.
/// <summary>
/// Create a content node in the root of the content tree
/// </summary>
/// <param name="nodeName">Name of the node</param>
/// <param name="latitude">Latitude of the map marker</param>
/// <param name="longitude">Longitude of the map marker</param>
/// <param name="label">The text to appear if the user clicks the map marker</param>
/// <returns></returns>
public bool CreateMapContent(string nodeName, double latitude, double longitude, string label)
{
var content = Umbraco.Core.ApplicationContext.Current.Services.ContentService.CreateContent(nodeName, -1, "mydoctype", 0);
var json = "{zoom: 5,label: {content: " + label + ",id: \"standard\",enable: true,editPosition: 0," +
"view: \"/App_Plugins/Terratype/views/label.standard.html?cache=1.0.12\",controller: \"terratype.label.standard\"}" +
"position: {id: \"WGS84\",datum: " + latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," +
longitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "}}";
content.SetValue("mymap", json);
return ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(content).Success;
}
So to create content with a Terratype map, you would call CreateMapContent() with the values your desire. For example
CreateMapContent("My node", 50.01, -2.56, "You have pressed the map icon");
Please note that the json will change in the future, but hopefully I will always keep backward compatibility. I do plan to create some helper functions to help with the json creation process, but for now, thats all there is.
Sorry for the json, I'm pleased that you fixed it and got it working.
As for
Is there a way in the JSON to set the text of the address that corresponds to the longitude/latitude?
Not currently, this would need a separate process to carry out the geocoding or reverse geocoding. There are lots of restrictions around this sort of process; Google for example limit it to 2500 requests per day. I do have plans to create a premium package that would download Open Street Map data to allow unlimited usage, but I'm many months away from being able to offer this.
Following up as promised. You can, in face add the location to the json (see below), however the code as Jonathon mentioned does not geocode nor make sure that it is valid.
Programmatically create map - any examples?
Are there any examples around showing how to programmatically create a map and set the location info from the back office, I am working on an importer for some information, and have not been able to get this to successfully work.
Hi John,
Currently your are unable to create Terratype.Models.Model objects from scratch, which is what you would need to create some sort of import feature.
For testing purposes, I do have a Unit Test that creates this class, but it cheats - It override the private accessor to set values.
Unit test that creates Terratype maps
The other solution would be to change the json yourself that Terratype stores - you can see this json by switching on debug mode when you create yourself a Terratype property type.
Cheers
Jonathan
OK, I'll have a look at the unit test, I don't mind fiddling with JSON if needed, but would rather go a supported route.
Any chance for a release that would expose the private assessors, even if it were a helper class, I don't really want to mess around with reflection unless I have to.
As an alternative, is there a way to inject a longitude/latitude while rendering? I could keep the address data separate and just merge things while rendering the front end.
Hi John,
I know it might sound like an oversight, but I was trying to stop people creating Terratypes configurations themselves and forcing them to only use the property type editor in the developer section. The setters as are, allows you to create any old configuration including map abominations, 99% of the time would crash Terratype, so what I need to do is add to them is lots of checking code. I'm not against doing this, I just require a free bit of time, I will add this to the roadmap.
Yes. Using the Position property of the Option class.
(Options, as well as what is a Wgs84, is fully documented here)
Cheers
Jonathan
Hi John,
This is a follow on, of your request via twitter. And my response.
Recap: I have through this thread given you some different options on how to create Terratype properties;
I feel I should expand on item 2: how to do set a Terratype Property Value in json using code.
Obviously you would have executed some of these steps already, but I will repeat here, to cover everything.
.
So to create content with a Terratype map, you would call CreateMapContent() with the values your desire. For example
Please note that the json will change in the future, but hopefully I will always keep backward compatibility. I do plan to create some helper functions to help with the json creation process, but for now, thats all there is.
Hopefully this helps a little more
Cheers
Jonathan
Is there a way in the JSON to set the text of the address that corresponds to the longitude/latitude?
For other's benefit, the snippet that generates the JSON above doesn't quite work, here is an updated one:
Most of the issues was related to quoting the values correctly. (Thanks Jonathon for pointing me at least in the right direction :-)
Hi John,
Sorry for the json, I'm pleased that you fixed it and got it working.
As for
Not currently, this would need a separate process to carry out the geocoding or reverse geocoding. There are lots of restrictions around this sort of process; Google for example limit it to 2500 requests per day. I do have plans to create a premium package that would download Open Street Map data to allow unlimited usage, but I'm many months away from being able to offer this.
Cheers
Jonathan
Following up as promised. You can, in face add the location to the json (see below), however the code as Jonathon mentioned does not geocode nor make sure that it is valid.
Here is a sample json with the address
We are using this here to import data, and have not encountered any issues with our first block of around 500 records.
is working on a reply...