[mapguide-users] How to get selection with fusion??

Kajar kajar.kuldsepp at gmail.com
Wed Mar 5 23:29:38 PST 2014


Ok I put the code to Aqua index.html also with openlayers popup code like
this, but cant get popup working when select feature on map. What I'm doing
wrong, I'm not skilled programmer, just beginner.

<script type="text/javascript">
//selection//
var themap;
var fusionInitialized = function() {
    $('AppContainer').resize({forceResize: true});
       
         themap = Fusion.getWidgetById('Map');
         themap.registerForEvent(Fusion.Event.MAP_SELECTION_ON,
selectionOn);
}
var selectionOn = function()
{
         var maps = themap.getAllMaps();
         var map = maps[0];
         map.getSelection(displaySelection);
}
function displaySelection(res){
  var layer = res.getLayer(0);
         var propNames = layer.getPropertyNames();
         var msg;
         for (var j=0; j<layer.getNumElements(); j++) {
                 for (var k=0; k<propNames.length; k++)
                      msg += ("\n" + propNames[k] +"  "+
layer.getElementValue(j, k));
          }
          alert(msg);
} 
//openlayers popup start//
        var map, drawControls, selectControl, selectedFeature;
        function onPopupClose(evt) {
            selectControl.unselect(selectedFeature);
        }
        function onFeatureSelect(feature) {
            selectedFeature = feature;
            popup = new OpenLayers.Popup.FramedCloud("chicken", 
                                    
feature.geometry.getBounds().getCenterLonLat(),
                                     null,
                                     "<div
style='font-size:.8em'>Feature: " + feature.id +"<br>Area: " +
feature.geometry.getArea()+"</div>",
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        }
        function onFeatureUnselect(feature) {
            map.removePopup(feature.popup);
            feature.popup.destroy();
            feature.popup = null;
        }    
        function init(){
            map = new OpenLayers.Map('map');
            var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers:
'basic'}); 

            var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");

            map.addLayers([wmsLayer, polygonLayer]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MousePosition());
            
            selectControl = new
OpenLayers.Control.SelectFeature(polygonLayer,
                {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
            drawControls = {
                polygon: new OpenLayers.Control.DrawFeature(polygonLayer,
                            OpenLayers.Handler.Polygon),
                select: selectControl
            };
            
            for(var key in drawControls) {
                map.addControl(drawControls[key]);
            }

            
            map.setCenter(new OpenLayers.LonLat(0, 0), 3);

        }

        function toggleControl(element) {
            for(key in drawControls) {
                var control = drawControls[key];
                if(element.value == key && element.checked) {
                    control.activate();
                } else {
                    control.deactivate();
                }
            }
        }
    
//popup end//
//selection sript end//
var dOverviewMap;



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-get-selection-with-fusion-tp4187847p5107827.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list