question

Alyson P avatar image
4 Likes"
Alyson P asked Michal Klodawski commented

Is it possible to add a point in map through FlexScript?

Hello, guys.

I need to add several points to a map and do it manually would take a long time. Is it possible to create some points through FlexScript, set their coordinates and add them to the map? I also need to make connections among these created points through FlexScript and further I will try to read an Excel sheet with the city names and their geographical coordinates in order to add all cities "automatically".

Thanks for your attention.

FlexSim 21.2.0
flexscriptgiscoordinatesmappoint
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
6 Likes"
Phil BoBo answered Michal Klodawski commented

Below is a script that programmatically creates various GIS objects and sets their properties.

  1. // Create a map object if one does not exist
  2. Object map = model().find("UtahMap");
  3. if (!map) {
  4.     map = createinstance(library().find("/GIS/Map"), model());
  5.     map.name = "UtahMap";
  6.     map.setSize(30, 20, 2);
  7.     map.setLocation(10, 0, 0);
  8.     
  9.     map.setProperty("Latitude", 40.54);
  10.     map.setProperty("Longitude", -111.76);
  11.     map.setProperty("Zoom", 11.87);
  12. }
  13.  
  14. // The map should have asserted a GISNavigator when it was created
  15. Object navigator = model().find("GISNavigator");
  16. if (!navigator)
  17.     return 0;
  18.  
  19. // Delete any existing points
  20. navigator.subnodes.clear();
  21.  
  22. // Create a point
  23. Object point1 = createinstance(library().find("/GIS/Point"), navigator);
  24. point1.name = "FlexSim HQ";
  25. point1.setProperty("Latitude", 40.325546989330164);
  26. point1.setProperty("Longitude", -111.67937559702706);
  27.  
  28. point1.setSize(4, 3, 2);
  29. point1.color = Color.green;
  30. point1.setProperty("DrawPoint", 0);
  31.  
  32. // For point1, use a Processor shape
  33. string shapename = "fs3d\\Processor\\Processor.3ds";
  34. sets(shape(point1), shapename);
  35. double theindex = getshapeindex(shapename);
  36. setobjectshapeindex(point1, theindex);
  37. applyshapefactors(point1);
  38.  
  39. // Create another point
  40. Object point2 = createinstance(library().find("/GIS/Point"), navigator);
  41. point2.name = "SLC Airport";
  42. point2.setProperty("Latitude", 40.777322465390746);
  43. point2.setProperty("Longitude", -111.98225326723002);
  44. point2.color = Color.red;
  45.  
  46. // Connect the points to create a route
  47. contextdragconnection(point1, point2, "A");
  48.  
  49. // Get a reference to the newly created route
  50. treenode routeNode = getvarnode(point1, "routes").last;
  51.  
  52. // Set its Update Type to Driving Roads and Update it
  53. routeNode.subnodes["updateType"].value = GIS_UPDATE_TYPE_DRIVING_ROADS;
  54. function_s(navigator, "updateRoute", routeNode);
  55.  
  56. // The route's color is stored on a subnode called colorNode. It will be black if that node has no subnodes.
  57. treenode colorNode = routeNode.subnodes["colorNode"];
  58. while (colorNode.subnodes.length < 3)
  59.     colorNode.subnodes.add().value = 0;
  60. colorNode.subnodes[3].value = 0.7; // blue
  61.  
  62. // Create a Truck
  63. Object truck = model().find("Truck1");
  64. if (!truck) {
  65.     truck = createinstance(library().find("?TaskExecuter"), model());
  66.     truck.name = "Truck1";
  67.     string shapename = "fs3d\\FlowItem\\SemiTruck\\Truck.ac";
  68.     sets(shape(truck), shapename);
  69.     double theindex = getshapeindex(shapename);
  70.     setobjectshapeindex(truck, theindex);
  71.     applyshapefactors(truck);
  72.     truck.setLocation(10, 10, 0);
  73.     truck.setSize(13.57 * 0.5, 1.88 * 0.5, 2.85 * 0.5);
  74.  
  75.     // Connecting a TE to a point will connect that TE to the GIS Navigator with that point as its reset point.
  76.     contextdragconnection(truck, point1, "A");
  77. }
  78.  
  79. repaintall();
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.