Openlayers Customizing Simple Popup

Source: Internet
Author: User

Many types of popup can be used in openlayers, and you can see it in the Openlayers popupmatrix.html example. There was a mistake before: Popup and marker are bound, and there must be marker to have a popup. And then recently in order to achieve the same demand: Click in the grid of the graph to generate a simple popup with just a little bit of information that doesn't require as much content as nestpupop in other projects. After their own groping, finally realized. First show the following:

The implementation method is not difficult, mainly as follows:

1. Add a click event to a Map object

Map.events.register (' Click ', Map, function (e) {               var position = Map.getlonlatfrompixel (e.xy);               Dealwithmapclick (position);           });

  

2. Map Click event Handling, Dealwithmapclick

/Add action on the map Bubble function Dealwithmapclick (POS) {                var lonlat = new Openlayers.lonlat (Pos.lon, Pos.lat);                var size=new openlayers.size (110,155);                var popup = new OpenLayers.Popup.Anchored (' n ', Lonlat, size, Getpopupcon (), NULL, FALSE, NULL);                var popups = map.popups;                for (var i = 0; i < popups.length; I  ) {                    Popups[i].destroy ();                }                Map.addpopup (popup);                Initpopupbtnevents ();}

  

3.popup Content Fill

 /* Fill Popup's contents */function Getpopupcon () {var str = ' <div id= ' selectedareapopup ' > ' ' <div class=areapopuphead> ' data.name ' &LT;/DIV&G                              t; '                                      ' <div class= ' areapopupitem ' > ' <div class= ' left ' > ' '  ' &l T;/div> ' <div class= "right" > "&LT;LABEL&G                              t; View reports </label> ' </div> ' </div> ' ' <div class= ' Areapopupitem abled ' > ' <div class= ' left ' > " '                                  ' </div> ' <div class= ' right ' > '                              ' <label> close bubbles </label> ' </div> '                        ' </div> ' <div id= "noreporttips" > Report construction, cannot view </div> '        ' </div> '; return str;}

  

This effect is relatively nestpupop, and the proportions are simple. No anchor point, only suitable for simple use.

Openlayers Customizing Simple Popup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.