diff src/djol/WFSSource.js @ 24:f750c89976d3

Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
author cin
date Thu, 07 Dec 2017 19:19:29 +0300
parents 67a5de7581ad
children
line wrap: on
line diff
--- a/src/djol/WFSSource.js	Wed Dec 06 14:19:45 2017 +0300
+++ b/src/djol/WFSSource.js	Thu Dec 07 19:19:29 2017 +0300
@@ -1,7 +1,16 @@
-define([ "ol", "dojo/request", "dojo/_base/array", "implab/safe"],
-
-function(ol, request, array, safe) {
-    return function(wfs, featurePrefix, featureType, featureNS, queryArgs) {
+define([
+    "ol",
+    "dojo/request",
+    "dojo/_base/array",
+    "implab/safe",
+    "implab/log/trace!"
+], function (ol,
+    request,
+    array,
+    safe,
+    trace
+) {
+    return function (wfs, featurePrefix, featureType, featureNS, queryArgs) {
         if (arguments.length == 1) {
             featurePrefix = wfs.featurePrefix;
             featureType = wfs.featureType;
@@ -16,36 +25,38 @@
         safe.argumentNotEmptyString(featureType, "featureType");
 
         var format = new ol.format.WFS({
-            featureNS : featureNS,
-            featureType : featureType
+            featureNS: featureNS,
+            featureType: featureType
         });
 
         var layerName = featurePrefix + ":" + featureType;
 
         function loader(extent, resolution, projection) {
             var query = {
-                service : 'WFS',
-                version : '1.1.0',
-                request : 'GetFeature',
-                typename : layerName,
-                srsname : projection.getCode()
+                service: 'WFS',
+                version: '1.1.0',
+                request: 'GetFeature',
+                typename: layerName,
+                srsname: projection.getCode()
             };
             safe.mixin(query, queryArgs);
-            
+
             if (extent && isFinite(extent[0]))
                 query.bbox = extent.join(',') + "," + projection.getCode();
-            
+
             return request(wfs, {
-                query : query,
-                handleAs : 'xml'
-            }).then(function(data) {
+                query: query,
+                handleAs: 'xml'
+            }).then(function (data) {
                 // в загрузчике нельзя вызывать метод source.clear() поскольку
                 // это приводит к рекурсии
                 var features = format.readFeatures(data);
 
-                var map = {}, del = [], add = [];
+                var map = {},
+                    del = [],
+                    add = [];
 
-                array.forEach(features, function(x) {
+                array.forEach(features, function (x) {
                     // HACK исправляем идентификаторы, чтобы они совпадали с
                     // реальными
 
@@ -69,14 +80,14 @@
                     }
                 });
 
-                source.forEachFeatureInExtent(extent, function(x) {
+                source.forEachFeatureInExtent(extent, function (x) {
                     if (!(x.getId() in map))
                         del.push(x);
                 });
 
                 source.addFeatures(add);
 
-                array.forEach(del, function(x) {
+                array.forEach(del, function (x) {
                     source.removeFeature(x);
                 });
 
@@ -90,23 +101,23 @@
         var cls = ol.source.ServerVector || ol.source.Vector;
         var revision = 0;
         var source = new cls({
-            loader : loader,
+            loader: loader,
             //revision: revision
-            wrapX : false
-        // ,
-        // strategy : options.strategy || ol.loadingstrategy.all,
-        // projection : options.projection
+            wrapX: false
+            // ,
+            // strategy : options.strategy || ol.loadingstrategy.all,
+            // projection : options.projection
         });
         source.set("revision", revision);
-        source.reload = function(extent,resolution, projection, q) {
+        source.reload = function (extent, resolution, projection, q) {
             if (arguments.length >= 4)
                 queryArgs = q;
             if (!extent)
                 extent = [-Infinity, -Infinity, Infinity, Infinity];
-            return loader(extent,resolution,projection);
+            return loader(extent, resolution, projection);
         };
-        
-        console.log(wfs, layerName);
+
+        trace.log("{0} -> {1}", layerName, wfs);
         return source;
     };
 });
\ No newline at end of file