{"id":6056,"date":"2022-12-31T10:40:04","date_gmt":"2022-12-31T07:10:04","guid":{"rendered":"https:\/\/en.geobox.ir\/developers\/?post_type=docs&#038;p=6056"},"modified":"2023-01-21T09:26:34","modified_gmt":"2023-01-21T05:56:34","slug":"create-feature-layer-and-add-to-map","status":"publish","type":"docs","link":"https:\/\/en.geobox.ir\/developers\/docs\/features\/create-feature-layer-and-add-to-map\/","title":{"rendered":"Create feature layer"},"content":{"rendered":"<h3>newFeatureLayer(options)<\/h3>\n<p>In order to display vector layer in the leaflet, the style and source settings must be made. For this, we create a new object of the newFeatureLayer class.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<p>options (Object)<\/p>\n<table class=\"table table--fixed table--compact\" style=\"width: 82.5238%; height: 359px;\">\n<thead>\n<tr class=\"bg-gray-faint\" style=\"height: 26px;\">\n<th style=\"text-align: left; height: 26px; width: 22.8381%;\">Name<\/th>\n<th style=\"text-align: left; height: 26px; width: 103.215%;\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.source<\/div>\n<div><a href=\"https:\/\/www.geobox.ir\">Vector layer<\/a><\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">vector layer that has been got \u00a0from the server.<\/td>\n<\/tr>\n<tr style=\"height: 53px;\">\n<td style=\"height: 47px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.style<\/div>\n<div>Object?<\/div>\n<\/td>\n<td style=\"height: 47px; width: 103.215%; text-align: left;\">\n<div>\n<div>An object contains style information. e.g.{ color: &#8216;blue&#8217;, selectionColor: &#8216;#f5b759&#8217; }<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.editable<\/div>\n<div>Boolean<\/div>\n<div>Default: true<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">If true, the feature layer will be editable.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.geometryEditable<\/div>\n<div>\n<div>Boolean<\/div>\n<div>Default: true<\/div>\n<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">If true, geometry of features will be editable.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.selectable<\/div>\n<div>\n<div>Boolean<\/div>\n<div>Default: true<\/div>\n<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">If true, features will be selectable.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.showPopup<\/div>\n<div>\n<div>Boolean<\/div>\n<div>Default: true<\/div>\n<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">If true, a popup will be open when a feature is clicked.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.titleField<\/div>\n<div>String<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Name of the field that it&#8217;s value will be shown in popup.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.selectionChanged<\/div>\n<div>Function?<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Function will be triggered when a feature is selected. This function has no argument.<\/p>\n<p>e.g.: <span style=\"font-family: inherit; font-size: inherit;\">function() { <\/span>console.log(fLayer.selectionSet) <span style=\"font-family: inherit; font-size: inherit;\">}<\/span><\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.featurePopupContent<\/div>\n<div>Function?<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Function will be triggered when the popup is opened. This function changes popup content.<\/p>\n<p>e.g.: <span style=\"font-family: inherit; font-size: inherit;\">function(feature) { <\/span>return <span style=\"font-family: inherit; font-size: inherit;\">`&lt;div&gt;&lt;p&gt;feature id is ${feature.id}&lt;\/p&gt;&lt;\/div&gt;` <\/span><span style=\"font-family: inherit; font-size: inherit;\">}<\/span><\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.popupOpened<\/div>\n<div>Function?<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Function will be triggered when the popup is opened. This function has no argument.e.g.: <span style=\"font-family: inherit; font-size: inherit;\">function() { <\/span>console.log(fLayer.selectionSet) <span style=\"font-family: inherit; font-size: inherit;\">}<\/span><\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.featureDeleted<\/div>\n<div>Function?<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Function will be triggered when a feature is deleted. This function returns deleted feature id.<\/p>\n<p>e.g.: <span style=\"font-family: inherit; font-size: inherit;\">function(id) { <\/span>console.log(id) <span style=\"font-family: inherit; font-size: inherit;\">}<\/span><\/td>\n<\/tr>\n<tr style=\"height: 28px;\">\n<td style=\"height: 26px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.editStatusChanged<\/div>\n<div>Function?<\/div>\n<\/td>\n<td style=\"height: 26px; width: 103.215%; text-align: left;\">Function will be triggered when edit status changed. This function has 2 arguments, status and feature. Status is one of the started, canceled, inserted and updated. Feature returns inserted or updated feature, otherwise it is null.<\/p>\n<p>e.g.: <span style=\"font-family: inherit; font-size: inherit;\">function(status, feature) { if (status === &#8216;inserted &#8216;) {console.log(feature)}<\/span><span style=\"font-family: inherit; font-size: inherit;\">}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p id=\"zoomin-returns\" class=\"unprose txt-m mb3 anchor mt12\"><strong>Returns:<\/strong><\/p>\n<p>Feature layer: Returns feature layer object to allow for method chaining.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const vectorLayer = await server.getVectorLayer('4f9f3e4b-4dc1-469b-83ab-00ae00f02581');\r\nconst fLayer = map.newFeatureLayer({\r\n   source: vectorLayer,\r\n   style: { color: 'blue', selectionColor: '#f5b759' },\r\n   editable: true,\r\n   geometryEditable: true,\r\n   selectable: true,\r\n   showPopup: true,\r\n   titleField: 'name',\r\n   editStatusChanged: function(status, feature) { if (status === 'inserted ') {console.log(feature)}}\r\n});<\/pre>\n<h2 dir=\"rtl\"><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>newFeatureLayer(options) In order to display vector layer in the leaflet, the style and source settings must be made. For this, we create a new object of the newFeatureLayer class. Parameters: options (Object) Name Description options.source Vector layer vector layer that has been got \u00a0from the server. options.style Object? An object contains style information. e.g.{ color: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[63],"doc_tag":[],"class_list":["post-6056","docs","type-docs","status-publish","hentry","doc_category-features"],"_links":{"self":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/comments?post=6056"}],"version-history":[{"count":8,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6056\/revisions"}],"predecessor-version":[{"id":6617,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6056\/revisions\/6617"}],"wp:attachment":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/media?parent=6056"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/doc_category?post=6056"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/doc_tag?post=6056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}