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