首页 / 浏览问题 / 云GIS / 问题详情
iserver SQL查询无法正确识别中文
580EXP 2019年06月04日
iserver 9.1.2 SQL查询无法正确识别中文,通过中文查不到,但英文和数字是正常的。请问什么原因?

2 个回答

您好,通过中文可以查询出来的呢,我看了你的查询条件。中文字符串的话,是不是要加\斜杆去转义一下呢?

1,255EXP 2019年06月05日

您好,我这边用9.1.2的Windows deploy包测试了一下,自己新建了一个工作空间,绘制了几个面,然后查询中文字符的条件和数据集都是可以的


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title data-i18n="resources.title_getFeatureBySQL"></title>
<style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
<div class='panel-heading'>
<h5 class='panel-title text-center' data-i18n="resources.title_getFeatureBySQL"></h5></div>
<div class='panel-body content'>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="getFeaturesBySQL()"/>&nbsp;
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearFeatures()"/>
</div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var map, local, layer, vectorLayer,
        style = {
            strokeColor: "#304DBE",
            strokeWidth: 1,
            fillColor: "#304DBE",
            fillOpacity: "0.8"
        },
        url1 =  "http://localhost:8090/iserver/services/map-zz/rest/maps/中字@zz",
        url2 = "http://localhost:8090/iserver/services/data-zz/rest/data";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("中字", url1, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
    }

    function addLayer() {
        map.addLayers([layer, vectorLayer]);
        map.setCenter(new SuperMap.LonLat(141.24 , 51.54), 0);
    }

    function getFeaturesBySQL() {
        vectorLayer.removeAllFeatures();

        var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;

        getFeatureParam = new SuperMap.REST.FilterParameter({
            name: "中字@zz",
            attributeFilter: "名字=\"北京\""
        });
        getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
            queryParameter: getFeatureParam,
            datasetNames: ["zz:中字"]
        });
        getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
            eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
        });

        getFeatureBySQLService.processAsync(getFeatureBySQLParams);
    }

    function processCompleted(getFeaturesEventArgs) {
        var i, len, features, feature, result = getFeaturesEventArgs.result;
        if (result && result.features) {
            features = result.features
            for (i = 0, len = features.length; i < len; i++) {
                feature = features[i];
                feature.style = style;
                vectorLayer.addFeatures(feature);
            }
        }
    }

    function processFailed(e) {
        widgets.alert.showAlert(e.error.errorMsg, false);
    }

    function clearFeatures() {
        //先清除上次的显示结果
        vectorLayer.removeAllFeatures();
        vectorLayer.refresh();
    }

</script>
</body>
</html>

用的范例是http://iclient.supermap.io/examples/classic/editor.html#query_getFeatureBySQL

5,668EXP 2019年06月05日

我用的是leaflet,以官网示例为例http://iclient.supermap.io/examples/leaflet/editor.html#02_getFeatureBySQL

查询条件写成SMID=1查到了俄罗斯,"CAPITAL = 莫斯科"就查不到。里面有CAPITAL字段的。


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_getFeatureBySQL"></title>
<script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var map, resultLayer,
        baseUrl = host + "/iserver/services/map-world/rest/maps/World",
        url = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: {lon: 0, lat: 0},
        maxZoom: 18,
        zoom: 1
    });
    L.supermap.tiledMapLayer(baseUrl).addTo(map);
    query();

    function query() {
        var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
            queryParameter: {
                name: "Countries@World",
                attributeFilter: "CAPITAL = 莫斯科"
            },
            datasetNames: ["World:Countries"]
        });
        L.supermap
            .featureService(url)
            .getFeaturesBySQL(sqlParam, function (serviceResult) {
                resultLayer = L.geoJSON(serviceResult.result.features).addTo(map).bindPopup('SMID = 247');
            });
    }
</script>
</body>
</html>

请问怎样能将这个查询结果居中放大显示呢?
...