小编Chr*_*ssy的帖子

OpenLayers 3矢量图层上所有要素的范围?

我有一个OpenLayers 3地图,带有基础层和矢量图层.

this.topoLayer = new ol.layer.Vector({
  source: new ol.source.Vector(),
  style: style
});

var baseLayer = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://[…]/{z}/{x}/{y}.png',
        crossOrigin: 'null'
    })
});

this.map = new ol.Map({
    target: 'map',
    layers: [baseLayer, this.topoLayer],
    view: new ol.View2D({
        center: ol.proj.transform([11.38,  48.54], this.options.markerEPSG, this.options.mapEPSG),
        zoom: 5,
    }),
});
Run Code Online (Sandbox Code Playgroud)

在用户交互时,我向向量层添加和删除了几个要素.以下是添加新功能的功能:

  var feature = new ol.Feature({
        topo: topo,
        selected: false,
        geometry: new ol.geom.Point(ol.proj.transform(location, this.options.markerEPSG, this.options.mapEPSG)),
  });

  this.topoLayer.getSource().addFeatures([feature]);
Run Code Online (Sandbox Code Playgroud)

添加/删除新功能后,我想自动缩放和平移地图以适应我的功能.在旧的OpenLayers API中getDataExtent,矢量图层上有一个函数可以检索显示的所有特征周围的"边界框".但我想知道如何使用新的API做到这一点.

javascript openlayers openlayers-3

19
推荐指数
3
解决办法
3万
查看次数

Plotly更新数据

好的,所以我有以下代码:

    var element = document.getElementById(scope.changeid);

function getData(division,redraw) {
    var employeeData = [];
    if (!division) {
        $http.get(api.getUrl('competenceUserAverageByMyDivisions', null)).success(function (response) {
            processData(response,redraw);
        });
    }
    else {
        $http.get(api.getUrl('competenceUserAverageByDivision', division)).success(function (response) {
            processData(response,redraw);
        })
    }

}

