{"id":6008,"date":"2022-12-28T16:57:58","date_gmt":"2022-12-28T13:27:58","guid":{"rendered":"https:\/\/en.geobox.ir\/developers\/?post_type=docs&#038;p=6008"},"modified":"2023-01-21T09:16:40","modified_gmt":"2023-01-21T05:46:40","slug":"add-vector-layer-2","status":"publish","type":"docs","link":"https:\/\/en.geobox.ir\/developers\/docs\/add-sources-geobox-api-for-leaflet\/add-vector-layer-2\/","title":{"rendered":"Add vector layer"},"content":{"rendered":"<h2 style=\"text-align: left;\">Add vector layer or vector layer view<\/h2>\n<p>To add a vector layer or vector layer view to the map, first copy the uuid of the vector layer from the geobox portal and<a href=\"https:\/\/en.geobox.ir\/developers\/docs\/vector\/working-with-vectorlayer\/#4-toc-title\"> get the vector layer from the server<\/a>: (examples are explained for vector layer, but the same is true for vector layer view.)<\/p>\n<h3>getVectorLayer(layer_uuid)<\/h3>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const vectorLayer\u00a0= await Server.getVectorLayer('4f9f3e4b-4dc1-469b-83ab-00ae00f02581');<\/pre>\n<p>After getting the vector layer, it is necessary to create a feature layer from the vector layer. For this, use the <a href=\"https:\/\/en.geobox.ir\/developers\/docs\/features\/create-feature-layer-and-add-to-map\/\">featureLayer creation guide<\/a>.<\/p>\n<h3>newFeatureLayer(options)<\/h3>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fLayer = map.newFeatureLayer({ source: vectorLayer });<\/pre>\n<p>After the new object is created from the newFeatureLayer class, you need to load the features of the layer.<\/p>\n<h3>loadFeatures(options)<\/h3>\n<p><strong>Parameters:<\/strong><\/p>\n<p>options (Object)<\/p>\n<table class=\"table table--fixed table--compact\" style=\"width: 82.5964%; height: 204px;\">\n<thead>\n<tr class=\"bg-gray-faint\" style=\"height: 26px;\">\n<th style=\"text-align: left; height: 48px; width: 22.8381%;\">Name<\/th>\n<th style=\"text-align: left; height: 48px; width: 102.491%;\">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.<span style=\"font-family: inherit; font-size: inherit;\">f<\/span><\/div>\n<div>String<\/div>\n<div>Default: &#8216;topojson&#8217;<\/div>\n<\/td>\n<td style=\"height: 26px; width: 102.491%; text-align: left;\">Output format. Choices are: &#8216;topojson&#8217; | &#8216;json&#8217;<\/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.<span style=\"font-family: inherit; font-size: inherit;\">skip<\/span><\/div>\n<div>\n<div>Number?<\/div>\n<div>Default: 0<\/div>\n<\/div>\n<\/td>\n<td style=\"height: 26px; width: 102.491%; text-align: left;\">Number of skipped features.<\/td>\n<\/tr>\n<tr style=\"height: 79px;\">\n<td style=\"height: 79px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.<span style=\"font-family: inherit; font-size: inherit;\">limit<\/span><\/div>\n<div>\n<div>Number?<\/div>\n<div>Default:1000<\/div>\n<\/div>\n<\/div>\n<\/td>\n<td style=\"height: 79px; width: 102.491%; text-align: left;\">Maximum number for result features.<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 25px; width: 22.8381%; text-align: left;\">\n<div class=\"txt-mono txt-bold txt-break-word\">options.<span style=\"font-family: inherit; font-size: inherit;\">order_by<\/span><\/div>\n<div>String?<\/div>\n<\/td>\n<td style=\"height: 25px; width: 102.491%; text-align: left;\">Comma separated list of fields for sorting results [field1 A|D, field2 A|D, \u2026]. e.g. name A, type D<br \/>\nNOTE: &#8220;A&#8221; denotes ascending order and &#8220;D&#8221; denotes descending order.<\/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>GeoJSON: Returns GeoJSON of features.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">await fLayer.loadFeatures({ f: 'topojson', skip:0, limit:1000, order_by: 'id A' });<\/pre>\n<p>Finally, add the layer to the map using the addToMap method.<\/p>\n<h3>addToMap()<\/h3>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fLayer.addToMap();<\/pre>\n<p>After adding the layer to the map, it is better to change the view of the map to the layer extent. For this purpose, use the zoomToAll method.<\/p>\n<h3>zoomToAll()<\/h3>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fLayer.zoomToAll();<\/pre>\n<p class='codepen'  data-height='500' data-theme-id='1' data-slug-hash='xxJZyYw' data-default-tab='result' data-animations='run' data-editable='' data-embed-version='2'>\nSee the Pen <a href=\"https:\/\/codepen.io\/geobox-gl-demo\/pen\/xxJZyYw\">Contact Form \u2013 Pen a Day 20<\/a> by Geobox (<a href=\"https:\/\/codepen.io\/geobox-gl-demo\">@geobox-gl-demo<\/a>) on <a href=\"http:\/\/codepen.io\">CodePen<\/a>.1<\/p>\n<script async src=\"https:\/\/cpwebassets.codepen.io\/assets\/embed\/ei.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>Add vector layer or vector layer view To add a vector layer or vector layer view to the map, first copy the uuid of the vector layer from the geobox portal and get the vector layer from the server: (examples are explained for vector layer, but the same is true for vector layer view.) getVectorLayer(layer_uuid) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[62],"doc_tag":[],"class_list":["post-6008","docs","type-docs","status-publish","hentry","doc_category-add-sources-geobox-api-for-leaflet"],"_links":{"self":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6008","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=6008"}],"version-history":[{"count":6,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6008\/revisions"}],"predecessor-version":[{"id":6615,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/docs\/6008\/revisions\/6615"}],"wp:attachment":[{"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/media?parent=6008"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/doc_category?post=6008"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/en.geobox.ir\/developers\/wp-json\/wp\/v2\/doc_tag?post=6008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}