1

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

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

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

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

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

(由于位置变化,链接被删除。)

感谢您提前提供的所有帮助。

4

1 回答 1

1

I finally got it to work. For anyone in a similar situation here's my final code for the layers. I did change the names of the layers from what they are originally and blacked out the spreadsheet I used, but the changes should be noticeable.

//
//// 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();

        }
于 2013-06-19T04:10:48.317 回答