function processData(data,redraw) {
    var y = [],
        x1 = [],
        x2 = [];

    data.forEach(function (item) {
        y.push(item.user.profile.firstname);
        x1.push(item.current_level);
        x2.push(item.expected);
    });

    var charData = [{
            x: x1,
            y: y,
            type: 'bar',
            orientation: 'h',

            name: 'Nuværende'
        }, {
            x: x2,
            y: y,
            type: 'bar',
            orientation: 'h',

            name: 'Forventet'
        }],
        layout …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs plotly

18
推荐指数
2
解决办法
2万
查看次数

Bounds如何在OpenLayers 3中运行?

难道概念OpenLayers.Bounds从2.X的OpenLayers仍处于3的OpenLayers存在?它是如何改变的,它的新名称是什么?

openlayers openlayers-3

14
推荐指数
3
解决办法
2万
查看次数

base64.encodestring在python 3中失败

以下代码在python 2机器上成功运行:

base64_str = base64.encodestring('%s:%s' % (username,password)).replace('\n', '')
Run Code Online (Sandbox Code Playgroud)

我试图将它移植到Python 3,但是当我这样做时,我遇到以下错误:

>>> a = base64.encodestring('{0}:{1}'.format(username,password)).replace('\n','')
Traceback (most recent call last):
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 519, in _input_type_check
    m = memoryview(s)
TypeError: memoryview: str object does not have the buffer interface

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 548, in encodestring
    return encodebytes(s)
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 536, in encodebytes
    _input_type_check(s)
  File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 522, in …
Run Code Online (Sandbox Code Playgroud)

python base64 encoding python-2.7 python-3.4

14
推荐指数
2
解决办法
1万
查看次数

记录器格式和throwable,slf4j

在将一些旧记录器转换String.format为较新的slf4j {}变体的过程中,我偶然发现了这种情况:

logger.error(String.format("%s ... %s ... %s", ...), e);
Run Code Online (Sandbox Code Playgroud)

我想只使用{}并删除String格式,但是,包含throwable的记录器方法签名是:

error(String msg, Throwable t)

所以我必须保持String.format这种情况?!

为什么没有:

error(Throwable t, String format, Object... arguments)

java logging slf4j

12
推荐指数
1
解决办法
2343
查看次数

如何在gitlab wiki上创建表?

如何在gitlab wiki上创建表?

它使用github风格的markdown,这种降价支持表的味道,但我不能使下面的例子工作:

冒号可用于对齐列.

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

Markdown | Less | Pretty
--- | --- | ---
*Still* | …
Run Code Online (Sandbox Code Playgroud)

markdown gitlab

11
推荐指数
1
解决办法
1万
查看次数

Eclipse错误/警告忽略未使用的变量分析中的断言

我有"隐藏"错误,因为Eclipse没有报告"未使用"变量,因为它们用于断言(前置条件),例如:

public void method(final String text, ...other parameters) {
  assert StringUtils.isNotBlank(text);
  ...
  // The text variable is never used in the method.
  // If Eclipse had reported the variable as 'unused' I would have noticed that something is wrong with the code.
  ...
}
Run Code Online (Sandbox Code Playgroud)

我想告诉Eclipse在检查未使用的变量时忽略断言.我怀疑有人会传递一个参数只在它上面运行一个断言...也让我知道FindBugs或其他工具是否可以做到这一点.

java eclipse static-analysis findbugs unused-variables

11
推荐指数
1
解决办法
849
查看次数

postgresql 9.5使用jsonb_set更新特定的jsonb数组值

目前我正在使用postgreSQL 9.5并尝试更新jsonb字段数组中的值.但我无法获得所选值的索引

我的表看起来像:

 CREATE TABLE samples (
    id serial,
    sample jsonb
 );
Run Code Online (Sandbox Code Playgroud)

我的JSON看起来像:

{"result": [
    {"8410": "ABNDAT", "8411": "Abnahmedatum"},
    {"8410": "ABNZIT", "8411": "Abnahmezeit"},
    {"8410": "FERR_R", "8411": "Ferritin"}
]}
Run Code Online (Sandbox Code Playgroud)

我的SELECT语句可以获得正确的值:

SELECT 
    id, value 
FROM 
    samples s, jsonb_array_elements(s.sample#>'{result}') r  
WHERE 
    s.id = 26 and r->>'8410' = 'FERR_R';
Run Code Online (Sandbox Code Playgroud)

结果是:

id | value
----------------------------------------------
26 | {"8410": "FERR_R", "8411": "Ferritin"}
Run Code Online (Sandbox Code Playgroud)

好的,这就是我想要的.现在我想使用以下UPDATE语句执行更新以添加新元素"ratingtext"(如果尚未存在):

UPDATE 
    samples s
SET
    sample = jsonb_set(sample,
              '{result,2,ratingtext}',
              '"Some individual text"'::jsonb,
              true)
WHERE
      s.id = 26;
Run Code Online (Sandbox Code Playgroud)

执行UPDATE语句后,我的数据看起来像这样(也正确):

{"result": [
    {"8410": "ABNDAT", "8411": "Abnahmedatum"}, …
Run Code Online (Sandbox Code Playgroud)

arrays postgresql json sql-update jsonb

10
推荐指数
1
解决办法
4988
查看次数

使用Thread时HashMap顺序会更改,但在没有Thread的情况下是常量

我知道HashMap 不保证订单.请考虑以下代码:

import java.util.HashMap;
import java.util.Map;

public class SandBox {
    protected static class Book {
        String name;

        public Book(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    protected static class MyThread extends Thread {
        @Override
        public void run() {
            super.run();
            final int n = 10;
            Book[] books = new Book[n];
            for (int i=0; i<n; i++)
                books[i] = new Book("b" + i);
            for (Book b : books)
                System.out.print(b + ", ");
            System.out.println();
            HashMap<Book, …
Run Code Online (Sandbox Code Playgroud)

java multithreading hashmap

10
推荐指数
1
解决办法
771
查看次数

为什么Java中的一些资源没有被垃圾收集,必须关闭或自动关闭?

如果你是幸运一些类实现AutoClosable但有时你必须要小心,检查现有的方法要注意有一个close,destroyshutdown方法(或什么都笔者决定将它命名).

这是Java中资源泄漏的主要来源.

我和一位同事正在讨论这个问题,并且也想知道:为什么这不能以某种方式自动化?

从理论上讲,您可以使用finalize这种情况,但不建议这样做.那么为什么没有办法只使用其中一些可关闭的资源并让GC在实例不再可用时自动关闭它们而不必记住明确地写一些close处理代码(比如try ...)?

这是因为在GC启动之前系统可能资源不足(文件描述符,...)?

注意:我尽可能使用autoclose并使用FindBugs(+ FB contrib)检查我的代码是否存在内存泄漏,但我仍然想知道......

同样感兴趣(如答案中所讨论的):最终确定的弃用.

java resources garbage-collection finalize

8
推荐指数
1
解决办法
174
查看次数