Commit f1de8360891e7cb1952b9b51897fe58480ebc691

  • avatar
  • arvind
  • Wed Jan 09 21:55:49 IST 2013
Adding features
			 - Annotations are now posted as a (s)tweet.
myVector.js
(49 / 30)
  
11var map, vectorLayer;
22var mapBounds = new OpenLayers.Bounds( 0.0, -4668.0, 31110.0, 0.0);
33var mapMinZoom = 0;
4var mapMaxZoom = 7;
4var mapMaxZoom = 7;
55var boxes;
66var box_extents = [
77 [3759.0000, -1614.33337, 4079.0000, -1274.33337],
1414var ans = {
1515 ans: [],
1616 count: 0
17
17
1818};
19var user;
1920// avoid pink tiles
2021OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
2122OpenLayers.Util.onImageLoadErrorColor = "transparent";
5252 {"jewelery":"Pendant"},
5353 {"Material":"Silver"}
5454 ],
55 "size": "50px X 90px"
55 "size": "50px X 90px"
5656 };
5757 onMyFeatureSelect(map,myjson,3751,-1802)
5858 }
132132 numZoomLevels: 8
133133 };
134134 map = new OpenLayers.Map('map', options);
135 $.get("http://192.168.100.56:82/fetch", function(data){
135 $.get(config.indexer+"/fetch", function(data){
136136 return;
137137 if (data.length != 0)
138138 {
145145
146146 }
147147
148 });
148 });
149149 var layer = new OpenLayers.Layer.TMS( "TMS Layer","",
150150 { url: '', serviceVersion: '.', layername: '.', alpha: true,
151 type: 'png', getURL: overlay_getTileURL
152 });
151 type: 'png', getURL: overlay_getTileURL
152 });
153153 boxes = new OpenLayers.Layer.Vector( "Boxes" );
154154 map.addLayers([layer, boxes]);
155
155
156156 boxes.events.register('featureadded', boxes, myfeatureadded);
157157 box2 = new OpenLayers.Layer.Vector( "Boxes" );
158158 for (var i = 0; i < box_extents.length; i++) {
159159 ext = box_extents[i];
160160 bounds = OpenLayers.Bounds.fromArray(ext);
161
161
162162 box = new OpenLayers.Feature.Vector(bounds.toGeometry());
163163 box2.addFeatures(box);
164164 }
166166 for (var i = 0; i < box_extents1.length; i++) {
167167 ext = box_extents1[i];
168168 bounds = OpenLayers.Bounds.fromArray(ext);
169
169
170170 box = new OpenLayers.Feature.Vector(bounds.toGeometry());
171171 box3.addFeatures(box);
172172 }
173173 map.addLayers([box2, box3]);
174
174
175175 selectControl = new OpenLayers.Control.SelectFeature(box3,
176176 {onSelect: onFeatureSelect});
177
177
178178 drawControls = {
179179 box : new OpenLayers.Control.DrawFeature(boxes,
180180 OpenLayers.Handler.RegularPolygon, {
187187 select: selectControl
188188 };
189189
190 map.zoomToExtent( mapBounds );
190 map.zoomToExtent( mapBounds );
191191 for(var key in drawControls){
192192 map.addControl(drawControls[key]);
193193 }
194194 drawControls['select'].activate();
195195 addLabel('3759.0000','-1274.33337','Face');
196196 addLabel('3719','-1771','Jewelery');
197 addLabel('4263.0000','-1345.33337', 'Video');
197 addLabel('4263.0000','-1345.33337', 'Video');
198198 map.addControl(new OpenLayers.Control.PanZoomBar());
199199 map.addControl(new OpenLayers.Control.MousePosition());
200200 map.addControl(new OpenLayers.Control.MouseDefaults());
207207{
208208 var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
209209 renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
210
210
211211 vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
212212 styleMap: new OpenLayers.StyleMap({'default':{
213213 strokeColor: "#000",
220220 // label with \n linebreaks
221221 label : "${name}\n",
222222//\nage: ${age}",
223
223
224224 fontColor: "#000",
225225 fontSize: "16px",
226226 fontFamily: "Georgia, Serif",
247247}
248248 function makeBoxes(x)
249249{
250
250
251251 bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']);
252252 box = new OpenLayers.Feature.Vector(bounds.toGeometry());
253253 box3.addFeatures(box);
254254 addLabel(x['left'],x['top'],x['name']);
255 }
255 }
256256// function onmouse(data){
257257// console.log(data);
258258// }
260260{
261261 var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
262262 renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
263
263
264264 vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
265265 styleMap: new OpenLayers.StyleMap({'default':{
266266 strokeColor: "#000",
273273 // label with \n linebreaks
274274 label : "${name}\n",
275275//\nage: ${age}",
276
276
277277 fontColor: "#000",
278278 fontSize: "16px",
279279 fontFamily: "Georgia, Serif",
293293 align: 'cm',
294294 favColor: 'blue',
295295 };
296 labelFeature.attributes['name'] = prompt("Enter a name");
296 labelFeature.attributes['name'] = prompt("Enter a label for the annotation..");
297 user = prompt("Enter your name");
297298 if(labelFeature.attributes['name'])
298299 {
299300 topValue = myObj.feature.geometry.bounds.top;
337337 var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
338338 var z = this.map.getZoom();
339339 if (x >= 0 && y >= 0) {
340 return this.url + z + "/" + x + "/" + y + "." + this.type;
340 return this.url + z + "/" + x + "/" + y + "." + this.type;
341341 } else {
342342 return "http://www.maptiler.org/img/none.png";
343343 }
359359 return 0;
360360}
361361
362function resize() {
363 var map = document.getElementById("map");
364 var header = document.getElementById("header");
365 var subheader = document.getElementById("subheader");
362function resize() {
363 var map = document.getElementById("map");
364 var header = document.getElementById("header");
365 var subheader = document.getElementById("subheader");
366366 map.style.height = (getWindowHeight()-180) +"px";
367367 map.style.width = (getWindowWidth()-60) + "px";
368368 //header.style.width = (getWindowWidth()-60) + "px";
369369 subheader.style.width = (getWindowWidth()-60) + "px";
370370 if (map.updateSize) { map.updateSize(); };
371}
371}
372372function allowPan(element) {
373373 var stop = !element.checked;
374374 for(var key in drawControls){
379379onresize=function(){ resize();};
380380function publish()
381381{
382 $.post("http://192.168.100.56:82/submit", JSON.stringify(myJSON), function(data) {
383 $('#posted').show();
384 });
382 if(myJSON.length < 1){
383 return;}
384 for(var i in myJSON){
385 jString = JSON.stringify(myJSON[i]).replace(/\{/g, '').replace(/\}[,]*/g, '').replace(/\[/g, '').replace(/\][,]/g, '').
386 replace(/\"/g, '');
387 myJSON[i].text = ' annotated '+window.location.href+"#[top="+myJSON[i].top+",bottom="+myJSON[i].bottom+",left="+myJSON[i].left+",right="+myJSON[i].right+"] as "+myJSON[i].name+" "+jString+" #swtr"; //The string which gets posted as a tweet.
388 myJSON[i].text = encodeURIComponent(myJSON[i].text);
389 myJSON[i].user = user; // User need not know the modification to the JSON.
390 myJSON[i].title = 'Annotation for '+window.location.href;
391 }
392 $.post(config.indexer+'/submit', JSON.stringify(myJSON),function(){
393 $.post(config.postTweetUrl, {"data":JSON.stringify(myJSON)}, function(data) {
394 $('#posted').show();
395 myJSON = [];
396 });
397 });
398}
399var config = {
400 'postTweetUrl':'http://127.0.0.1:5000/add',
401 'indexer':'http://192.168.100.56:82'
385402}