Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 36
Registered: ‎11-11-2015
Accepted Solution

Create a Feature Class with Style and add it to PSS

Please share the code snippet to create a Feature Class with Style and add it to PSS data source.

Highlighted
Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Create a Feature Class with Style and add it to PSS

Hi.

 

The example below creates 4 FC - Text, Point, Line and Area - and adds them to a new category in legend.

This has inline styles but it can be put in another object and reuse it anytime you need.

Hope it helps.

 

createFeatures: function (ms) {
        $GP.edit.PSS.addFeatureClasses({
            mapServiceId: ms.get_id(),
            featureClassDefinitions: [{
                featureClassName: "Text",
                featureClassId: "IPT_PSS_LAYER_TEXT",
                fields: [],
                geometryType: Intergraph.WebSolutions.Core.WebClient.Platform.Common.GeometryType.GraphicsText,
                style: {
                    bold: true,
                    color: "#FF0000",
                    horizontalAlignment: 0,
                    imageHeight: 0,
                    imageUrl: null,
                    imageWidth: 0,
                    italic: false,
                    name: "Text Style",
                    rotation: 0,
                    rule: null,
                    size: 16,
                    styleCollectionType: 0,
                    styles: [],
                    subtype: 0,
                    translucency: 0,
                    type: 6,
                    underline: false,
                    verticalAlignment: 0,
                    visible: true,
                    width: 0
                }
            }, {
                featureClassName: "Points",
                featureClassId: "IPT_PSS_LAYER_POINTS",
                fields: [],
                geometryType: Intergraph.WebSolutions.Core.WebClient.Platform.Common.GeometryType.Point,
                style: {
                    bold: false,
                    color: "#B32400",
                    horizontalAlignment: 0,
                    imageHeight: 1,
                    imageUrl: null,
                    imageWidth: 1,
                    italic: false,
                    name: "Simple Point Style",
                    rotation: 0,
                    rule: null,
                    size: 3,
                    styleCollectionType: 0,
                    styles: [],
                    subtype: 0,
                    translucency: 0,
                    type: 1,
                    underline: false,
                    verticalAlignment: 0,
                    visible: true,
                    width: 0
                }
            }, {
                featureClassName: "Lines",
                featureClassId: "IPT_PSS_LAYER_LINES",
                fields: [],
                geometryType: Intergraph.WebSolutions.Core.WebClient.Platform.Common.GeometryType.Linear,
                style: {
                    bold: false,
                    color: "#B32400",
                    horizontalAlignment: 0,
                    imageHeight: 0,
                    imageUrl: null,
                    imageWidth: 0,
                    italic: false,
                    name: "Simple Line Style",
                    rotation: 0,
                    rule: null,
                    size: 0,
                    styleCollectionType: 0,
                    styles: [],
                    subtype: 0,
                    translucency: 0,
                    type: 2,
                    underline: false,
                    verticalAlignment: 0,
                    visible: true,
                    width: 1
                }
            }, {
                featureClassName: "Areas",
                featureClassId: "IPT_PSS_LAYER_AREAS",
                fields: [],
                geometryType: Intergraph.WebSolutions.Core.WebClient.Platform.Common.GeometryType.Areal,
                style: {
                    bold: false,
                    color: null,
                    horizontalAlignment: 0,
                    imageHeight: 0,
                    imageUrl: null,
                    imageWidth: 0,
                    italic: false,
                    name: "Area Style",
                    rotation: 0,
                    rule: null,
                    size: 0,
                    styleCollectionType: 0,
                    styles: [{
                        bold: false,
                        color: null,
                        horizontalAlignment: 0,
                        imageHeight: 0,
                        imageUrl: null,
                        imageWidth: 0,
                        italic: false,
                        name: "Boundaries",
                        rotation: 0,
                        rule: null,
                        size: 0,
                        styleCollectionType: 2,
                        styles: [{
                            bold: false,
                            color: "#B32400",
                            horizontalAlignment: 0,
                            imageHeight: 0,
                            imageUrl: null,
                            imageWidth: 0,
                            italic: false,
                            name: "Simple Line Style",
                            rotation: 0,
                            rule: null,
                            size: 0,
                            styleCollectionType: 0,
                            styles: [],
                            subtype: 0,
                            translucency: 0,
                            type: 2,
                            underline: false,
                            verticalAlignment: 0,
                            visible: true,
                            width: 1
                        }
                        ],
                        subtype: 0,
                        translucency: 0,
                        type: 0,
                        underline: false,
                        verticalAlignment: 0,
                        visible: false,
                        width: 0
                    }, {
                        bold: false,
                        color: null,
                        horizontalAlignment: 0,
                        imageHeight: 0,
                        imageUrl: null,
                        imageWidth: 0,
                        italic: false,
                        name: "Fill",
                        rotation: 0,
                        rule: null,
                        size: 0,
                        styleCollectionType: 3,
                        styles: [{
                            bold: false,
                            color: "#FF3300",
                            horizontalAlignment: 0,
                            imageHeight: 1,
                            imageUrl: null,
                            imageWidth: 1,
                            italic: false,
                            name: "Simple Fill Style",
                            rotation: 0,
                            rule: null,
                            size: 0,
                            styleCollectionType: 0,
                            styles: [],
                            subtype: 0,
                            translucency: 0.6,
                            type: 3,
                            underline: false,
                            verticalAlignment: 0,
                            visible: true,
                            width: 0
                        }
                        ],
                        subtype: 0,
                        translucency: 0,
                        type: 0,
                        underline: false,
                        verticalAlignment: 0,
                        visible: false,
                        width: 0
                    }
                    ],
                    subtype: 0,
                    translucency: 0,
                    type: 4,
                    underline: false,
                    verticalAlignment: 0,
                    visible: false,
                    width: 0
                }
            }]
        }, this.callbakPssAddLegendItems);
    },
    callbakPssAddLegendItems: function (ret2) {
        $GP.legend.add({
            mapServiceId: $userManager.getPssId(),
            names: ["Areas", "Lines", "Points", "Text"],
            name: "Personal Notes"
        }, function (result) {
            var currLegendItems = [],
                currLiName,
                dstLegendItems,
                i = 0,
                legend,
                li,
                mapState,
                newLegendItem,
                newLiName,
                oldParentItems,
                stub;

            mapState = $mapStateManager.findMapState("map");
            legend = mapState.get_legend();

            stub = {
                mapServiceId: $userManager.getPssId(),
                legendItemDefinitionId: Intergraph.WebSolutions.Core.WebClient.Platform.MapServices.MapService.dummyFolderId,
                name: "Personal Notes",
                isLocatable: true,
                isVisible: true
            };
            newLegendItem = new Intergraph.WebSolutions.Core.WebClient.Platform.MapContent.LegendItem(stub, legend);
            newLegendItem.set_priority(legend.get_flatLegend().length - result.ids.length);
            dstLegendItems = legend.get_legendItems();
            currLegendItems = dstLegendItems.splice(0 - result.ids.length);
            for (i = 0; i < currLegendItems.length; i++) {
                currLegendItems[i]._parent = newLegendItem;
                newLegendItem.get_legendItems().push(currLegendItems[i]);
            }
            dstLegendItems.push(newLegendItem);

            $event.notify("refreshMapLegendControl", {
                mapStateId: "map"
            }, this);
        });
    }

 

