PHP and jquery Implementation map area data statistics show data sample _php instance

Source: Internet
Author: User


Html

First in the head part of the load Raphael.js library files and chinamappath.js path information file, this article does not repeat, the only difference is the need to add a div#tip in the body, to show the map information of the balloon.

Copy Code code as follows:

<div id= "Map" ></div>
<div id= "Tip" ></div>

Jquery

By calling Raphael to draw a map of China, and then load statistics, because the map block small, we do not load in the map when the data displayed in the map block, we through the mouse interactive implementation of the data information to better display to the user. When the mouse slides to the province block, position the mouse coordinates through E.pagex and e.pagey, and then position the Cue box Div#tip via the jquery css () method, and add the name of the corresponding province and the number of active users to the cue box and show it, see the code:

Copy Code code as follows:

$ (function () {
$.get ("json.php", function (JSON) {

...//here omit code several

var i=0;
For (var. in) {
china[state][' path '].color = Raphael.getcolor (0.9);
(Function (St, state) {
var prodata = data[i];
var fillcolor = colors[arr[i]];
St.attr ({fill:fillcolor});//Fill background color
Xoffset = 70;
Yoffset = 180;
St.hover (function (e) {//mouse sliding
St.animate ({fill: "#fdd", Stroke: "#eee"}, 500);
R.safari ();
$ ("#tip"). CSS ({"Top":(E.pagey-xoffset) + "px", "left":(E.pagex-yoffset) + "px"}). FadeIn ("Fast")
. HTML ("},function () {//mouse left
St.animate ({fill:fillcolor, stroke: "#eee"}, 500);
R.safari ();
$ ("#tip"). Hide ();
});

St.mousemove (function (e) {//mouse move
$ ("#tip"). CSS ({"Top":(E.pagey-xoffset) + "px", "left":(E.pagex-yoffset) + "px"});
R.safari ();
});

}) (china[state][' path '], state);
i++;
}
});
});

The above code can be seen, through the hover () of jquery () mouse to the province block, call pop-up prompt box, and load the data into the prompt box, and it is noteworthy that we also need to add an effect, that is, the mouse in the province block mobile MouseMove (), You should also call the prompt box to follow the mouse to move together, otherwise, when the mouse in a block in a province sliding words prompt box position will not change, this will affect the experience effect, small changes can enhance the user experience.
Finally, if you need to customize the effect of the cue box, you can set the CSS style of the hint box, in this case the simple CSS code is as follows:

Copy Code code as follows:

#tip {Position:absolute width:180px; border:1px solid #d3d3d3 background: #fff;d isplay:none;
-moz-border-radius:5px; -webkit-border-radius:5px; Overflow:hidden; border-radius:5px;
-moz-box-shadow:1px 1px 2px Rgba (0,0,0,.2); -webkit-box-shadow:1px 1px 2px Rgba (0,0,0,.2);
box-shadow:1px 1px 2px Rgba (0,0,0,.2);}
#tip h4{height:28px; line-height:28px; padding-left:6px; background: #f0f0f0}
#tip p{line-height:24px padding:2px 4px}

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.