首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mapbox更新属性符合几何学

Mapbox更新属性符合几何学
EN

Stack Overflow用户
提问于 2017-12-17 18:15:27
回答 1查看 132关注 0票数 0

当我在地图上添加一个新的标记时,我会添加一个属性,以便能够使用自定义图标。然后我保存了geoJson,但是当我看到保存的geojson时,我看到了错误的设置。

这是代码:

代码语言:javascript
复制
function updtateMarker(t, layer) {

   // t is the value I need to save in property "iconSet"
   // layer is the layer ID

    var marker = featureGroup._layers[layer];
    console.log("### updtate Marker ###");

    // if marker already exists it works good
    if (marker.feature && marker.feature.properties && marker.feature.properties.iconSet) {

        marker.feature.properties.iconSet = t;
        marker.setIcon(arrayIcon[t]); //  update icon on Map

    } else {

        // Marker is new, it doesn't exist

        //  update marker icon on Map
        marker.setIcon(runnaloIcon[t]);

       marker.feature = {properties: {iconSet: t}};
       // *****   THIS IS WRONG: why? ******
       // this will be saved in "geometry" !??!

    }

}

这是th 错误的 geojson:

代码语言:javascript
复制
{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "properties": {
            "iconSet": 2
        },
        "geometry": {
            "type": "Point",
            "coordinates": [9.672668, 44.934964]
        }
    }

这就是我需要的:

代码语言:javascript
复制
{
    "type": "Feature",
    "properties": {
        "iconSet": 2
    },
    "geometry": {
        "type": "Point",
        "coordinates": [9.672668, 44.934964]
    }
}

为了完成我的代码,这是保存部分

代码语言:javascript
复制
 var data = featureGroup.toGeoJSON();
 var convertedData = JSON.stringify(data);

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

发布于 2017-12-18 07:01:35

我修正了它,当我创建新的标记时添加属性,而不是在使用它的时候。

代码语言:javascript
复制
map.on('draw:created', function (event) {

   // Each time a featuree is created, it's added to the over arching feature group

   if (event.layerType == "marker") {

       var layer = event.layer;

       // set the  first property
       feature = layer.feature = layer.feature || {};
       feature.type = feature.type || "Feature";
       var props = feature.properties = feature.properties || {};
       props.iconSet = 1;  // default value

   }

})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47858085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档