Best regards.

 

Contributor
Posts: 36
Registered: ‎11-11-2015

Re: Create a Feature Class with Style and add it to PSS

Thanks. Can we set the styles in feature level. We have Dynamci Styles concept to define styling for individual features in the feature class. Do we any any mechanism otherthan this. Also can we update the "Font Family" value?

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Create a Feature Class with Style and add it to PSS

You can change the Font Family value. Regarding styles in feature level I haven't done any implementation or tests so I cannot help on that subject.

Best regards

Contributor
Posts: 36
Registered: ‎11-11-2015

Re: Create a Feature Class with Style and add it to PSS

Can you share sample code snippet to updat the FontFamily value. Thanks for sharing the information.

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Create a Feature Class with Style and add it to PSS

[ Edited ]

Sorry but I don't have any.

 

But you might look at the _displayStyle property of an LegendItem and see the properties that the element have.

Try to include in the previous code to see if it works.

 

 legendItemStyle.png

Contributor
Posts: 36
Registered: ‎11-11-2015

Re: Create a Feature Class with Style and add it to PSS

Thanks. I will check this. One clarification - When should we use below methods. Do we have any difference between these two. Can we set geometry type and style if we use $GP.edit.PSS.createFromFeatureCollections.

 

 

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Create a Feature Class with Style and add it to PSS

[ Edited ]

You can check the difference between the 2 methods in: http://demo.hexagongeospatial.com/communityportal/docs/index.html#!/api/$GP.edit.PSS

 

Basically the first one lets you add FC to an existing PSS and the second one creates a PSS from a FecatureCollection.

 

I've used that method this way:

 

jsonPolygon.featureCollectionsData[0].featureClassId = "Polygons";
jsonPolygon.featureCollectionsData[0].featureClassName = "Polygons";
$GP.edit.PSS.createFromFeatureCollections(jsonPolygon, function (res) {
	var j;

	if (res.success) {
		for (j = 0; j < res.ids.length; j++) {
			$GP.legend.find({
				name : res.ids[j]
			}, function (res1) {
				var currLi;
				var i;

				if (res1.success) {
					for (i = 0; i < res1.legendItems.length; i++) {
						currLi = res1.legendItems[i];
						currLi._.li.set_displayStyle(getProperStyle('polygonStyle'));

						$event.register('featureDatasetRefreshed', featureDatasetRefreshed, this);
					}
				}
			}, function (res2) {
				alert(Ext.encode(res2));
			});
		}
	}
}, function () {
	Ext.Msg.alert("Error", "ErrorOccured");
});

 

HTH

Contributor
Posts: 36
Registered: ‎11-11-2015

Re: Create a Feature Class with Style and add it to PSS

Can we set geometry type and Style information for Feature class while using createFromFeatureCollections?

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Create a Feature Class with Style and add it to PSS

[ Edited ]

Regarding Style, you can see in my previous post that it has an instruction to do it:

currLi._.li.set_displayStyle(getProperStyle('polygonStyle'));

 

Regarding Geometry Type you can set it.

In the script that I posted the object jsonPolygon has that information in it.

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.