-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.qtip.html
148 lines (126 loc) · 5.01 KB
/
jquery.qtip.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE HTML>
<html>
<head>
<!-- from : http://jsfiddle.net/77CLm/30/ -->
<title>jquery qtip example</title>
<link rel="stylesheet" href="css/jquery.qtip.css" type="text/css">
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<!-- ff debug ol -- must be relative to OpenLayers
<script src="../lib/Firebug/firebug.js"></script>
-->
<script src="js/OpenLayers.js"></script>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery.qtip.js"></script>
<script>
// some defaults
var def_lat = 40.55;
var def_lon = 10.0;
var def_zoom = 2;
(function(){
var map, fromProjection, toProjection;
function initMap(lat,lon,zoom) {
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
// units: "m",
// maxResolution: 156543.0339,
// maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
// 20037508.34, 20037508.34),
//numZoomLevels: 20,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine(),
// new OpenLayers.Control.Permalink('permalink'), // THIS FAILS! WHY???
new OpenLayers.Control.KeyboardDefaults()
]
};
//var url = "http://a.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256/${z}/${x}/${y}.png";
//var url = "http://93.93.252.173/osm/${z}/${x}/${y}.png";
map = new OpenLayers.Map("basicMap",options);
//var newL = new OpenLayers.Layer.OSM("Default", url);
var newL = new OpenLayers.Layer.OSM("Default");
// newL.events.register("loadend", newL, layerLoadend);
map.addLayer(newL);
fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var lonLat = new OpenLayers.LonLat(10.0, 40.55).transform(
fromProjection, toProjection);
//new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter(lonLat, zoom);
poiLayer = new OpenLayers.Layer.Vector('myPoiLayer');
var myControl = new OpenLayers.Control.SelectFeature(poiLayer, {
hover: true,
highlightOnly: true,
eventListeners: {
beforefeaturehighlighted: showQtip,
// featurehighlighted: report
}
});
var features = new Array(0);
features[0] = poi("New York", 40.7143, -74.006);
features[1] = poi("Rio", -22.9028, -43.2075);
features[2] = poi("Tokyo", 35.6724, 139.7724);
features[3] = poi("Sydney", -33.949, 151.18);
features[4] = poi("San Francisco", 37.6188,-122.3749);
poiLayer.addFeatures(features);
map.addLayer(poiLayer);
map.addControl(myControl);
myControl.activate();
};
function poi(item, lat, lon ) {
var fpoint = new OpenLayers.Geometry.Point(lon,lat).transform(
new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
var attributes = {
'name': item,
'longitude': lon,
'latitude': lat
};
var feature = new OpenLayers.Feature.Vector(fpoint, attributes);
feature.id = "POI_" + item;
return feature;
};
function showQtip(olEvent){
var elem = document.getElementById(olEvent.feature.geometry.id);
var msg; // no, get attributes = elem._featureId.substr(4);
var attr = olEvent.feature.attributes;
msg = attr.name;
msg += " at lat "+attr.latitude+", lon "+attr.longitude;
$(elem).qtip({
overwrite: false,
//content: 'haha',
content: msg,
show: {
ready: true
}
})
.qtip('show');
}
function gup2( name, def ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return def;
return results[1];
}
$(document).ready(function() {
var lat = gup2('lat',def_lat);
var lon = gup2('lon',def_lon);
var zoom = gup2('zoom',def_zoom);
initMap(lat,lon,zoom);
});
})()
</script>
</head>
<body>
<div id="basicMap"></div>
</body>
</html>