annotate webapp/src/main/webapp/jquery/jquery.digilib.vector.js @ 1316:6afc572d63be

fixed stupid error.
author robcast
date Thu, 22 Jan 2015 18:49:30 +0100
parents abad8526fa64
children cac657d25ba9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1 /*
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
2 * #%L
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
3 * digilib vector plugin
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
4 * %%
1246
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
5 * Copyright (C) 2014 MPIWG Berlin, Bibliotheca Hertziana
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
6 * %%
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or modify
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
8 * it under the terms of the GNU Lesser General Public License as
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
10 * License, or (at your option) any later version.
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
11 *
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
15 * GNU General Lesser Public License for more details.
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
16 *
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
17 * You should have received a copy of the GNU General Lesser Public
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
18 * License along with this program. If not, see
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
19 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
20 * #L%
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
21 * Authors: Robert Casties, Martin Raspe
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
22 */
1246
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
23
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
24 /**
1246
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
25 * digilib vector plugin.
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
26 *
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
27 * Displays vector shapes on top of the image.
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
28 *
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
29 * Shapes are objects with "geometry" and "properties" members.
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
30 * geometry is an object with "type" and "coordinates" members.
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
31 * Currently supported types: "Point", "Line", "LineString", "Rectangle", "Polygon".
1282
3ffdeb8e209b nicer comments.
robcast
parents: 1267
diff changeset
32 * coordinates is a list of pairs of relative coordinates.
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
33 * properties are the SVG properties "stroke", "stroke-width", "fill" and other properties.
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
34 * A property 'editable':true will display drag-handles to change the shape.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
35 * Editing the shape will send a "changeShape"(shape) event.
1246
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
36 * If a shape has an "id" member its value will be used in SVG.
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
37 *
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
38 * shape = {
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
39 * 'geometry' : {
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
40 * 'type' : 'Line',
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
41 * 'coordinates' : [[0.1, 0.2], [0.3, 0.4]]
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
42 * },
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
43 * 'properties' : {
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
44 * 'stroke' : 'blue',
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
45 * 'editable' : true
1246
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
46 * }
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
47 * }
778c099c6b4c some documentation.
robcast
parents: 1245
diff changeset
48 *
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
49 */
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
50 (function($) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
51
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
52 // affine geometry
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
53 var geom = null;
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
54 // plugin object with digilib data
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
55 var digilib = null;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
56 // SVG namespace
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
57 var svgNS = 'http://www.w3.org/2000/svg';
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
58
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
59 var defaults = {
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
60 // is vector active?
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
61 'isVectorActive' : true,
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
62 // default SVG stroke
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
63 'defaultStroke' : 'red',
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
64 // default SVG stroke-width
1249
20fe79f8f432 vector plugin uses screen coordinates in SVG now.
robcast
parents: 1247
diff changeset
65 'defaultStrokeWidth' : '2',
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
66 // default SVG fill
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
67 'defaultFill' : 'none',
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
68 // grab handle size
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
69 'editHandleSize' : 10
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
70 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
71
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
72 var actions = {
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
73 /**
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
74 * set list of vector objects (shapes).
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
75 *
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
76 * replaces all existing shapes on layer.
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
77 *
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
78 * @param data
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
79 * @param shapes
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
80 * @param layer
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
81 */
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
82 setShapes : function(data, shapes, layer) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
83 if (layer == null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
84 // assume shape layer is 0
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
85 layer = data.vectorLayers[0];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
86 }
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
87 layer.shapes = shapes;
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
88 renderShapes(data);
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
89 },
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
90
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
91 /**
1247
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
92 * add vector object (shape) or create one by clicking.
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
93 *
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
94 * For interactive use shape has to be initialized with a shape object with
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
95 * type but no coordinates, e.g {'geometry':{'type':'Line'}}.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
96 * onComplete(data, newShape) will be called when done.
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
97 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
98 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
99 * @param shape
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
100 * @param onComplete
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
101 * @param layer
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
102 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
103 addShape : function(data, shape, onComplete, layer) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
104 if (layer == null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
105 // assume shape layer is 0
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
106 layer = data.vectorLayers[0];
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
107 }
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
108 if (layer.shapes == null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
109 layer.shapes = [];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
110 }
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
111 if (shape.geometry.coordinates == null) {
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
112 // define shape interactively
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
113 defineShape(data, shape, layer, onComplete);
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
114 } else {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
115 layer.shapes.push(shape);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
116 renderShapes(data, layer);
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
117 }
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
118 },
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
119
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
120 /**
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
121 * get vector object (shape) by id.
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
122 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
123 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
124 * @param id
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
125 * @returns shape
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
126 */
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
127 getShapeById : function(data, id, layer) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
128 if (layer == null) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
129 // assume shape layer is 0
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
130 layer = data.vectorLayers[0];
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
131 }
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
132 var shapes = layer.shapes;
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
133 if (shapes == null) return null;
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
134 for (var i in shapes) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
135 if (shapes[i].id === id) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
136 return shapes[i];
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
137 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
138 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
139 return null;
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
140 },
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
141
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
142 /**
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
143 * remove vector object (shape) by id.
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
144 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
145 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
146 * @param id
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
147 */
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
148 removeShapeById : function(data, id, layer) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
149 if (layer == null) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
150 // assume shape layer is 0
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
151 layer = data.vectorLayers[0];
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
152 }
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
153 var shapes = layer.shapes;
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
154 if (shapes == null) return;
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
155 for (var i in shapes) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
156 if (shapes[i].id === id) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
157 shapes.splice(i, 1);
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
158 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
159 }
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
160 renderShapes(data, layer);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
161 },
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
162
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
163 /**
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
164 * add vector layer.
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
165 *
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
166 * Layer is an object with a "projection" member.
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
167 * projection can be "relative": relative (0..1) coordinates,
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
168 * "screen": on-screen coordinates (needs renderFn(data, layer)).
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
169 * A SVG layer is specified by the jQuery-HTML element "$elem" and the SVG-element "svgElem".
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
170 *
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
171 * layer : {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
172 * projection : relative,
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
173 * $elem : $(...),
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
174 * svgElem : ...
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
175 * }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
176 *
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
177 * @param date
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
178 * @param layer
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
179 */
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
180 addVectorLayer : function (data, layer) {
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
181 if (layer.projection === 'relative') {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
182 var svg = layer.svgElem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
183 // set defaults for SVG in relative coordinates
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
184 svg.setAttributeNS(null, 'viewBox', '0 0 1 1');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
185 svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
186 var $elem = layer.$elem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
187 // set defaults for HTML element
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
188 $elem.css({'position':'absolute', 'z-index': 9, 'pointer-events':'none'});
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
189 $elem.addClass(data.settings.cssPrefix+'overlay');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
190 }
1306
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
191 // add layer
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
192 data.vectorLayers.push(layer);
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
193 renderLayers(data);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
194 }
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
195 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
196
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
197 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
198 * plugin installation routine, called by digilib on each plugin object.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
199 */
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
200 var install = function(plugin) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
201 digilib = plugin;
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
202 console.debug('installing vector plugin. digilib:', digilib);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
203 // import geometry classes
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
204 geom = digilib.fn.geometry;
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
205 // add defaults, actions, buttons to the main digilib object
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
206 $.extend(digilib.defaults, defaults);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
207 $.extend(digilib.actions, actions);
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
208 // export functions
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
209 digilib.fn.vectorDefaultRenderFn = renderShapes;
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
210 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
211
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
212 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
213 * plugin initialization
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
214 */
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
215 var init = function (data) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
216 console.debug('initialising vector plugin. data:', data);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
217 var $data = $(data);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
218 // create default shapes layer
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
219 var shapeLayer = {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
220 'projection': 'screen',
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
221 'renderFn': renderShapes,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
222 'shapes': []
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
223 };
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
224 // shapes layer is first
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
225 data.vectorLayers = [shapeLayer];
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
226 // install event handlers
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
227 $data.bind('update', handleUpdate);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
228 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
229
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
230 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
231 * handle update event
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
232 */
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
233 var handleUpdate = function (evt) {
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
234 console.debug("vector: handleUpdate");
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
235 var data = this;
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
236 if (data.imgTrafo == null || !data.settings.isVectorActive) return;
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
237 if (data.imgTrafo != data._vectorImgTrafo) {
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
238 // imgTrafo changed -- redraw
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
239 renderLayers(data);
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
240 // save new imgTrafo
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
241 data._vectorImgTrafo = data.imgTrafo;
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
242 }
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
243 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
244
1251
0bcc1cd62fc6 start editable shapes.
robcast
parents: 1249
diff changeset
245 /**
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
246 * render all layers on screen
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
247 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
248 var renderLayers = function(data) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
249 if (data.imgRect == null)
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
250 return;
1310
425ce8f971aa less rendering calls.
robcast
parents: 1308
diff changeset
251 for (var i in data.vectorLayers) {
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
252 var layer = data.vectorLayers[i];
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
253 if (layer.projection === 'screen') {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
254 // screen layers have render function
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
255 if (layer.renderFn != null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
256 layer.renderFn(data, layer);
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
257 }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
258 } else if (layer.projection === 'relative') {
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
259 var svg = layer.svgElem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
260 if (svg != null) {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
261 // set current viewBox (jQuery lowercases attributes)
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
262 svg.setAttribute('viewBox', data.zoomArea.getAsSvg());
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
263 }
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
264 var $elem = layer.$elem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
265 if ($elem != null) {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
266 // adjust layer element size and position (doesn't work with .adjustDiv())
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
267 $elem.css(data.imgRect.getAsCss());
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
268 $elem.show();
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
269 }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
270 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
271 }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
272 };
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
273
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
274 /**
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
275 * render all shapes on the layer.
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
276 *
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
277 * @param data
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
278 * @param layer
1251
0bcc1cd62fc6 start editable shapes.
robcast
parents: 1249
diff changeset
279 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
280 var renderShapes = function (data, layer) {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
281 var shapes = layer.shapes || data.shapes;
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
282 console.debug("renderShapes shapes:", shapes);
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
283 if (shapes == null || data.imgTrafo == null || !data.settings.isVectorActive)
1249
20fe79f8f432 vector plugin uses screen coordinates in SVG now.
robcast
parents: 1247
diff changeset
284 return;
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
285 if (layer == null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
286 // assume shape layer is 0
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
287 layer = data.vectorLayers[0];
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
288 }
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
289 var $svg = layer.$elem;
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
290 if ($svg != null) {
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
291 $svg.remove();
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
292 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
293 var svgElem = svgElement('svg', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
294 'viewBox': data.imgRect.getAsSvg(),
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
295 'class': data.settings.cssPrefix+'overlay',
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
296 'style': 'position:absolute; z-index:10; pointer-events:none;'});
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
297 $svg = $(svgElem);
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
298 layer.svgElem = svgElem;
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
299 layer.$elem = $svg;
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
300 for (var i = 0; i < shapes.length; ++i) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
301 var shape = shapes[i];
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
302 renderShape(data, shape, layer);
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
303 }
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
304 data.$elem.append($svg);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
305 // adjust layer element size and position (doesn't work with .adjustDiv())
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
306 $svg.css(data.imgRect.getAsCss());
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
307 $svg.show();
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
308 };
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
309
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
310 /**
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
311 * render a shape on screen.
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
312 *
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
313 * Creates a SVG element and adds it to the layer.
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
314 * Puts a reference $elem in the shape object.
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
315 *
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
316 * @param data
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
317 * @param shape
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
318 * @param layer
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
319 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
320 var renderShape = function (data, shape, layer) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
321 // make sure we have a SVG element
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
322 if (layer.svgElem == null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
323 renderShapes(data, layer);
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
324 return;
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
325 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
326 var $svg = $(layer.svgElem);
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
327 var settings = data.settings;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
328 var css = settings.cssPrefix;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
329 var hs = settings.editHandleSize;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
330 var trafo = data.imgTrafo;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
331 // use given id
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
332 var id = digilib.fn.createId(shape.id, css+'svg-');
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
333 // set properties
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
334 var props = shape.properties || {};
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
335 var stroke = props['stroke'] || settings.defaultStroke;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
336 var strokeWidth = props['stroke-width'] || settings.defaultStrokeWidth;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
337 var fill = props['fill'] || settings.defaultFill;
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
338 var cssclass = props['cssclass'];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
339 var style = props['style'];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
340 var coords = shape.geometry.coordinates;
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
341 var gt = shape.geometry.type;
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
342 if (gt === 'Point') {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
343 /*
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
344 * Point
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
345 */
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
346 var p1 = trafo.transform(geom.position(coords[0]));
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
347 var $elem = $(svgElement('circle', {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
348 'id': id, 'class': cssclass,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
349 'cx': p1.x, 'cy': p1.y,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
350 'r': hs,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
351 'stroke': stroke, 'stroke-width': strokeWidth,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
352 'fill': fill, 'style': style}));
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
353 shape.$elem = $elem;
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
354 $svg.append($elem);
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
355 if (props.editable) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
356 $elem.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 0));
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
357 }
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
358 } else if (gt === 'Line') {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
359 /*
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
360 * Line
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
361 */
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
362 var p1 = trafo.transform(geom.position(coords[0]));
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
363 var p2 = trafo.transform(geom.position(coords[1]));
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
364 var $elem = $(svgElement('line', {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
365 'id': id, 'class': cssclass,
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
366 'x1': p1.x, 'y1': p1.y,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
367 'x2': p2.x, 'y2': p2.y,
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
368 'stroke': stroke, 'stroke-width': strokeWidth, 'style': style}));
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
369 shape.$elem = $elem;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
370 $svg.append($elem);
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
371 if (props.editable) {
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
372 var $e1 = $(svgElement('rect', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
373 'x': p1.x-hs/2, 'y': p1.y-hs/2, 'width': hs, 'height': hs,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
374 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
375 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
376 var $e2 = $(svgElement('rect', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
377 'x': p2.x-hs/2, 'y': p2.y-hs/2, 'width': hs, 'height': hs,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
378 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
379 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
380 var $vertexElems = [$e1, $e2];
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
381 shape.$vertexElems = $vertexElems;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
382 $svg.append($vertexElems);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
383 $e1.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 0));
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
384 $e2.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 1));
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
385 }
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
386 } else if (gt === 'Rectangle') {
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
387 /*
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
388 * Rectangle
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
389 */
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
390 var p1 = trafo.transform(geom.position(coords[0]));
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
391 var p2 = trafo.transform(geom.position(coords[1]));
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
392 var rect = geom.rectangle(p1, p2);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
393 var $elem = $(svgElement('rect', {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
394 'id': id, 'class': cssclass,
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
395 'x': rect.x, 'y': rect.y,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
396 'width': rect.width, 'height': rect.height,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
397 'stroke': stroke, 'stroke-width': strokeWidth,
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
398 'fill': fill, 'style': style}));
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
399 shape.$elem = $elem;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
400 $svg.append($elem);
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
401 if (props.editable) {
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
402 var $e1 = $(svgElement('rect', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
403 'x': p1.x-hs/2, 'y': p1.y-hs/2, 'width': hs, 'height': hs,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
404 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
405 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
406 var $e2 = $(svgElement('rect', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
407 'x': p2.x-hs/2, 'y': p2.y-hs/2, 'width': hs, 'height': hs,
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
408 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
409 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
410 var $vertexElems = [$e1, $e2];
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
411 shape.$vertexElems = $vertexElems;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
412 $svg.append($vertexElems);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
413 $e1.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 0));
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
414 $e2.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 1));
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
415 }
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
416 } else if (gt === 'Polygon') {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
417 /*
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
418 * Polygon
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
419 */
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
420 var ps = [];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
421 for (var i in coords) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
422 ps[i] = trafo.transform(geom.position(coords[i]));
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
423 }
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
424 var $elem = $(svgElement('polygon', {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
425 'id': id, 'class': cssclass,
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
426 'points': ps.join(" "),
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
427 'stroke': stroke, 'stroke-width': strokeWidth,
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
428 'fill': fill, 'style': style}));
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
429 shape.$elem = $elem;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
430 $svg.append($elem);
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
431 if (props.editable) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
432 var $vertexElems = [];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
433 shape.$vertexElems = $vertexElems;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
434 for (var i in ps) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
435 var p = ps[i];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
436 var $vertexElem = $(svgElement('rect', {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
437 'x': p.x-hs/2, 'y': p.y-hs/2, 'width': hs, 'height': hs,
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
438 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
439 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
440 $vertexElems[i] = $vertexElem;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
441 // getVertexDragHandler needs shape.$vertexElems
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
442 $vertexElem.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, i));
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
443 }
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
444 $svg.append($vertexElems);
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
445 }
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
446 } else if (gt === 'LineString') {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
447 /*
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
448 * Polyline
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
449 */
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
450 var ps = [];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
451 for (var i in coords) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
452 ps[i] = trafo.transform(geom.position(coords[i]));
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
453 }
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
454 var $elem = $(svgElement('polyline', {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
455 'id': id, 'class': cssclass,
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
456 'points': ps.join(" "),
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
457 'stroke': stroke, 'stroke-width': strokeWidth,
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
458 'fill': 'none', 'style': style}));
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
459 shape.$elem = $elem;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
460 $svg.append($elem);
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
461 if (props.editable) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
462 var $vertexElems = [];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
463 shape.$vertexElems = $vertexElems;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
464 for (var i in ps) {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
465 var p = ps[i];
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
466 var $vertexElem = $(svgElement('rect', {
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
467 'x': p.x-hs/2, 'y': p.y-hs/2, 'width': hs, 'height': hs,
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
468 'stroke': 'darkgrey', 'stroke-width': 1, 'fill': 'none',
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
469 'class': css+'svg-handle', 'style': 'pointer-events:all'}));
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
470 $vertexElems[i] = $vertexElem;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
471 // getVertexDragHandler needs shape.$vertexElems
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
472 $vertexElem.one('mousedown.dlVertexDrag', getVertexDragHandler(data, shape, i));
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
473 }
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
474 $svg.append($vertexElems);
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
475 }
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
476 } else {
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
477 console.error("Unable to render shape type:", gt);
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
478 return;
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
479 }
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
480 $(data).trigger("renderShape", shape);
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
481 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
482
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
483 /**
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
484 * remove rendered shape from screen.
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
485 *
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
486 * Removes the SVG elements from the layer.
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
487 *
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
488 * @param data
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
489 * @param shape
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
490 */
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
491 var unrenderShape = function (data, shape) {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
492 // remove vertex handles
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
493 if (shape.$vertexElems != null) {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
494 for (var i = 0; i < shape.$vertexElems.length; ++i) {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
495 shape.$vertexElems[i].remove();
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
496 }
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
497 delete shape.$vertexElems;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
498 }
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
499 // remove SVG element
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
500 if (shape.$elem != null) {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
501 shape.$elem.remove();
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
502 delete shape.$elem;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
503 }
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
504 };
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
505
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
506 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
507 * return a vertexDragHandler function.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
508 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
509 * @param data
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
510 * @param shape shape to drag
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
511 * @param vtx vertex number on shape
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
512 * @onComplete function(data, shape)
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
513 */
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
514 var getVertexDragHandler = function (data, shape, vtx, onComplete) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
515 var $document = $(document);
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
516 var hs = data.settings.editHandleSize;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
517 var $shape = shape.$elem;
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
518 var $handle = (shape.$vertexElems != null) ? shape.$vertexElems[vtx] : $();
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
519 var shapeType = shape.geometry.type;
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
520 var imgRect = data.imgRect;
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
521 var pt, pt0, pt1, pt2, rect;
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
522
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
523 var dragStart = function (evt) {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
524 // cancel if not left-click
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
525 if (evt.which != 1) return;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
526 pt0 = geom.position(evt);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
527 if (shapeType === 'Rectangle') {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
528 // save rectangle screen endpoints
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
529 pt1 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[0]));
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
530 pt2 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[1]));
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
531 }
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
532 $document.on("mousemove.dlVertexDrag", dragMove);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
533 $document.on("mouseup.dlVertexDrag", dragEnd);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
534 $document.on("dblclick.dlVertexDrag", dragEnd);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
535 return false;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
536 };
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
537
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
538 var dragMove = function (evt) {
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
539 pt = geom.position(evt);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
540 pt.clipTo(imgRect);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
541 // move handle
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
542 $handle.attr({'x': pt.x-hs/2, 'y': pt.y-hs/2});
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
543 // update shape SVG element
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
544 if (shapeType === 'Line') {
1262
2a46542cd05a fix bug in vector plugin.
robcast
parents: 1261
diff changeset
545 if (vtx == 0) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
546 $shape.attr({'x1': pt.x, 'y1': pt.y});
1262
2a46542cd05a fix bug in vector plugin.
robcast
parents: 1261
diff changeset
547 } else if (vtx == 1) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
548 $shape.attr({'x2': pt.x, 'y2': pt.y});
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
549 }
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
550 } else if (shapeType === 'Rectangle') {
1262
2a46542cd05a fix bug in vector plugin.
robcast
parents: 1261
diff changeset
551 if (vtx == 0) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
552 rect = geom.rectangle(pt, pt2);
1262
2a46542cd05a fix bug in vector plugin.
robcast
parents: 1261
diff changeset
553 } else if (vtx == 1) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
554 rect = geom.rectangle(pt1, pt);
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
555 }
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
556 $shape.attr({'x': rect.x, 'y': rect.y,
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
557 'width': rect.width, 'height': rect.height});
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
558 } else if (shapeType === 'Polygon' || shapeType === 'LineString') {
1267
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
559 var points = $shape.attr('points');
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
560 var ps = points.split(' ');
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
561 ps[vtx] = pt.x + ',' + pt.y;
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
562 points = ps.join(' ');
9c09ab5b46ec added Polygon and LineString aka polylline shape rendering. no creation yet.
robcast
parents: 1266
diff changeset
563 $shape.attr('points', points);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
564 }
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
565 return false;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
566 };
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
567
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
568 var dragEnd = function (evt) {
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
569 pt = geom.position(evt);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
570 if ((pt.distance(pt0) < 5) && evt.type === 'mouseup') {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
571 // not drag but click to start
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
572 return false;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
573 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
574 pt.clipTo(imgRect);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
575 var p1 = data.imgTrafo.invtransform(pt);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
576 // update shape object
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
577 if (shapeType === 'Line' || shapeType === 'Rectangle' ||
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
578 shapeType === 'Polygon' || shapeType === 'LineString') {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
579 shape.geometry.coordinates[vtx] = [p1.x, p1.y];
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
580 }
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
581 // remove move/end handler
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
582 $document.off("mousemove.dlVertexDrag", dragMove);
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
583 $document.off("mouseup.dlVertexDrag", dragEnd);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
584 $document.off("dblclick.dlVertexDrag", dragEnd);
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
585 // rearm start handler
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
586 $handle.one("mousedown.dlVertexDrag", dragStart);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
587 if (onComplete != null) {
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
588 onComplete(data, shape, evt);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
589 } else {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
590 $(data).trigger('changeShape', shape);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
591 }
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
592 return false;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
593 };
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
594
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
595 // return drag start handler
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
596 return dragStart;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
597 };
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
598
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
599 /**
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
600 * define a shape by click and drag.
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
601 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
602 * The given shape object has to have a type, but its coordinates will be overwritten.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
603 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
604 * @param data
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
605 * @param shape the shape to define
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
606 * @param layer the layer to draw on
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
607 * @onComplete function(data, shape)
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
608 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
609 var defineShape = function(data, shape, layer, onComplete) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
610 if (layer == null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
611 // assume shape layer is 0
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
612 layer = data.vectorLayers[0];
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
613 }
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
614 var shapeType = shape.geometry.type;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
615 var $elem = data.$elem;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
616 var $body = $('body');
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
617 var bodyRect = geom.rectangle($body);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
618 // overlay div prevents other elements from reacting to mouse events
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
619 var $overlayDiv = $('<div class="'+data.settings.cssPrefix+'shapeOverlay" style="position:absolute; z-index:100;"/>');
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
620 $elem.append($overlayDiv);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
621 bodyRect.adjustDiv($overlayDiv);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
622
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
623 var shapeStart = function (evt) {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
624 var pt = geom.position(evt);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
625 // setup shape
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
626 var p = data.imgTrafo.invtransform(pt);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
627 var vtxidx = 1;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
628 if (shapeType === 'Line' || shapeType === 'Rectangle' ||
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
629 shapeType === 'LineString' || shapeType === 'Polygon') {
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
630 shape.geometry.coordinates = [[p.x, p.y], [p.x, p.y]];
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
631 } else {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
632 console.error("unsupported shape type: "+shapeType);
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
633 $overlayDiv.remove();
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
634 return false;
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
635 }
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
636 // save editable state and set to non-editable
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
637 var isShapeEditable = false;
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
638 if (shape.properties != null) {
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
639 isShapeEditable = shape.properties.editable;
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
640 shape.properties.editable = false;
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
641 } else {
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
642 shape.properties = {'editable' : false};
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
643 }
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
644 // draw shape
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
645 renderShape(data, shape, layer);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
646 // vertex drag end handler
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
647 var vertexDragDone = function (data, newshape, newevt) {
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
648 var coords = newshape.geometry.coordinates;
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
649 if (shapeType === 'LineString' || shapeType === 'Polygon') {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
650 if (newevt.type === 'mouseup') {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
651 // single click adds line to LineString/Polygon
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
652 unrenderShape(data, newshape);
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
653 // copy last vertex as starting point
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
654 coords.push(coords[vtxidx].slice());
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
655 vtxidx += 1;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
656 // draw shape
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
657 renderShape(data, newshape, layer);
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
658 // execute vertex drag handler on next vertex
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
659 getVertexDragHandler(data, newshape, vtxidx, vertexDragDone)(newevt);
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
660 return false;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
661 } else if (newevt.type === 'dblclick') {
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
662 // double click ends Linestring/Polygon
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
663 if (coords[vtxidx][0] === coords[vtxidx-1][0] &&
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
664 coords[vtxidx][1] === coords[vtxidx-1][1]) {
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
665 unrenderShape(data, newshape);
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
666 // remove duplicate last vertex (from mouseup)
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
667 coords.pop();
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
668 renderShape(data, newshape, layer);
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
669 }
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
670 } else {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
671 console.error("unknown event type!");
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
672 return false;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
673 }
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
674 }
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
675 // dragging vertex done
1316
6afc572d63be fixed stupid error.
robcast
parents: 1315
diff changeset
676 if (shape.properties.editable !== isShapeEditable) {
1315
abad8526fa64 optimized number of renderings in defineShape.
robcast
parents: 1312
diff changeset
677 // re-set editable
abad8526fa64 optimized number of renderings in defineShape.
robcast
parents: 1312
diff changeset
678 unrenderShape(data, newshape);
abad8526fa64 optimized number of renderings in defineShape.
robcast
parents: 1312
diff changeset
679 shape.properties.editable = isShapeEditable;
abad8526fa64 optimized number of renderings in defineShape.
robcast
parents: 1312
diff changeset
680 renderShape(data, newshape, layer);
abad8526fa64 optimized number of renderings in defineShape.
robcast
parents: 1312
diff changeset
681 }
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
682 // save shape
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
683 layer.shapes.push(newshape);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
684 $overlayDiv.remove();
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
685 if (onComplete != null) {
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
686 onComplete(data, newshape);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
687 }
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
688 };
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
689 // execute vertex drag handler on second vertex
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
690 getVertexDragHandler(data, shape, vtxidx, vertexDragDone)(evt);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
691 return false;
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
692 };
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
693
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
694 // start by clicking
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
695 $overlayDiv.one('mousedown.dlShape', shapeStart);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
696 };
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
697
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
698 /**
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
699 * create a SVG element with attributes.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
700 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
701 * @param name tag name
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
702 * @param attrs object with attributes
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
703 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
704 var svgElement = function (name, attrs) {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
705 var elem = document.createElementNS(svgNS, name);
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
706 if (attrs != null) {
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
707 for (var att in attrs) {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
708 if (attrs[att] != null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
709 elem.setAttributeNS(null, att, attrs[att]);
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
710 }
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
711 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
712 }
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
713 return elem;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
714 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
715
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
716 // plugin object, containing name, install and init routines
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
717 // all shared objects are filled by digilib on registration
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
718 var plugin = {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
719 name : 'vector',
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
720 install : install,
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
721 init : init,
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
722 buttons : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
723 actions : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
724 fn : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
725 plugins : {}
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
726 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
727
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
728 if ($.fn.digilib == null) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
729 $.error("jquery.digilib.vector.js must be loaded after jquery.digilib!");
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
730 } else {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
731 $.fn.digilib('plugin', plugin);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
732 }
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
733 })(jQuery);