【问题标题】:OpenLayer Popups for markers imported from google spreadsheet从谷歌电子表格导入的标记的 OpenLayer 弹出窗口
【发布时间】:2018-07-29 20:59:55
【问题描述】:

我正在寻找一种在当前设置中使用 framecloud 类型弹出窗口的方法。不幸的是,我所有的尝试要么没有奏效,要么只能在最近放置的制造商上奏效。

在尝试让它工作的过程中,我已将我的原始脚本从使用标记转换为使用向量来放置标记点(正如我所见,自定义向量比标记更容易。)

现在我可以使用哪一个我可以开始工作,但在为此工作了几天后,我已经束手无策,需要在正确的方向上伸出援助之手。

我的观点是使用 tabletop.js 从谷歌电子表格中提取的。该功能正在按照我的意愿工作,标记根据我称为“类型”的字段放置在各自的图层上。 虽然我感觉这可能是我的标记类型层问题的根源,但我不确定如何解决它。

您可以通过这些页面查看编码

(链接因位置变化而被删除。)

提前感谢所有帮助。

【问题讨论】:

    标签: vector map popup openlayers


    【解决方案1】:

    我终于让它工作了。对于处于类似情况的任何人,这是我的层的最终代码。我确实更改了图层的原始名称,并将我使用的电子表格涂黑了,但这些更改应该很明显。

    //
    //// Set 'Markers'
    //
                var iconMarker = {externalGraphic: 'http://www.openlayers.org/dev/img/marker.png', graphicHeight: 21, graphicWidth: 16};
                var iconGeo = {externalGraphic: './images/fortress.jpg', graphicHeight: 25, graphicWidth: 25};
                var iconAero = {externalGraphic: './images/aeropolae.jpg', graphicHeight: 25, graphicWidth: 25}; // Image is the creation of DriveByArtist: http://drivebyartist.deviantart.com/
    
                var vector1 = new OpenLayers.Layer.Vector("1");
                var vector2 = new OpenLayers.Layer.Vector("2");
                var vector3 = new OpenLayers.Layer.Vector("3");
    
    
    // Pulls map info from Spreadsheet
    //*
            Tabletop.init({
              key: 'http://xxxxxxxxxx', //Spreadsheet URL goes here
              callback: function(data, tabletop) { 
                var i,
                    dataLength = data.length;
    
                for (i=0; i<dataLength; i++) { //following are variables from the spreadsheet
                    locName = data[i].name;
                    locLon = data[i].long;
                    locLat = data[i].lat;
                    locInfo = data[i].info;
                    locType = data[i].type; // Contains the following string in the cell, which provides a pre-determined output based on provided information in the spreadsheet: =ARRAYFORMULA("<h2>"&B2:B&"</h2><b>"&G2:G&"</b><br /> "&C2:C&", "&D2:D&"<br />"&E2:E&if(ISTEXT(F2:F),"<br /><a target='_blank' href='"&F2:F&"'>Read More...</a>",""))
    
                    locLonLat= new OpenLayers.Geometry.Point(locLon, locLat);
    
                   switch(locType)
                    {
                    case "Geopolae":
                         feature = new OpenLayers.Feature.Vector(
                         locLonLat,
                         {description:locInfo},
                         iconGeo);
                        vector1.addFeatures(feature);        
                      break;
                    case "POI":
                      feature = new OpenLayers.Feature.Vector(
                         locLonLat,
                         {description:locInfo},
                         iconMarker);
                        vector2.addFeatures(feature);             
                      break;
                    case "Aeropolae":
                      feature = new OpenLayers.Feature.Vector(
                         locLonLat,
                         {description:locInfo},
                         iconAero);
                        vector3.addFeatures(feature);             
                      break;  
                    }
    
                  }
              },
              simpleSheet: true 
            });             
    
                map.addLayers([vector1, vector2, vector3]);
    
                map.addControl(new OpenLayers.Control.LayerSwitcher());
    
            //Add a selector control to the vectorLayer with popup functions
            var controls = {
              selector: new OpenLayers.Control.SelectFeature(Array(vector1, vector2, vector3), { onSelect: createPopup, onUnselect: destroyPopup })
            };
    
            function createPopup(feature) {
              feature.popup = new OpenLayers.Popup.FramedCloud("pop",
                  feature.geometry.getBounds().getCenterLonLat(),
                  null,
                  '<div class="markerContent">'+feature.attributes.description+'</div>',
                  null,
                  true,
                  function() { controls['selector'].unselectAll(); }
              );
              feature.popup.autoSize = true;
              feature.popup.minSize = new OpenLayers.Size(400,100);
              feature.popup.maxSize = new OpenLayers.Size(400,800);
              feature.popup.fixedRelativePosition = true;
              feature.popup.overflow ="auto";
              //feature.popup.closeOnMove = true;
              map.addPopup(feature.popup);
            }
    
            function destroyPopup(feature) {
              feature.popup.destroy();
              feature.popup = null;
            }
    
            map.addControl(controls['selector']);
            controls['selector'].activate();
    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多