【问题标题】:HERE Maps Morocco and Western SaharaHERE 地图摩洛哥和西撒哈拉
【发布时间】:2022-07-19 21:30:42
【问题描述】:

如你所知,摩洛哥disputes the territory of Western Sahara

我们正在使用摩洛哥的地缘政治视图 (political_view),它成功移除了边界,但并未从视图中移除标签“西撒哈拉”。

mapStyle.setProperty('global.political_view','ma');

我们是否需要设置一些额外的属性,或者这是否需要改变摩洛哥的政治观点?

【问题讨论】:

    标签: here-api heremaps


    【解决方案1】:

    是的,使用地缘政治观点成功地移除了边界,但没有移除标签。

    你可以实现它来改变样式的“transform.political_view”的程序代码。

    1. 在skeleton.yaml 文件中(路径:“sources.omv.transform.political_view”) - 也许您需要地图样式编辑器:https://enterprise.here.com/map-style-editor/

    直接下载(已经为你返工):https://github.com/alexisad/alexisad.github.io/blob/master/vector-styles/removeSomeLabel/skeleton.yaml

    1. 在运行时,代码:

    /**
     * The function add the "change" event listener to the map's style
     * and modifies colors of the map features within that listener.
     * @param  {H.Map} map      A HERE Map instance within the application
     */
    function interleave(map){
      var provider = map.getBaseLayer().getProvider();
    
      // get the style object for the base layer
      var style = provider.getStyle();
    
      var changeListener = () => {
        if (style.getState() === H.map.render.webgl.Style.State.READY) {
          style.removeEventListener('change', changeListener);
          
          const filterWestSahara = `function(data, extraData) {
                if (extraData && extraData.political_view && extraData.political_view == "ma" && data.places) {
                    const pview = extraData.political_view;
                    const features = data.places.features;
                    let featureIdx = features.length;
                    while (featureIdx--) {
                        let properties = features[featureIdx].properties;
                        if (properties['name:en'] && properties['name:en'].toUpperCase() == "WESTERN SAHARA") {
                            properties.kind = 'country:' + pview;
                        }
                    }
                }
              if (extraData && extraData.political_view && data.boundaries) {
                
                const pview = extraData.political_view;
                const features = data.boundaries.features;
                let featureIdx = features.length;
                while (featureIdx--) {
                  let properties = features[featureIdx].properties;
                  if (properties['kind:'+pview]) {
                    properties.kind = properties['kind:'+pview];
                  }
                }
              }
              return data;
            }
    `;
      style.setProperty("sources.omv.transform.political_view", filterWestSahara, true);
      style.setProperty('global.political_view','ma');
          
    
        }
      }
    
      style.addEventListener('change', changeListener);
    }
    
    /**
     * Boilerplate map initialization code starts below:
     */
    
    //Step 1: initialize communication with the platform
    // In your own code, replace variable window.apikey with your own apikey
    var platform = new H.service.Platform({
      apikey: window.apikey
    });
    var defaultLayers = platform.createDefaultLayers();
    
    //Step 2: initialize a map
    var map = new H.Map(document.getElementById('map'),
      defaultLayers.vector.normal.map, {
      center: {lat: 52.51477270923461, lng: 13.39846691425174},
      zoom: 10,
      pixelRatio: window.devicePixelRatio || 1
    });
    //map.getViewModel().setLookAtData({tilt: 45});
    
    // add a resize listener to make sure that the map occupies the whole container
    window.addEventListener('resize', () => map.getViewPort().resize());
    
    //Step 3: make the map interactive
    // MapEvents enables the event system
    // Behavior implements default interactions for pan/zoom (also on mobile touch environments)
    var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
    
    // Now use the map as required...
    interleave(map);
    

    JSFiddle:https://jsfiddle.net/hnromqaL/1/

    【讨论】:

      【解决方案2】:

      HERE 开发人员支持的答案在几天前都完美无缺。现在答案提供了一张看起来很奇怪的地图,其中摩洛哥和毛里塔尼亚之间的边界不存在。

      Map screenshot taken from the provided JSFiddle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-30
        • 2019-11-09
        • 1970-01-01
        • 1970-01-01
        • 2023-02-23
        相关资源
        最近更新 更多