Changes between Version 6 and Version 7 of UserRecipes

Show
Ignore:
Timestamp:
04/03/07 07:12:36 (8 years ago)
Author:
openlayers
Comment:

Made into index page

Legend:

Unmodified
Added
Removed
Modified
  • UserRecipes

    v6 v7  
    66 
    77= WMS = 
    8 == !GetFeatureInfo == 
    9 Brent Pedersen indirectly gave me the idea to start the User Ricipes after he had offer up his solution to the email list. 
    108 
    11 So in my function, findLayerClick() takes in an event and then packages up an URL to send to the WMS server using !GetFeatureInfo instead of !GetMap. 
    12 {{{ 
    13 /* 
    14  * An event occured so now drill down the layers to get the info 
    15  */ 
    16 function findLayerClick(event) { 
    17      
    18     layerlist = "here,there,everywhere"; 
    19  
    20     mouseLoc = map.getLonLatFromPixel(event.xy); 
    21  
    22     var url = prox.getFullRequestString({ 
    23                 REQUEST: "GetFeatureInfo", 
    24                 EXCEPTIONS: "application/vnd.ogc.se_xml", 
    25                 BBOX: map.getExtent().toBBOX(), 
    26                 X: event.xy.x, 
    27                 Y: event.xy.y, 
    28                 INFO_FORMAT: 'text/plain', 
    29                 QUERY_LAYERS: layerlist, 
    30                 FEATURE_COUNT: 1, 
    31                 WIDTH: map.size.w, 
    32                 HEIGHT: map.size.h}, 
    33                 "http://server.org/cgi-bin/wmsmap?"); 
    34  
    35     OpenLayers.loadURL(url, '', this, setHTML); 
    36  
    37     Event.stop(e); 
    38 } 
    39 }}} 
    40 NOTE: 
    41   ''prox'' is a layer defined elsewhere[[BR]] 
    42   ''mouseLoc'' is used later in setHTML() 
    43  
    44 findLayerClick is trggered by something like below in init(); 
    45 {{{ 
    46 map.events.register('click',findLayerClick); 
    47 }}} 
    48  
    49 Now for the callback ''setHTML'' referenced in the OpenLayers.loadURL() above 
    50 {{{ 
    51 /* 
    52  * Get the Ajax response and pop up a info bubble 
    53  */ 
    54 function setHTML(response) { 
    55     if (response.responseText.indexOf('no results') == -1) { 
    56         var cat="Unkown", src="Unkown", leg="Unkown", linkinfo=""; 
    57         var lines = response.responseText.split('\n'); 
    58         for (lcv = 0; lcv < (lines.length); lcv++) { 
    59             var vals = lines[lcv].replace(/^\s*/,'').replace(/\s*$/,'').replace(/ = /,"=").replace(/'/g,'').split('='); 
    60             if (vals[1] == "") { 
    61                 vals[1] = "Unkown"; 
    62             } 
    63             if (vals[0].indexOf('CATEGORY') != -1 ) { 
    64                 cat = vals[1]; 
    65             } else if (vals[0].indexOf('SOURCE') != -1 ) { 
    66                 src = vals[1]; 
    67             } else if (vals[0].indexOf('LEGEND') != -1 ) { 
    68                 leg = vals[1]; 
    69             } else if (vals[0].indexOf('DATAITEM') != -1 ) { 
    70                 linkinfo = vals[1]; 
    71             } 
    72         } 
    73         var popup_info = "<font size=2><b>" + cat + 
    74                         "<br>Description:</b> " + leg + 
    75                         "<br><a href='" + linkinfo + "' target='_blank'>More Info</a>" + 
    76                         "<br><font size=1>Source: " + src + 
    77                         "</font></font>"; 
    78         if (popup != null) { 
    79             popup.destroy(); 
    80             popup = null; 
    81         } 
    82         popup = new OpenLayers.Popup.AnchoredBubble("SDVegetationInfo", 
    83                                         mouseLoc, 
    84                                         new OpenLayers.Size(250,120), 
    85                                         popup_info, 
    86                                         null, 
    87                                         true); 
    88         popup.setBackgroundColor("#bcd2ee"); 
    89 //      popup.setOpacity(.7); 
    90         map.addPopup(popup); 
    91         popup.events.register("click", map, popupDestroy); 
    92     } 
    93 } 
    94 }}} 
    95 NOTE: popup is global var 
    96  
    97 And lastly the function ''popupDestroy'' 
    98 {{{ 
    99 /* 
    100  * Destory popup and stop event 
    101  */ 
    102 function popupDestroy(e) { 
    103     popup.destroy(); 
    104     popup = null; 
    105     OpenLayers.Util.safeStopPropagation(e); 
    106 } 
    107 }}} 
    108 '''''submitted by bwoodall''''' 
     9 * [wiki:GetFeatureInfo] - get information about a feature 
     10 * [wiki:DebugTileServer] - serve tiles containing debug information