annotate webapp/src/main/webapp/jquery/jquery.digilib.vector.js @ 1610:f425f00bf5e3 geom_prototype

changed digilib.geometry to use new and prototypes instead of adding methods to objects.
author robcast
date Sun, 12 Mar 2017 15:53:01 +0100
parents f322ac84adf7
children
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.
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
31 * Currently supported types: "Point", "Line", "LineString", "Rectangle", "Polygon", "Circle".
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 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
50 (function ($) {
1238
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';
1338
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
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
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
69 'editHandleSize' : 10,
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
70 // handle type (square, diamond, circle, cross)
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
71 'editHandleType' : 'square',
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
72 // add or remove polygon points?
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
73 'editPolygonPoints' : true
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
74 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
75
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
76 var actions = {
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
77 /**
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
78 * set list of vector objects (shapes).
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
79 *
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
80 * replaces all existing shapes on layer.
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
81 *
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
82 * @param data
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
83 * @param shapes
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
84 * @param layer
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
85 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
86 setShapes : function (data, shapes, layer) {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
87 if (layer == null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
88 // assume shape layer is 0
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
89 layer = data.vectorLayers[0];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
90 }
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
91 layer.shapes = shapes;
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
92 renderShapes(data);
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
93 },
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
94
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
95 /**
1247
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
96 * add vector object (shape) or create one by clicking.
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
97 *
032dfc2515e9 more doc.
robcast
parents: 1246
diff changeset
98 * For interactive use shape has to be initialized with a shape object with
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
99 * type but no coordinates, e.g {'geometry':{'type':'Line'}}.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
100 * onComplete(data, newShape) will be called when done.
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
101 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
102 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
103 * @param shape
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
104 * @param onComplete
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
105 * @param layer
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
106 */
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
107 addShape : function (data, shape, layer, onComplete) {
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
108 if (layer == null) {
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
109 // assume shape layer is 0
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
110 layer = data.vectorLayers[0];
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
111 }
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
112 if (layer.shapes == null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
113 layer.shapes = [];
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
114 }
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
115 if (shape.geometry == null) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
116 shape.geometry = {};
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
117 }
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
118 if (shape.geometry.coordinates == null) {
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
119 // define shape interactively
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
120 defineShape(data, shape, layer, onComplete);
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
121 console.debug('addShape', shape);
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
122 } else {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
123 layer.shapes.push(shape);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
124 renderShapes(data, layer);
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
125 }
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
126 },
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
127
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
128 /**
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
129 * get vector object (shape) by id.
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
130 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
131 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
132 * @param id
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
133 * @returns shape
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
134 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
135 getShapeById : function (data, id, layer) {
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
136 if (layer == null) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
137 // assume shape layer is 0
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
138 layer = data.vectorLayers[0];
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
139 }
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
140 var shapes = layer.shapes;
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
141 if (shapes == null) return null;
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
142 for (var i in shapes) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
143 if (shapes[i].id === id) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
144 return shapes[i];
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
145 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
146 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
147 return null;
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
148 },
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
149
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
150 /**
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
151 * remove vector object (shape) by id.
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
152 *
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
153 * @param data
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
154 * @param id
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
155 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
156 removeShapeById : function (data, id, layer) {
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
157 if (layer == null) {
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
158 // assume shape layer is 0
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
159 layer = data.vectorLayers[0];
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
160 }
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
161 var shapes = layer.shapes;
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
162 if (shapes == null) return;
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
163 for (var i = 0; i < shapes.length; ++i) {
1241
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
164 if (shapes[i].id === id) {
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
165 shapes.splice(i, 1);
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
166 }
34c68ecef8cf more vectors.
robcast
parents: 1239
diff changeset
167 }
1308
75db880828a1 move annotation creation in its own function.
robcast
parents: 1306
diff changeset
168 renderShapes(data, layer);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
169 },
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
170
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
171 /**
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
172 * add vector layer.
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
173 *
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
174 * Layer is an object with a "projection" member.
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
175 * projection can be "relative": relative (0..1) coordinates,
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
176 * "screen": on-screen coordinates (needs renderFn(data, layer)).
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
177 * 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
178 *
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
179 * layer : {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
180 * projection : relative,
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
181 * $elem : $(...),
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
182 * svgElem : ...
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
183 * }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
184 *
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
185 * @param date
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
186 * @param layer
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
187 */
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
188 addVectorLayer : function (data, layer) {
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
189 if (layer.projection === 'relative') {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
190 var svg = layer.svgElem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
191 // set defaults for SVG in relative coordinates
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
192 svg.setAttributeNS(null, 'viewBox', '0 0 1 1');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
193 svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
194 var $elem = layer.$elem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
195 // set defaults for HTML element
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
196 $elem.css({'position':'absolute', 'z-index': 9, 'pointer-events':'none'});
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
197 $elem.addClass(data.settings.cssPrefix+'overlay');
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
198 }
1306
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
199 // add layer
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
200 data.vectorLayers.push(layer);
927a3ebf9d6e annotator uses its own vector layer now.
robcast
parents: 1304
diff changeset
201 renderLayers(data);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
202 }
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
203 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
204
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
205 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
206 * plugin installation routine, called by digilib on each plugin object.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
207 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
208 var install = function (plugin) {
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
209 digilib = plugin;
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
210 console.debug('installing vector plugin. digilib:', digilib);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
211 // import geometry classes
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
212 geom = digilib.fn.geometry;
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
213 // add defaults, actions, buttons to the main digilib object
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
214 $.extend(digilib.defaults, defaults);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
215 $.extend(digilib.actions, actions);
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
216 // export functions
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
217 $.extend(digilib.fn, {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
218 vectorDefaultRenderFn: renderShapes,
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
219 svgElement: svgElement,
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
220 svgAttr: svgAttr,
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
221 createScreenCoords: createScreenCoords,
1584
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
222 startShapeEdit: startShapeEdit,
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
223 undoShapeEdit: undoShapeEdit,
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
224 finishShapeEdit: finishShapeEdit,
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
225 redrawShape: redrawShape
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
226 });
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
227 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
228
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
229 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
230 * plugin initialization
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
231 */
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
232 var init = function (data) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
233 console.debug('initialising vector plugin. data:', data);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
234 var $data = $(data);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
235 // create default shapes layer
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
236 var shapeLayer = {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
237 'projection': 'screen',
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
238 'renderFn': renderShapes,
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
239 'shapes': []
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
240 };
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
241 // shapes layer is first
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
242 data.vectorLayers = [shapeLayer];
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
243 // pluggable SVG create functions
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
244 data.shapeFactory = getShapeFactory(data);
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
245 setupHandleFactory(data);
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
246 // install event handlers
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
247 $data.bind('update', handleUpdate);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
248 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
249
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
250 /**
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
251 * handle update event
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
252 */
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
253 var handleUpdate = function (evt) {
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
254 console.debug("vector: handleUpdate");
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
255 var data = this;
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
256 if (data.imgTrafo == null || !data.settings.isVectorActive) return;
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
257 if (data.imgTrafo != data._vectorImgTrafo) {
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
258 // imgTrafo changed -- redraw
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
259 renderLayers(data);
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
260 // save new imgTrafo
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
261 data._vectorImgTrafo = data.imgTrafo;
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
262 }
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
263 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
264
1251
0bcc1cd62fc6 start editable shapes.
robcast
parents: 1249
diff changeset
265 /**
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
266 * render all layers on screen
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
267 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
268 var renderLayers = function (data) {
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
269 if (data.imgRect == null)
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
270 return;
1310
425ce8f971aa less rendering calls.
robcast
parents: 1308
diff changeset
271 for (var i in data.vectorLayers) {
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
272 var layer = data.vectorLayers[i];
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
273 if (layer.projection === 'screen') {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
274 // screen layers have render function
1361
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
275 if (layer.renderFn == null) {
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
276 // user renderShapes as default
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
277 layer.renderFn = renderShapes;
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
278 }
1361
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
279 layer.renderFn(data, layer);
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
280 } else if (layer.projection === 'relative') {
1265
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
281 var svg = layer.svgElem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
282 if (svg != null) {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
283 // set current viewBox (jQuery lowercases attributes)
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
284 svg.setAttribute('viewBox', data.zoomArea.getAsSvg());
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
285 }
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
286 var $elem = layer.$elem;
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
287 if ($elem != null) {
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
288 // 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
289 $elem.css(data.imgRect.getAsCss());
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
290 $elem.show();
cc1decb4c941 loading additional (relative coordinate) SVG layers works now.
robcast
parents: 1263
diff changeset
291 }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
292 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
293 }
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
294 };
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
295
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
296 /**
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
297 * render all shapes on the layer.
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
298 *
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
299 * @param data
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
300 * @param layer
1251
0bcc1cd62fc6 start editable shapes.
robcast
parents: 1249
diff changeset
301 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
302 var renderShapes = function (data, layer) {
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
303 if (layer == null) {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
304 // assume shape layer is 0
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
305 layer = data.vectorLayers[0];
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
306 }
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
307 var shapes = layer.shapes || data.shapes;
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
308 if (shapes == null || data.imgTrafo == null || !data.settings.isVectorActive)
1249
20fe79f8f432 vector plugin uses screen coordinates in SVG now.
robcast
parents: 1247
diff changeset
309 return;
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
310 // set up shapes
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
311 for (var i = 0; i < shapes.length; ++i) {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
312 var shape = shapes[i];
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
313 data.shapeFactory[shape.geometry.type].setup(data, shape);
1546
fb4cb912dd51 debug output too noisy
hertzhaft
parents: 1545
diff changeset
314 // console.debug('render', shape);
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
315 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
316 // sort shapes by size descending
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
317 shapes.sort(function (a, b) {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
318 return (b.properties.sorta - a.properties.sorta);
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
319 });
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
320 // set up SVG
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
321 var $svg = layer.$elem;
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
322 if ($svg != null) {
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
323 $svg.remove();
1244
8cb0faad875a interactive creation of vector lines and rectangles.
robcast
parents: 1241
diff changeset
324 }
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
325 var svgElem = svgElement('svg', {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
326 'viewBox': data.imgRect.getAsSvg(),
1261
9859f582b3ed new addVectorLayer action.
robcast
parents: 1260
diff changeset
327 'class': data.settings.cssPrefix+'overlay',
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
328 'style': 'position:absolute; z-index:10; pointer-events:none;'});
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
329 $svg = $(svgElem);
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
330 layer.svgElem = svgElem;
1347
668a62a873b2 store screen positions on drag; trigger positionShape event
hertzhaft
parents: 1344
diff changeset
331 layer.$elem = $svg;
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
332 for (var i = 0; i < shapes.length; ++i) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
333 var shape = shapes[i];
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
334 renderShape(data, shape, layer);
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
335 }
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
336 data.$elem.append($svg);
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
337 // 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
338 $svg.css(data.imgRect.getAsCss());
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
339 $svg.show();
1239
ffe4de6896b0 vector plugin has setShapes action now.
robcast
parents: 1238
diff changeset
340 };
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
341
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
342 /**
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
343 * set standard SVG attributes
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
344 *
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
345 * @param data
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
346 */
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
347 var svgAttr = function (data, shape) {
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
348 var settings = data.settings;
1545
9dc9042cea47 overlooked css variable definition
hertzhaft
parents: 1544
diff changeset
349 var css = settings.cssPrefix;
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
350 var props = shape.properties;
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
351 return {
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
352 'id': shape.id || digilib.fn.createId(shape.id, css+'svg-'),
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
353 'stroke': props['stroke'] || settings.defaultStroke,
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
354 'stroke-width' : props['stroke-width'] || settings.defaultStrokeWidth,
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
355 'fill' : props['fill'] || settings.defaultFill,
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
356 'class' : props['cssclass'],
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
357 'style' : props['style']
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
358 };
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
359 };
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
360 /**
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
361 * setup Shape SVG creation functions
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
362 * (more functions can be plugged into data.settings.ShapeFactory)
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
363 *
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
364 * @param data
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
365 */
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
366 var getShapeFactory = function (data) {
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
367 var settings = data.settings;
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
368 var hs = settings.editHandleSize;
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
369 var factory = {
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
370 'Point' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
371 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
372 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
373 shape.properties.maxvtx = 1;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
374 shape.properties.sorta = 0;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
375 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
376 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
377 var $s = $(svgElement('path', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
378 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
379 // point uses pin-like path of size 3*pu
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
380 var p = shape.properties.screenpos[0];
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
381 var pu = hs / 3;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
382 this.attr({'d': 'M '+p.x+','+p.y+' l '+2*pu+','+pu+' c '+2*pu+','+pu+' '+0+','+3*pu+' '+(-pu)+','+pu+' Z'});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
383 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
384 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
385 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
386 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
387 'Line' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
388 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
389 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
390 shape.properties.maxvtx = 2;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
391 shape.properties.bbox = getBboxRect(data, shape);
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
392 shape.properties.sorta = 0;
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
393 },
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
394 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
395 var $s = $(svgElement('line', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
396 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
397 var p = shape.properties.screenpos;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
398 this.attr({'x1': p[0].x, 'y1': p[0].y, 'x2': p[1].x, 'y2': p[1].y});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
399 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
400 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
401 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
402 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
403 'Rectangle' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
404 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
405 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
406 shape.properties.maxvtx = 2;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
407 shape.properties.bbox = getBboxRect(data, shape);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
408 if (shape.properties.bbox != null) {
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
409 shape.properties.sorta = shape.properties.bbox.getArea();
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
410 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
411 },
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
412 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
413 var $s = $(svgElement('rect', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
414 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
415 var p = shape.properties.screenpos;
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
416 var r = new geom.Rectangle(p[0], p[1]);
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
417 this.attr({'x': r.x, 'y': r.y, 'width': r.width, 'height': r.height});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
418 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
419 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
420 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
421 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
422 'Polygon' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
423 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
424 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
425 shape.properties.bbox = getBboxRect(data, shape);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
426 if (shape.properties.bbox != null) {
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
427 shape.properties.sorta = shape.properties.bbox.getArea();
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
428 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
429 },
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
430 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
431 var $s = $(svgElement('polygon', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
432 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
433 var p = shape.properties.screenpos;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
434 this.attr({'points': p.join(" ")});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
435 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
436 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
437 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
438 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
439 'LineString' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
440 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
441 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
442 shape.properties.bbox = getBboxRect(data, shape);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
443 if (shape.properties.bbox != null) {
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
444 shape.properties.sorta = shape.properties.bbox.getArea();
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
445 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
446 },
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
447 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
448 var $s = $(svgElement('polyline', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
449 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
450 var p = shape.properties.screenpos;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
451 this.attr({'points': p.join(" ")});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
452 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
453 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
454 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
455 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
456 'Circle' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
457 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
458 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
459 shape.properties.maxvtx = 2;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
460 // TODO: bbox not really accurate
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
461 shape.properties.bbox = getBboxRect(data, shape);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
462 if (shape.properties.bbox != null) {
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
463 shape.properties.sorta = shape.properties.bbox.getArea();
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
464 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
465 },
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
466 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
467 var $s = $(svgElement('circle', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
468 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
469 var p = shape.properties.screenpos;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
470 this.attr({'cx': p[0].x, 'cy': p[0].y, 'r': p[0].distance(p[1])});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
471 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
472 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
473 }
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
474 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
475 'Ellipse' : {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
476 'setup' : function (data, shape) {
1390
c7fb7b895e95 fix bug with not-initialised shape.properties.
robcast
parents: 1387
diff changeset
477 if (shape.properties == null) shape.properties = {};
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
478 shape.properties.maxvtx = 2;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
479 // TODO: bbox not really accurate
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
480 shape.properties.bbox = getBboxRect(data, shape);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
481 if (shape.properties.bbox != null) {
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
482 shape.properties.sorta = shape.properties.bbox.getArea();
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
483 }
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
484 },
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
485 'svg' : function (shape) {
1544
020739227ffd measure plugin: define the event interactor element for composite svg elements
hertzhaft
parents: 1538
diff changeset
486 var $s = $(svgElement('ellipse', svgAttr(data, shape)));
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
487 $s.place = function () {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
488 var p = shape.properties.screenpos;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
489 this.attr({'cx': p[0].x, 'cy': p[0].y,
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
490 'rx' : Math.abs(p[0].x - p[1].x),
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
491 'ry' : Math.abs(p[0].y - p[1].y)});
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
492 };
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
493 return $s;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
494 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
495 }
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
496 };
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
497
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
498 return factory;
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
499 };
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
500
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
501 /**
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
502 * setup handle creation functions
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
503 * (more functions can be plugged into data.settings.handleFactory)
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
504 *
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
505 * @param data
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
506 */
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
507 var setupHandleFactory = function (data) {
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
508 var settings = data.settings;
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
509 var css = settings.cssPrefix;
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
510 var hs = settings.editHandleSize;
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
511 var d = hs/2;
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
512 var attr = {
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
513 'stroke': 'darkgrey',
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
514 'stroke-width': 1,
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
515 'fill': 'none',
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
516 'class': css+'svg-handle',
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
517 'style': 'pointer-events:all'
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
518 };
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
519 var factory = {
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
520 'square' : function () {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
521 var $h = $(svgElement('rect', attr));
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
522 $h.attr({'width': hs, 'height': hs});
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
523 $h.moveTo = function (p) {
1537
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
524 this.attr({'x': p.x-d, 'y': p.y-d});
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
525 };
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
526 return $h;
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
527 },
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
528 'circle' : function () {
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
529 var $h = $(svgElement('circle', attr));
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
530 $h.moveTo = function (p) {
dc63c24c59be vector plugin: new handle type (circle)
hertzhaft
parents: 1390
diff changeset
531 this.attr({'cx': p.x, 'cy': p.y, 'r': d});
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
532 };
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
533 return $h;
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
534 },
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
535 'diamond' : function () {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
536 var $h = $(svgElement('polygon', attr));
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
537 $h.moveTo = function (p) {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
538 this.attr('points', (p.x-d) +','+ p.y+ ' '+p.x +','+(p.y+d)+' '+(p.x+d)+','+p.y+' '+p.x+','+(p.y-d));
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
539 };
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
540 return $h;
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
541 },
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
542 'cross' : function () {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
543 var $h = $(svgElement('path', attr));
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
544 $h.moveTo = function (p) {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
545 this.attr('d', 'M'+(p.x-d) +','+ p.y+ ' L'+(p.x+d)+','+p.y+' M'+p.x+','+(p.y+d)+' L'+p.x+','+(p.y-d));
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
546 };
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
547 return $h;
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
548 }
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
549 };
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
550 data.handleFactory = factory;
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
551 };
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
552
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
553 /**
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
554 * add adjustment handles to a shape.
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
555 *
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
556 * Creates a SVG element for each screen point and append them to the SVG element.
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
557 *
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
558 * @param data
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
559 * @param shape
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
560 * @param layer
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
561 */
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
562 var addEditHandles = function (data, shape, layer) {
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
563 var $svg = $(layer.svgElem);
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
564 var trafo = data.imgTrafo;
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
565 // type of handle can be stated in layer or in settings
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
566 var type = layer.handleType || data.settings.editHandleType;
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
567 var handles = [];
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
568 var createHandle = data.handleFactory[type];
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
569 var insertHandle = function (i, item) {
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
570 var p = trafo.transform(new geom.Position(item));
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
571 var $handle = createHandle();
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
572 $handle.data('vertex', i);
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
573 $handle.moveTo(p);
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
574 handles.push($handle);
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
575 $svg.append($handle);
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
576 return $handle;
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
577 };
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
578 $.each(shape.geometry.coordinates, insertHandle);
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
579 shape.$vertexElems = handles;
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
580 // not needed?
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
581 var done = function (data, shape, evt) {
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
582 redrawShape(data, shape, layer);
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
583 };
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
584 // vertexElems must be defined before calling getVertexDragHandler()
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
585 var attachEvent = function (i, item) {
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
586 item.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, i, done));
1354
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
587 };
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
588 $.each(handles, attachEvent);
1712eef019e3 pluggable handle types
hertzhaft
parents: 1353
diff changeset
589 };
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
590
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
591 /**
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
592 * remove SVG adjustment handles from a shape.
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
593 *
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
594 * @param data
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
595 * @param shape
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
596 */
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
597 var removeEditHandles = function (data, shape) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
598 // remove vertex handles
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
599 if (shape.$vertexElems != null) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
600 for (var i = 0; i < shape.$vertexElems.length; ++i) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
601 shape.$vertexElems[i].remove();
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
602 }
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
603 delete shape.$vertexElems;
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
604 }
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
605 };
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
606
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
607 /**
1582
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
608 * make shape editable, add handles and events
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
609 *
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
610 * @param data
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
611 * @param shape
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
612 */
1584
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
613 var startShapeEdit = function (data, shape) {
1582
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
614 shape.properties.editable = true;
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
615 shape.savecoords = shape.geometry.coordinates.slice(0); // clone coords
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
616 redrawShape(data, shape);
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
617 };
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
618
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
619 /**
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
620 * end editing shape
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
621 *
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
622 * @param data
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
623 * @param shape
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
624 */
1584
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
625 var finishShapeEdit = function (data, shape) {
1582
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
626 shape.properties.editable = false;
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
627 redrawShape(data, shape);
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
628 };
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
629
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
630 /**
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
631 * restore edited shape to previous state
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
632 *
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
633 * @param data
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
634 * @param shape
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
635 */
1584
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
636 var undoShapeEdit = function (data, shape) {
1582
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
637 shape.geometry.coordinates = shape.savecoords;
1584
817a5c42cb1b annotator plugin: render annotations only on store event, include annotation data created on storage (e.g. id)
hertzhaft
parents: 1582
diff changeset
638 finishShapeEdit(data, shape);
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
639 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
640
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
641 /**
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
642 * shape has a polygon type
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
643 *
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
644 * @param shape
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
645 */
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
646 var hasPolygonType = function (shape) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
647 var type = shape.geometry.type;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
648 return (type === 'Polygon' || type === 'LineString');
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
649 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
650
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
651 /**
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
652 * activate polygon edit (add/remove points)
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
653 *
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
654 * @param data
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
655 * @param shape
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
656 */
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
657 var enablePolygonEdit = function (data, shape) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
658 var $w = polygonPointWidget(data);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
659 var onHandleMouseDown = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
660 $w.fadeOut();
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
661 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
662 var onHandleMouseLeave = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
663 $w.data.timer = setTimeout(onHandleMouseDown, 500);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
664 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
665 var onHandleMouseEnter = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
666 $w.data({ vertex: $(this).data('vertex'), shape: shape, timer: false });
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
667 $w.fadeIn().offset({
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
668 left : event.pageX + 5,
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
669 top : event.pageY + 5
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
670 });
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
671 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
672 var addEventsToHandle = function(i, $handle) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
673 $handle
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
674 .on('mouseenter.handle', onHandleMouseEnter)
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
675 .on('mouseleave.handle', onHandleMouseLeave)
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
676 .on('mousedown.handle', onHandleMouseDown);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
677 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
678 $.each(shape.$vertexElems, addEventsToHandle);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
679 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
680
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
681 /**
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
682 * deactivate polygon edit (add/remove points)
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
683 *
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
684 * @param data
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
685 * @param shape
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
686 */
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
687 var disablePolygonEdit = function (data) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
688 var $w = data.$polygonPointWidget;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
689 if ($w == null) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
690 return;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
691 }
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
692 $w.data({ vertex: null, shape: null, timer: false });
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
693 $w.fadeOut();
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
694 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
695
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
696 /**
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
697 * create HTML div to add/remove polygon points
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
698 *
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
699 * @param data
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
700 */
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
701 var polygonPointWidget = function (data) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
702 var css = data.settings.cssPrefix;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
703 var $w = data.$polygonPointWidget;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
704 if ($w == null) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
705 // setup html
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
706 var html = '\
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
707 <div id="'+css+'polygonPointWidget">\
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
708 <div id="'+css+'iconplus"><div class="icon plus" /></div>\
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
709 <div id="'+css+'iconminus"><div class="icon minus" /></div>\
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
710 </div>';
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
711 $w = $(html);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
712 $w.appendTo(data.$elem);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
713 // setup mouse bindings
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
714 var onPlusClick = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
715 var vertex = $w.data('vertex');
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
716 var shape = $w.data('shape');
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
717 var coords = shape.geometry.coordinates;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
718 var v1 = parseInt(vertex) > 0 ? vertex-1 : coords.length-1;
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
719 var pt = new geom.Position(coords[vertex]).mid(new geom.Position(coords[v1]));
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
720 console.debug('+ point', coords[vertex], pt);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
721 coords.splice(vertex, 0, pt);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
722 redrawShape(data, shape);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
723 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
724 var onMinusClick = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
725 var vertex = $w.data('vertex');
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
726 var shape = $w.data('shape');
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
727 var coords = shape.geometry.coordinates;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
728 if (vertex == null || coords.length < 4) { return; }
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
729 console.debug('- point', coords[vertex]);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
730 coords.splice(vertex, 1);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
731 redrawShape(data, shape);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
732 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
733 var onEnter = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
734 clearTimeout($w.data.timer);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
735 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
736 var onLeave = function (event) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
737 $w.fadeOut();
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
738 };
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
739 var $plus = $w.children().first();
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
740 var $minus = $w.children().last();
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
741 $plus.on('click', onPlusClick);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
742 $minus.on('click', onMinusClick);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
743 $w.on('mouseenter', onEnter).on('mouseleave', onLeave);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
744 data.$polygonPointWidget = $w;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
745 }
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
746 return $w;
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
747 };
1582
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
748
14a6d8a8a307 vector plugin: make a shape editable
hertzhaft
parents: 1556
diff changeset
749 /**
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
750 * calculate screen positions from coordinates for a shape.
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
751 *
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
752 * @param data
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
753 * @param shape
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
754 */
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
755 var createScreenCoords = function (data, shape) {
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
756 var coords = shape.geometry.coordinates;
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
757 var trafo = data.imgTrafo;
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
758 var screenpos = $.map(coords, function (coord) {
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
759 return trafo.transform(new geom.Position(coord));
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
760 });
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
761 if (shape.properties == null) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
762 shape.properties = {};
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
763 }
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
764 shape.properties.screenpos = screenpos;
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
765 return screenpos;
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
766 };
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
767
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
768 var getBboxRect = function (data, shape) {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
769 var coords = shape.geometry.coordinates;
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
770 if (coords == null) return null;
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
771 var xmin = 1;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
772 var xmax = 0;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
773 var ymin = 1;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
774 var ymax = 0;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
775 var x, y;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
776 for (var i = 0; i < coords.length; ++i) {
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
777 x = coords[i][0];
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
778 y = coords[i][1];
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
779 xmin = (x < xmin) ? x : xmin;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
780 xmax = (x > xmax) ? x : xmax;
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
781 ymin = (y < ymin) ? y : ymin;
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
782 ymax = (y > ymax) ? y : ymax;
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
783 }
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
784 return new geom.Rectangle(xmin, ymin, xmax-xmin, ymax-ymin);
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
785 };
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
786
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
787 /**
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
788 * render a shape on screen.
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
789 *
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
790 * Creates a SVG element and adds it to the layer.
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
791 * Puts a reference $elem in the shape object.
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
792 *
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
793 * @param data
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
794 * @param shape
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
795 * @param layer
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
796 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
797 var renderShape = function (data, shape, layer) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
798 // make sure we have a SVG element
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
799 if (layer.svgElem == null) {
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
800 renderShapes(data, layer);
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
801 return;
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
802 }
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
803 var shapeType = shape.geometry.type;
1357
c176dca2b62b added Proportion shape (LineString with only 3 vertices)
hertzhaft
parents: 1356
diff changeset
804 if (!isSupported(data, shapeType)) {
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
805 console.error("renderShape: unsupported shape type: "+shapeType);
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
806 return;
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
807 }
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
808 // create the SVG
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
809 var $elem = data.shapeFactory[shapeType].svg(shape);
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
810 // let shape know where it is rendered
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
811 shape.$elem = $elem;
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
812 shape.layer = layer;
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
813 // place the SVG on screen
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
814 createScreenCoords(data, shape);
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
815 $elem.place();
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
816 // render the SVG
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
817 $(layer.svgElem).append($elem);
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
818 // add adjustment handles
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
819 if (shape.properties.editable) {
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
820 addEditHandles(data, shape, layer);
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
821 if (hasPolygonType(shape) && data.settings.editPolygonPoints) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
822 enablePolygonEdit(data, shape);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
823 }
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
824 }
1312
444c5e250a4c vector plugin sends renderShape event when shapes are (re)rendered into SVG elements.
robcast
parents: 1310
diff changeset
825 $(data).trigger("renderShape", shape);
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
826 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
827
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
828 /**
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
829 * remove rendered shape from screen.
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
830 *
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
831 * Removes the SVG elements from the layer.
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
832 *
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
833 * @param data
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
834 * @param shape
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
835 */
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
836 var unrenderShape = function (data, shape) {
1538
747ed0af8663 annotations: some refactoring in shape creation; enable shape editing
hertzhaft
parents: 1537
diff changeset
837 removeEditHandles(data, shape);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
838 // remove SVG element
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
839 if (shape.$elem != null) {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
840 shape.$elem.remove();
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
841 delete shape.$elem;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
842 }
1585
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
843 if (hasPolygonType(shape) && data.settings.editPolygonPoints) {
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
844 disablePolygonEdit(data);
f322ac84adf7 vector plugin: add polygon editing facility
hertzhaft
parents: 1584
diff changeset
845 }
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
846 };
1351
76b72fa16012 immediate reaction on when dragging and keys x or y are pressed
hertzhaft
parents: 1350
diff changeset
847
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
848 /**
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
849 * re-render a shape.
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
850 *
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
851 * Removes the SVG element from layer and renders the (updated) shape again.
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
852 *
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
853 * @param data
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
854 * @param shape
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
855 * @param layer
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
856 */
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
857 var redrawShape = function (data, shape, layer) {
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
858 unrenderShape(data, shape);
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
859 renderShape(data, shape, layer || shape.layer);
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
860 };
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
861
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
862 /**
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
863 * return a vertexDragHandler function.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
864 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
865 * @param data
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
866 * @param shape shape to drag
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
867 * @param vtx vertex number on shape
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
868 * @onComplete function (data, shape)
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
869 */
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
870 var getVertexDragHandler = function (data, shape, vtx, onComplete) {
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
871 var $document = $(document);
1368
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
872 var imgRect = data.imgRect;
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
873 var $shape = shape.$elem;
1361
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
874 var $handle = (shape.$vertexElems != null) ? shape.$vertexElems[vtx] : null;
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
875 var shapeType = shape.geometry.type;
1368
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
876 var props = shape.properties;
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
877 var pos = props.screenpos;
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
878 var pStart; // save startpoint
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
879
1368
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
880 var placeHandle = function (i, $handle) {
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
881 $handle.moveTo(pos[i]);
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
882 };
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
883
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
884 var placeHandles = function () {
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
885 $.each(shape.$vertexElems, placeHandle);
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
886 };
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
887
1342
6c169dca1ea7 simplify some convenience variables
hertzhaft
parents: 1341
diff changeset
888 var dragStart = function (evt) { // start dragging
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
889 // cancel if not left-click
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
890 if (evt.which != 1) return;
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
891 pStart = new geom.Position(evt);
1368
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
892 props.startpos = pStart;
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
893 props.vtx = vtx;
1347
668a62a873b2 store screen positions on drag; trigger positionShape event
hertzhaft
parents: 1344
diff changeset
894 $(data).trigger('positionShape', shape);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
895 $document.on("mousemove.dlVertexDrag", dragMove);
1337
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
896 $document.on("mouseup.dlVertexDrag", dragEnd);
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
897 $document.on("dblclick.dlVertexDrag", dragEnd);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
898 return false;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
899 };
1337
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
900
1342
6c169dca1ea7 simplify some convenience variables
hertzhaft
parents: 1341
diff changeset
901 var dragMove = function (evt) { // dragging
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
902 var pt = new geom.Position(evt);
1351
76b72fa16012 immediate reaction on when dragging and keys x or y are pressed
hertzhaft
parents: 1350
diff changeset
903 pt.clipTo(imgRect);
1384
ce7b4b7e6208 some optimisations; snap still buggy
hertzhaft
parents: 1376
diff changeset
904 pos[vtx].moveTo(pt);
1344
3ec94ec07930 toggle SVG and key handler according to visibility of measure bar
hertzhaft
parents: 1342
diff changeset
905 if (isSupported(data, shapeType)) {
1384
ce7b4b7e6208 some optimisations; snap still buggy
hertzhaft
parents: 1376
diff changeset
906 // trigger drag event (may manipulate screen position)
ce7b4b7e6208 some optimisations; snap still buggy
hertzhaft
parents: 1376
diff changeset
907 $(data).trigger('positionShape', shape);
ce7b4b7e6208 some optimisations; snap still buggy
hertzhaft
parents: 1376
diff changeset
908 // update vertex coords of shape
ce7b4b7e6208 some optimisations; snap still buggy
hertzhaft
parents: 1376
diff changeset
909 shape.geometry.coordinates[vtx] = data.imgTrafo.invtransform(pos[vtx]).toArray();
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
910 // update shape SVG element
1361
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
911 $shape.place();
1368
186ef7695627 place handles along with shapes
hertzhaft
parents: 1361
diff changeset
912 // move handles accordingly
1376
eee1d8cc672b fix bug when creating shapes without handles.
robcast
parents: 1368
diff changeset
913 if (shape.$vertexElems != null) placeHandles();
1337
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
914 $(data).trigger('dragShape', shape);
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
915 }
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
916 return false;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
917 };
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
918
1342
6c169dca1ea7 simplify some convenience variables
hertzhaft
parents: 1341
diff changeset
919 var dragEnd = function (evt) { // end dragging
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
920 var pt = new geom.Position(evt);
1342
6c169dca1ea7 simplify some convenience variables
hertzhaft
parents: 1341
diff changeset
921 if ((pt.distance(pStart) < 5) && evt.type === 'mouseup') {
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
922 // 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
923 return false;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
924 }
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
925 dragMove(evt);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
926 // remove move/end handler
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
927 $document.off("mousemove.dlVertexDrag", dragMove);
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
928 $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
929 $document.off("dblclick.dlVertexDrag", dragEnd);
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
930 // call setup to update bbox
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
931 data.shapeFactory[shapeType].setup(data, shape);
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
932 // rearm start handler
1361
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
933 if ($handle != null) {
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
934 $handle.one("mousedown.dlVertexDrag", dragStart);
ddc086449463 fix bug with defineShape if shape is non-editable (no handles). automatically use renderShapes as default renderFn.
robcast
parents: 1360
diff changeset
935 }
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
936 if (onComplete != null) {
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
937 onComplete(data, shape, evt);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
938 } else {
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
939 $(data).trigger('changeShape', shape);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
940 }
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
941 return false;
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
942 };
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
943
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
944 // return drag start handler
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
945 return dragStart;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
946 };
1337
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
947
1338
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
948
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
949 /**
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
950 * returns true if shapeType is supported
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
951 *
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
952 * @param shapeType shapeType to test
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
953 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
954 var isSupported = function (data, shapeType) {
1386
d8beafc1df41 sort image areas by size so that smaller areas are not eclipsed by bigger ones.
robcast
parents: 1384
diff changeset
955 return data.shapeFactory[shapeType] != null;
1338
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
956 };
3da1ca0a33d9 support Circle shape
hertzhaft
parents: 1337
diff changeset
957
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
958 /**
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
959 * define a shape by click and drag.
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
960 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
961 * The given shape object has to have a type, but its coordinates will be overwritten.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
962 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
963 * @param data
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
964 * @param shape the shape to define
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
965 * @param layer the layer to draw on
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
966 * @onComplete function (data, shape)
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
967 */
1355
c37c6e67ef07 create SVGs through factory
hertzhaft
parents: 1354
diff changeset
968 var defineShape = function (data, shape, layer, onComplete) {
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
969 var shapeType = shape.geometry.type;
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
970 // call setup to make sure maxvtx is set
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
971 data.shapeFactory[shapeType].setup(data, shape);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
972 var $elem = data.$elem;
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
973 var $body = $('body');
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
974 var bodyRect = new geom.Rectangle($body);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
975 // 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
976 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
977 $elem.append($overlayDiv);
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
978 bodyRect.adjustDiv($overlayDiv);
1342
6c169dca1ea7 simplify some convenience variables
hertzhaft
parents: 1341
diff changeset
979
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
980 var shapeStart = function (evt) {
1610
f425f00bf5e3 changed digilib.geometry to use new and prototypes instead of adding methods to objects.
robcast
parents: 1585
diff changeset
981 var pt = new geom.Position(evt);
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
982 // setup shape
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
983 var p1 = data.imgTrafo.invtransform(pt).toArray();
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
984 var p2 = p1.slice(0);
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
985 var vtx = 1;
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
986 if (shapeType === 'Point') {
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
987 shape.geometry.coordinates = [p1];
1344
3ec94ec07930 toggle SVG and key handler according to visibility of measure bar
hertzhaft
parents: 1342
diff changeset
988 } else if (isSupported(data, shapeType)) {
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
989 shape.geometry.coordinates = [p1, p2];
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
990 } else {
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
991 console.error("defineShape: unsupported shape type: "+shapeType);
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
992 $overlayDiv.remove();
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
993 return false;
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
994 }
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
995 // shape is not editable by default
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
996 if (shape.properties == null) {
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
997 shape.properties = {'editable' : false};
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
998 }
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
999 // save first mousedown position
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1000 shape.properties.screenpos = [pt];
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
1001 shape.properties.vtx = vtx;
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
1002 // draw shape
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
1003 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
1004 // vertex drag end handler
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1005 var vertexDragDone = function (data, shape, evt) {
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1006 var coords = shape.geometry.coordinates;
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1007 var max = shape.properties.maxvtx;
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1008 if (max == null || vtx < max-1) {
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1009 // multipoint shape (e. g. Polygon, LineString)
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1010 if (evt.type === 'mouseup') {
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1011 // single click adds next point
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1012 unrenderShape(data, shape);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1013 // copy last vertex as starting point
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1014 coords.push(coords[vtx].slice());
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1015 vtx += 1;
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1016 // draw shape
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
1017 shape.properties.vtx = vtx;
1337
1e9e86dbaa1e add dragShape event
hertzhaft
parents: 1333
diff changeset
1018 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
1019 // execute vertex drag handler on next vertex
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1020 getVertexDragHandler(data, shape, vtx, vertexDragDone)(evt);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1021 return false;
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1022 } else if (evt.type === 'dblclick') {
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1023 // double click ends multipoint shape
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1024 var rerender = false;
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1025 // remove duplicate vertices (from mouseup)
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1026 while (coords[vtx][0] === coords[vtx-1][0] &&
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1027 coords[vtx][1] === coords[vtx-1][1]) {
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1028 coords.pop();
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1029 vtx -= 1;
1323
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1030 rerender = true;
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1031 }
7e208f491ef1 some cleanup.
robcast
parents: 1317
diff changeset
1032 if (rerender) {
1359
647bd1686fa6 added Rect shape (rectangle drawn from a base line)
hertzhaft
parents: 1358
diff changeset
1033 shape.properties.vtx = vtx;
1556
9d754003c2d3 copy 2 files from branch measure-maps
hertzhaft
parents: 1546
diff changeset
1034 redrawShape(data, shape, layer);
1303
7b18c8e6ab31 clean up.
robcast
parents: 1302
diff changeset
1035 }
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1036 } else {
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1037 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
1038 return false;
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1039 }
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1040 }
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1041 shapeDone(data, shape);
1302
fe413f88f3b6 linestring and polygon can now be created interactively with defineShape. doubleclick to end shape.
robcast
parents: 1282
diff changeset
1042 };
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1043 if (vtx === shape.properties.maxvtx) {
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1044 // last vertex
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1045 shapeDone(data, shape);
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1046 } else {
1356
339e406772f9 pluggable SVG shapes
hertzhaft
parents: 1355
diff changeset
1047 // execute vertex drag handler on next vertex
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1048 getVertexDragHandler(data, shape, vtx, vertexDragDone)(evt);
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1049 }
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
1050 return false;
1258
fd90ed468eec improved vector update.
robcast
parents: 1257
diff changeset
1051 };
1353
94260e75bb7a factor out handles
hertzhaft
parents: 1352
diff changeset
1052
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1053 var shapeDone = function (data, shape) {
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1054 // defining shape done
1387
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
1055 unrenderShape(data, shape);
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
1056 // call setup to update bbox
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
1057 data.shapeFactory[shapeType].setup(data, shape);
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
1058 renderShape(data, shape, layer);
2540222b6dfe fixed bug with creating shapes that broke the measure tool.
robcast
parents: 1386
diff changeset
1059 // save shape
1317
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1060 layer.shapes.push(shape);
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1061 $overlayDiv.remove();
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1062 if (onComplete != null) {
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1063 onComplete(data, shape);
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1064 }
cac657d25ba9 use vector plugin defineShape method for annotation shapes.
robcast
parents: 1316
diff changeset
1065 };
1352
d8271e1e9ce2 seems we need not save editable state when drawing a shape
hertzhaft
parents: 1351
diff changeset
1066
1257
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
1067 // start by clicking
4f8f960a4bea createShape now uses vertexDragHandler too. vertex dragging also works with single clicks.
robcast
parents: 1255
diff changeset
1068 $overlayDiv.one('mousedown.dlShape', shapeStart);
1254
7410a158ca7b vector shapes can be editable now (properties:{editable:true}).
robcast
parents: 1253
diff changeset
1069 };
1339
8a0cdf624dc2 refactored the creation of drag handles for shapes
hertzhaft
parents: 1338
diff changeset
1070
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1071 /**
1260
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
1072 * create a SVG element with attributes.
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
1073 *
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
1074 * @param name tag name
0043a0a6457b more doc.
robcast
parents: 1259
diff changeset
1075 * @param attrs object with attributes
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1076 */
1266
52aeee70d2af fixed svg layer offset by updating imgRect more often.
robcast
parents: 1265
diff changeset
1077 var svgElement = function (name, attrs) {
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1078 var elem = document.createElementNS(svgNS, name);
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1079 if (attrs != null) {
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1080 for (var att in attrs) {
1304
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
1081 if (attrs[att] != null) {
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
1082 elem.setAttributeNS(null, att, attrs[att]);
94ca844425fe added Point shape type.
robcast
parents: 1303
diff changeset
1083 }
1253
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1084 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1085 }
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1086 return elem;
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1087 };
4d1a50cd41c1 vector plugin assembles svg elementwise now.
robcast
parents: 1251
diff changeset
1088
1238
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1089 // plugin object, containing name, install and init routines
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1090 // all shared objects are filled by digilib on registration
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1091 var plugin = {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1092 name : 'vector',
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1093 install : install,
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1094 init : init,
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1095 buttons : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1096 actions : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1097 fn : {},
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1098 plugins : {}
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1099 };
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1100
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1101 if ($.fn.digilib == null) {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1102 $.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
1103 } else {
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1104 $.fn.digilib('plugin', plugin);
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1105 }
f863da95ed6e working on new vector plugin for zoomable vector (SVG) overlays.
robcast
parents:
diff changeset
1106 })(jQuery);